dgbrfs.c
Go to the documentation of this file.
00001 /* dgbrfs.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static doublereal c_b15 = -1.;
00020 static doublereal c_b17 = 1.;
00021 
00022 /* Subroutine */ int dgbrfs_(char *trans, integer *n, integer *kl, integer *
00023         ku, integer *nrhs, doublereal *ab, integer *ldab, doublereal *afb, 
00024         integer *ldafb, integer *ipiv, doublereal *b, integer *ldb, 
00025         doublereal *x, integer *ldx, doublereal *ferr, doublereal *berr, 
00026         doublereal *work, integer *iwork, integer *info)
00027 {
00028     /* System generated locals */
00029     integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset, 
00030             x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7;
00031     doublereal d__1, d__2, d__3;
00032 
00033     /* Local variables */
00034     integer i__, j, k;
00035     doublereal s;
00036     integer kk;
00037     doublereal xk;
00038     integer nz;
00039     doublereal eps;
00040     integer kase;
00041     doublereal safe1, safe2;
00042     extern /* Subroutine */ int dgbmv_(char *, integer *, integer *, integer *
00043 , integer *, doublereal *, doublereal *, integer *, doublereal *, 
00044             integer *, doublereal *, doublereal *, integer *);
00045     extern logical lsame_(char *, char *);
00046     integer isave[3];
00047     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00048             doublereal *, integer *), daxpy_(integer *, doublereal *, 
00049             doublereal *, integer *, doublereal *, integer *);
00050     integer count;
00051     extern /* Subroutine */ int dlacn2_(integer *, doublereal *, doublereal *, 
00052              integer *, doublereal *, integer *, integer *);
00053     extern doublereal dlamch_(char *);
00054     doublereal safmin;
00055     extern /* Subroutine */ int xerbla_(char *, integer *), dgbtrs_(
00056             char *, integer *, integer *, integer *, integer *, doublereal *, 
00057             integer *, integer *, doublereal *, integer *, integer *);
00058     logical notran;
00059     char transt[1];
00060     doublereal lstres;
00061 
00062 
00063 /*  -- LAPACK routine (version 3.2) -- */
00064 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00065 /*     November 2006 */
00066 
00067 /*     Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
00068 
00069 /*     .. Scalar Arguments .. */
00070 /*     .. */
00071 /*     .. Array Arguments .. */
00072 /*     .. */
00073 
00074 /*  Purpose */
00075 /*  ======= */
00076 
00077 /*  DGBRFS improves the computed solution to a system of linear */
00078 /*  equations when the coefficient matrix is banded, and provides */
00079 /*  error bounds and backward error estimates for the solution. */
00080 
00081 /*  Arguments */
00082 /*  ========= */
00083 
00084 /*  TRANS   (input) CHARACTER*1 */
00085 /*          Specifies the form of the system of equations: */
00086 /*          = 'N':  A * X = B     (No transpose) */
00087 /*          = 'T':  A**T * X = B  (Transpose) */
00088 /*          = 'C':  A**H * X = B  (Conjugate transpose = Transpose) */
00089 
00090 /*  N       (input) INTEGER */
00091 /*          The order of the matrix A.  N >= 0. */
00092 
00093 /*  KL      (input) INTEGER */
00094 /*          The number of subdiagonals within the band of A.  KL >= 0. */
00095 
00096 /*  KU      (input) INTEGER */
00097 /*          The number of superdiagonals within the band of A.  KU >= 0. */
00098 
00099 /*  NRHS    (input) INTEGER */
00100 /*          The number of right hand sides, i.e., the number of columns */
00101 /*          of the matrices B and X.  NRHS >= 0. */
00102 
00103 /*  AB      (input) DOUBLE PRECISION array, dimension (LDAB,N) */
00104 /*          The original band matrix A, stored in rows 1 to KL+KU+1. */
00105 /*          The j-th column of A is stored in the j-th column of the */
00106 /*          array AB as follows: */
00107 /*          AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl). */
00108 
00109 /*  LDAB    (input) INTEGER */
00110 /*          The leading dimension of the array AB.  LDAB >= KL+KU+1. */
00111 
00112 /*  AFB     (input) DOUBLE PRECISION array, dimension (LDAFB,N) */
00113 /*          Details of the LU factorization of the band matrix A, as */
00114 /*          computed by DGBTRF.  U is stored as an upper triangular band */
00115 /*          matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and */
00116 /*          the multipliers used during the factorization are stored in */
00117 /*          rows KL+KU+2 to 2*KL+KU+1. */
00118 
00119 /*  LDAFB   (input) INTEGER */
00120 /*          The leading dimension of the array AFB.  LDAFB >= 2*KL*KU+1. */
00121 
00122 /*  IPIV    (input) INTEGER array, dimension (N) */
00123 /*          The pivot indices from DGBTRF; for 1<=i<=N, row i of the */
00124 /*          matrix was interchanged with row IPIV(i). */
00125 
00126 /*  B       (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
00127 /*          The right hand side matrix B. */
00128 
00129 /*  LDB     (input) INTEGER */
00130 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00131 
00132 /*  X       (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
00133 /*          On entry, the solution matrix X, as computed by DGBTRS. */
00134 /*          On exit, the improved solution matrix X. */
00135 
00136 /*  LDX     (input) INTEGER */
00137 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00138 
00139 /*  FERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00140 /*          The estimated forward error bound for each solution vector */
00141 /*          X(j) (the j-th column of the solution matrix X). */
00142 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00143 /*          is an estimated upper bound for the magnitude of the largest */
00144 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00145 /*          largest element in X(j).  The estimate is as reliable as */
00146 /*          the estimate for RCOND, and is almost always a slight */
00147 /*          overestimate of the true error. */
00148 
00149 /*  BERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00150 /*          The componentwise relative backward error of each solution */
00151 /*          vector X(j) (i.e., the smallest relative change in */
00152 /*          any element of A or B that makes X(j) an exact solution). */
00153 
00154 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N) */
00155 
00156 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00157 
00158 /*  INFO    (output) INTEGER */
00159 /*          = 0:  successful exit */
00160 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00161 
00162 /*  Internal Parameters */
00163 /*  =================== */
00164 
00165 /*  ITMAX is the maximum number of steps of iterative refinement. */
00166 
00167 /*  ===================================================================== */
00168 
00169 /*     .. Parameters .. */
00170 /*     .. */
00171 /*     .. Local Scalars .. */
00172 /*     .. */
00173 /*     .. Local Arrays .. */
00174 /*     .. */
00175 /*     .. External Subroutines .. */
00176 /*     .. */
00177 /*     .. Intrinsic Functions .. */
00178 /*     .. */
00179 /*     .. External Functions .. */
00180 /*     .. */
00181 /*     .. Executable Statements .. */
00182 
00183 /*     Test the input parameters. */
00184 
00185     /* Parameter adjustments */
00186     ab_dim1 = *ldab;
00187     ab_offset = 1 + ab_dim1;
00188     ab -= ab_offset;
00189     afb_dim1 = *ldafb;
00190     afb_offset = 1 + afb_dim1;
00191     afb -= afb_offset;
00192     --ipiv;
00193     b_dim1 = *ldb;
00194     b_offset = 1 + b_dim1;
00195     b -= b_offset;
00196     x_dim1 = *ldx;
00197     x_offset = 1 + x_dim1;
00198     x -= x_offset;
00199     --ferr;
00200     --berr;
00201     --work;
00202     --iwork;
00203 
00204     /* Function Body */
00205     *info = 0;
00206     notran = lsame_(trans, "N");
00207     if (! notran && ! lsame_(trans, "T") && ! lsame_(
00208             trans, "C")) {
00209         *info = -1;
00210     } else if (*n < 0) {
00211         *info = -2;
00212     } else if (*kl < 0) {
00213         *info = -3;
00214     } else if (*ku < 0) {
00215         *info = -4;
00216     } else if (*nrhs < 0) {
00217         *info = -5;
00218     } else if (*ldab < *kl + *ku + 1) {
00219         *info = -7;
00220     } else if (*ldafb < (*kl << 1) + *ku + 1) {
00221         *info = -9;
00222     } else if (*ldb < max(1,*n)) {
00223         *info = -12;
00224     } else if (*ldx < max(1,*n)) {
00225         *info = -14;
00226     }
00227     if (*info != 0) {
00228         i__1 = -(*info);
00229         xerbla_("DGBRFS", &i__1);
00230         return 0;
00231     }
00232 
00233 /*     Quick return if possible */
00234 
00235     if (*n == 0 || *nrhs == 0) {
00236         i__1 = *nrhs;
00237         for (j = 1; j <= i__1; ++j) {
00238             ferr[j] = 0.;
00239             berr[j] = 0.;
00240 /* L10: */
00241         }
00242         return 0;
00243     }
00244 
00245     if (notran) {
00246         *(unsigned char *)transt = 'T';
00247     } else {
00248         *(unsigned char *)transt = 'N';
00249     }
00250 
00251 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00252 
00253 /* Computing MIN */
00254     i__1 = *kl + *ku + 2, i__2 = *n + 1;
00255     nz = min(i__1,i__2);
00256     eps = dlamch_("Epsilon");
00257     safmin = dlamch_("Safe minimum");
00258     safe1 = nz * safmin;
00259     safe2 = safe1 / eps;
00260 
00261 /*     Do for each right hand side */
00262 
00263     i__1 = *nrhs;
00264     for (j = 1; j <= i__1; ++j) {
00265 
00266         count = 1;
00267         lstres = 3.;
00268 L20:
00269 
00270 /*        Loop until stopping criterion is satisfied. */
00271 
00272 /*        Compute residual R = B - op(A) * X, */
00273 /*        where op(A) = A, A**T, or A**H, depending on TRANS. */
00274 
00275         dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00276         dgbmv_(trans, n, n, kl, ku, &c_b15, &ab[ab_offset], ldab, &x[j * 
00277                 x_dim1 + 1], &c__1, &c_b17, &work[*n + 1], &c__1);
00278 
00279 /*        Compute componentwise relative backward error from formula */
00280 
00281 /*        max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) ) */
00282 
00283 /*        where abs(Z) is the componentwise absolute value of the matrix */
00284 /*        or vector Z.  If the i-th component of the denominator is less */
00285 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00286 /*        numerator and denominator before dividing. */
00287 
00288         i__2 = *n;
00289         for (i__ = 1; i__ <= i__2; ++i__) {
00290             work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
00291 /* L30: */
00292         }
00293 
00294 /*        Compute abs(op(A))*abs(X) + abs(B). */
00295 
00296         if (notran) {
00297             i__2 = *n;
00298             for (k = 1; k <= i__2; ++k) {
00299                 kk = *ku + 1 - k;
00300                 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00301 /* Computing MAX */
00302                 i__3 = 1, i__4 = k - *ku;
00303 /* Computing MIN */
00304                 i__6 = *n, i__7 = k + *kl;
00305                 i__5 = min(i__6,i__7);
00306                 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00307                     work[i__] += (d__1 = ab[kk + i__ + k * ab_dim1], abs(d__1)
00308                             ) * xk;
00309 /* L40: */
00310                 }
00311 /* L50: */
00312             }
00313         } else {
00314             i__2 = *n;
00315             for (k = 1; k <= i__2; ++k) {
00316                 s = 0.;
00317                 kk = *ku + 1 - k;
00318 /* Computing MAX */
00319                 i__5 = 1, i__3 = k - *ku;
00320 /* Computing MIN */
00321                 i__6 = *n, i__7 = k + *kl;
00322                 i__4 = min(i__6,i__7);
00323                 for (i__ = max(i__5,i__3); i__ <= i__4; ++i__) {
00324                     s += (d__1 = ab[kk + i__ + k * ab_dim1], abs(d__1)) * (
00325                             d__2 = x[i__ + j * x_dim1], abs(d__2));
00326 /* L60: */
00327                 }
00328                 work[k] += s;
00329 /* L70: */
00330             }
00331         }
00332         s = 0.;
00333         i__2 = *n;
00334         for (i__ = 1; i__ <= i__2; ++i__) {
00335             if (work[i__] > safe2) {
00336 /* Computing MAX */
00337                 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
00338                         i__];
00339                 s = max(d__2,d__3);
00340             } else {
00341 /* Computing MAX */
00342                 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) 
00343                         / (work[i__] + safe1);
00344                 s = max(d__2,d__3);
00345             }
00346 /* L80: */
00347         }
00348         berr[j] = s;
00349 
00350 /*        Test stopping criterion. Continue iterating if */
00351 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00352 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00353 /*              last iteration, and */
00354 /*           3) At most ITMAX iterations tried. */
00355 
00356         if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00357 
00358 /*           Update solution and try again. */
00359 
00360             dgbtrs_(trans, n, kl, ku, &c__1, &afb[afb_offset], ldafb, &ipiv[1]
00361 , &work[*n + 1], n, info);
00362             daxpy_(n, &c_b17, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00363                     ;
00364             lstres = berr[j];
00365             ++count;
00366             goto L20;
00367         }
00368 
00369 /*        Bound error from formula */
00370 
00371 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00372 /*        norm( abs(inv(op(A)))* */
00373 /*           ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X) */
00374 
00375 /*        where */
00376 /*          norm(Z) is the magnitude of the largest component of Z */
00377 /*          inv(op(A)) is the inverse of op(A) */
00378 /*          abs(Z) is the componentwise absolute value of the matrix or */
00379 /*             vector Z */
00380 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00381 /*          EPS is machine epsilon */
00382 
00383 /*        The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B)) */
00384 /*        is incremented by SAFE1 if the i-th component of */
00385 /*        abs(op(A))*abs(X) + abs(B) is less than SAFE2. */
00386 
00387 /*        Use DLACN2 to estimate the infinity-norm of the matrix */
00388 /*           inv(op(A)) * diag(W), */
00389 /*        where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) */
00390 
00391         i__2 = *n;
00392         for (i__ = 1; i__ <= i__2; ++i__) {
00393             if (work[i__] > safe2) {
00394                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00395                         work[i__];
00396             } else {
00397                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00398                         work[i__] + safe1;
00399             }
00400 /* L90: */
00401         }
00402 
00403         kase = 0;
00404 L100:
00405         dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00406                 kase, isave);
00407         if (kase != 0) {
00408             if (kase == 1) {
00409 
00410 /*              Multiply by diag(W)*inv(op(A)**T). */
00411 
00412                 dgbtrs_(transt, n, kl, ku, &c__1, &afb[afb_offset], ldafb, &
00413                         ipiv[1], &work[*n + 1], n, info);
00414                 i__2 = *n;
00415                 for (i__ = 1; i__ <= i__2; ++i__) {
00416                     work[*n + i__] *= work[i__];
00417 /* L110: */
00418                 }
00419             } else {
00420 
00421 /*              Multiply by inv(op(A))*diag(W). */
00422 
00423                 i__2 = *n;
00424                 for (i__ = 1; i__ <= i__2; ++i__) {
00425                     work[*n + i__] *= work[i__];
00426 /* L120: */
00427                 }
00428                 dgbtrs_(trans, n, kl, ku, &c__1, &afb[afb_offset], ldafb, &
00429                         ipiv[1], &work[*n + 1], n, info);
00430             }
00431             goto L100;
00432         }
00433 
00434 /*        Normalize error. */
00435 
00436         lstres = 0.;
00437         i__2 = *n;
00438         for (i__ = 1; i__ <= i__2; ++i__) {
00439 /* Computing MAX */
00440             d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00441             lstres = max(d__2,d__3);
00442 /* L130: */
00443         }
00444         if (lstres != 0.) {
00445             ferr[j] /= lstres;
00446         }
00447 
00448 /* L140: */
00449     }
00450 
00451     return 0;
00452 
00453 /*     End of DGBRFS */
00454 
00455 } /* dgbrfs_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:43