Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

dgerfs.c

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

Generated on Wed Sep 5 12:54:19 2007 for DSACSS Operational Code by  doxygen 1.3.9.1