dgtrfs.c
Go to the documentation of this file.
00001 /* dgtrfs.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_b18 = -1.;
00020 static doublereal c_b19 = 1.;
00021 
00022 /* Subroutine */ int dgtrfs_(char *trans, integer *n, integer *nrhs, 
00023         doublereal *dl, doublereal *d__, doublereal *du, doublereal *dlf, 
00024         doublereal *df, doublereal *duf, doublereal *du2, integer *ipiv, 
00025         doublereal *b, integer *ldb, doublereal *x, integer *ldx, doublereal *
00026         ferr, doublereal *berr, doublereal *work, integer *iwork, integer *
00027         info)
00028 {
00029     /* System generated locals */
00030     integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2;
00031     doublereal d__1, d__2, d__3, d__4;
00032 
00033     /* Local variables */
00034     integer i__, j;
00035     doublereal s;
00036     integer nz;
00037     doublereal eps;
00038     integer kase;
00039     doublereal safe1, safe2;
00040     extern logical lsame_(char *, char *);
00041     integer isave[3];
00042     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00043             doublereal *, integer *), daxpy_(integer *, doublereal *, 
00044             doublereal *, integer *, doublereal *, integer *);
00045     integer count;
00046     extern /* Subroutine */ int dlacn2_(integer *, doublereal *, doublereal *, 
00047              integer *, doublereal *, integer *, integer *);
00048     extern doublereal dlamch_(char *);
00049     extern /* Subroutine */ int dlagtm_(char *, integer *, integer *, 
00050             doublereal *, doublereal *, doublereal *, doublereal *, 
00051             doublereal *, integer *, doublereal *, doublereal *, integer *);
00052     doublereal safmin;
00053     extern /* Subroutine */ int xerbla_(char *, integer *);
00054     logical notran;
00055     char transn[1];
00056     extern /* Subroutine */ int dgttrs_(char *, integer *, integer *, 
00057             doublereal *, doublereal *, doublereal *, doublereal *, integer *, 
00058              doublereal *, integer *, integer *);
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 /*  DGTRFS improves the computed solution to a system of linear */
00078 /*  equations when the coefficient matrix is tridiagonal, 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 /*  NRHS    (input) INTEGER */
00094 /*          The number of right hand sides, i.e., the number of columns */
00095 /*          of the matrix B.  NRHS >= 0. */
00096 
00097 /*  DL      (input) DOUBLE PRECISION array, dimension (N-1) */
00098 /*          The (n-1) subdiagonal elements of A. */
00099 
00100 /*  D       (input) DOUBLE PRECISION array, dimension (N) */
00101 /*          The diagonal elements of A. */
00102 
00103 /*  DU      (input) DOUBLE PRECISION array, dimension (N-1) */
00104 /*          The (n-1) superdiagonal elements of A. */
00105 
00106 /*  DLF     (input) DOUBLE PRECISION array, dimension (N-1) */
00107 /*          The (n-1) multipliers that define the matrix L from the */
00108 /*          LU factorization of A as computed by DGTTRF. */
00109 
00110 /*  DF      (input) DOUBLE PRECISION array, dimension (N) */
00111 /*          The n diagonal elements of the upper triangular matrix U from */
00112 /*          the LU factorization of A. */
00113 
00114 /*  DUF     (input) DOUBLE PRECISION array, dimension (N-1) */
00115 /*          The (n-1) elements of the first superdiagonal of U. */
00116 
00117 /*  DU2     (input) DOUBLE PRECISION array, dimension (N-2) */
00118 /*          The (n-2) elements of the second superdiagonal of U. */
00119 
00120 /*  IPIV    (input) INTEGER array, dimension (N) */
00121 /*          The pivot indices; for 1 <= i <= n, row i of the matrix was */
00122 /*          interchanged with row IPIV(i).  IPIV(i) will always be either */
00123 /*          i or i+1; IPIV(i) = i indicates a row interchange was not */
00124 /*          required. */
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 DGTTRS. */
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     --dl;
00187     --d__;
00188     --du;
00189     --dlf;
00190     --df;
00191     --duf;
00192     --du2;
00193     --ipiv;
00194     b_dim1 = *ldb;
00195     b_offset = 1 + b_dim1;
00196     b -= b_offset;
00197     x_dim1 = *ldx;
00198     x_offset = 1 + x_dim1;
00199     x -= x_offset;
00200     --ferr;
00201     --berr;
00202     --work;
00203     --iwork;
00204 
00205     /* Function Body */
00206     *info = 0;
00207     notran = lsame_(trans, "N");
00208     if (! notran && ! lsame_(trans, "T") && ! lsame_(
00209             trans, "C")) {
00210         *info = -1;
00211     } else if (*n < 0) {
00212         *info = -2;
00213     } else if (*nrhs < 0) {
00214         *info = -3;
00215     } else if (*ldb < max(1,*n)) {
00216         *info = -13;
00217     } else if (*ldx < max(1,*n)) {
00218         *info = -15;
00219     }
00220     if (*info != 0) {
00221         i__1 = -(*info);
00222         xerbla_("DGTRFS", &i__1);
00223         return 0;
00224     }
00225 
00226 /*     Quick return if possible */
00227 
00228     if (*n == 0 || *nrhs == 0) {
00229         i__1 = *nrhs;
00230         for (j = 1; j <= i__1; ++j) {
00231             ferr[j] = 0.;
00232             berr[j] = 0.;
00233 /* L10: */
00234         }
00235         return 0;
00236     }
00237 
00238     if (notran) {
00239         *(unsigned char *)transn = 'N';
00240         *(unsigned char *)transt = 'T';
00241     } else {
00242         *(unsigned char *)transn = 'T';
00243         *(unsigned char *)transt = 'N';
00244     }
00245 
00246 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00247 
00248     nz = 4;
00249     eps = dlamch_("Epsilon");
00250     safmin = dlamch_("Safe minimum");
00251     safe1 = nz * safmin;
00252     safe2 = safe1 / eps;
00253 
00254 /*     Do for each right hand side */
00255 
00256     i__1 = *nrhs;
00257     for (j = 1; j <= i__1; ++j) {
00258 
00259         count = 1;
00260         lstres = 3.;
00261 L20:
00262 
00263 /*        Loop until stopping criterion is satisfied. */
00264 
00265 /*        Compute residual R = B - op(A) * X, */
00266 /*        where op(A) = A, A**T, or A**H, depending on TRANS. */
00267 
00268         dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00269         dlagtm_(trans, n, &c__1, &c_b18, &dl[1], &d__[1], &du[1], &x[j * 
00270                 x_dim1 + 1], ldx, &c_b19, &work[*n + 1], n);
00271 
00272 /*        Compute abs(op(A))*abs(x) + abs(b) for use in the backward */
00273 /*        error bound. */
00274 
00275         if (notran) {
00276             if (*n == 1) {
00277                 work[1] = (d__1 = b[j * b_dim1 + 1], abs(d__1)) + (d__2 = d__[
00278                         1] * x[j * x_dim1 + 1], abs(d__2));
00279             } else {
00280                 work[1] = (d__1 = b[j * b_dim1 + 1], abs(d__1)) + (d__2 = d__[
00281                         1] * x[j * x_dim1 + 1], abs(d__2)) + (d__3 = du[1] * 
00282                         x[j * x_dim1 + 2], abs(d__3));
00283                 i__2 = *n - 1;
00284                 for (i__ = 2; i__ <= i__2; ++i__) {
00285                     work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1)) + (
00286                             d__2 = dl[i__ - 1] * x[i__ - 1 + j * x_dim1], abs(
00287                             d__2)) + (d__3 = d__[i__] * x[i__ + j * x_dim1], 
00288                             abs(d__3)) + (d__4 = du[i__] * x[i__ + 1 + j * 
00289                             x_dim1], abs(d__4));
00290 /* L30: */
00291                 }
00292                 work[*n] = (d__1 = b[*n + j * b_dim1], abs(d__1)) + (d__2 = 
00293                         dl[*n - 1] * x[*n - 1 + j * x_dim1], abs(d__2)) + (
00294                         d__3 = d__[*n] * x[*n + j * x_dim1], abs(d__3));
00295             }
00296         } else {
00297             if (*n == 1) {
00298                 work[1] = (d__1 = b[j * b_dim1 + 1], abs(d__1)) + (d__2 = d__[
00299                         1] * x[j * x_dim1 + 1], abs(d__2));
00300             } else {
00301                 work[1] = (d__1 = b[j * b_dim1 + 1], abs(d__1)) + (d__2 = d__[
00302                         1] * x[j * x_dim1 + 1], abs(d__2)) + (d__3 = dl[1] * 
00303                         x[j * x_dim1 + 2], abs(d__3));
00304                 i__2 = *n - 1;
00305                 for (i__ = 2; i__ <= i__2; ++i__) {
00306                     work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1)) + (
00307                             d__2 = du[i__ - 1] * x[i__ - 1 + j * x_dim1], abs(
00308                             d__2)) + (d__3 = d__[i__] * x[i__ + j * x_dim1], 
00309                             abs(d__3)) + (d__4 = dl[i__] * x[i__ + 1 + j * 
00310                             x_dim1], abs(d__4));
00311 /* L40: */
00312                 }
00313                 work[*n] = (d__1 = b[*n + j * b_dim1], abs(d__1)) + (d__2 = 
00314                         du[*n - 1] * x[*n - 1 + j * x_dim1], abs(d__2)) + (
00315                         d__3 = d__[*n] * x[*n + j * x_dim1], abs(d__3));
00316             }
00317         }
00318 
00319 /*        Compute componentwise relative backward error from formula */
00320 
00321 /*        max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) ) */
00322 
00323 /*        where abs(Z) is the componentwise absolute value of the matrix */
00324 /*        or vector Z.  If the i-th component of the denominator is less */
00325 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00326 /*        numerator and denominator before dividing. */
00327 
00328         s = 0.;
00329         i__2 = *n;
00330         for (i__ = 1; i__ <= i__2; ++i__) {
00331             if (work[i__] > safe2) {
00332 /* Computing MAX */
00333                 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
00334                         i__];
00335                 s = max(d__2,d__3);
00336             } else {
00337 /* Computing MAX */
00338                 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) 
00339                         / (work[i__] + safe1);
00340                 s = max(d__2,d__3);
00341             }
00342 /* L50: */
00343         }
00344         berr[j] = s;
00345 
00346 /*        Test stopping criterion. Continue iterating if */
00347 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00348 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00349 /*              last iteration, and */
00350 /*           3) At most ITMAX iterations tried. */
00351 
00352         if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00353 
00354 /*           Update solution and try again. */
00355 
00356             dgttrs_(trans, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[
00357                     1], &work[*n + 1], n, info);
00358             daxpy_(n, &c_b19, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00359                     ;
00360             lstres = berr[j];
00361             ++count;
00362             goto L20;
00363         }
00364 
00365 /*        Bound error from formula */
00366 
00367 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00368 /*        norm( abs(inv(op(A)))* */
00369 /*           ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X) */
00370 
00371 /*        where */
00372 /*          norm(Z) is the magnitude of the largest component of Z */
00373 /*          inv(op(A)) is the inverse of op(A) */
00374 /*          abs(Z) is the componentwise absolute value of the matrix or */
00375 /*             vector Z */
00376 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00377 /*          EPS is machine epsilon */
00378 
00379 /*        The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B)) */
00380 /*        is incremented by SAFE1 if the i-th component of */
00381 /*        abs(op(A))*abs(X) + abs(B) is less than SAFE2. */
00382 
00383 /*        Use DLACN2 to estimate the infinity-norm of the matrix */
00384 /*           inv(op(A)) * diag(W), */
00385 /*        where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) */
00386 
00387         i__2 = *n;
00388         for (i__ = 1; i__ <= i__2; ++i__) {
00389             if (work[i__] > safe2) {
00390                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00391                         work[i__];
00392             } else {
00393                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00394                         work[i__] + safe1;
00395             }
00396 /* L60: */
00397         }
00398 
00399         kase = 0;
00400 L70:
00401         dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00402                 kase, isave);
00403         if (kase != 0) {
00404             if (kase == 1) {
00405 
00406 /*              Multiply by diag(W)*inv(op(A)**T). */
00407 
00408                 dgttrs_(transt, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &
00409                         ipiv[1], &work[*n + 1], n, info);
00410                 i__2 = *n;
00411                 for (i__ = 1; i__ <= i__2; ++i__) {
00412                     work[*n + i__] = work[i__] * work[*n + i__];
00413 /* L80: */
00414                 }
00415             } else {
00416 
00417 /*              Multiply by inv(op(A))*diag(W). */
00418 
00419                 i__2 = *n;
00420                 for (i__ = 1; i__ <= i__2; ++i__) {
00421                     work[*n + i__] = work[i__] * work[*n + i__];
00422 /* L90: */
00423                 }
00424                 dgttrs_(transn, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &
00425                         ipiv[1], &work[*n + 1], n, info);
00426             }
00427             goto L70;
00428         }
00429 
00430 /*        Normalize error. */
00431 
00432         lstres = 0.;
00433         i__2 = *n;
00434         for (i__ = 1; i__ <= i__2; ++i__) {
00435 /* Computing MAX */
00436             d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00437             lstres = max(d__2,d__3);
00438 /* L100: */
00439         }
00440         if (lstres != 0.) {
00441             ferr[j] /= lstres;
00442         }
00443 
00444 /* L110: */
00445     }
00446 
00447     return 0;
00448 
00449 /*     End of DGTRFS */
00450 
00451 } /* dgtrfs_ */


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