dptrfs.c
Go to the documentation of this file.
00001 /* dptrfs.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_b11 = 1.;
00020 
00021 /* Subroutine */ int dptrfs_(integer *n, integer *nrhs, doublereal *d__, 
00022         doublereal *e, doublereal *df, doublereal *ef, doublereal *b, integer 
00023         *ldb, doublereal *x, integer *ldx, doublereal *ferr, doublereal *berr, 
00024          doublereal *work, integer *info)
00025 {
00026     /* System generated locals */
00027     integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2;
00028     doublereal d__1, d__2, d__3;
00029 
00030     /* Local variables */
00031     integer i__, j;
00032     doublereal s, bi, cx, dx, ex;
00033     integer ix, nz;
00034     doublereal eps, safe1, safe2;
00035     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, 
00036             integer *, doublereal *, integer *);
00037     integer count;
00038     extern doublereal dlamch_(char *);
00039     extern integer idamax_(integer *, doublereal *, integer *);
00040     doublereal safmin;
00041     extern /* Subroutine */ int xerbla_(char *, integer *);
00042     doublereal lstres;
00043     extern /* Subroutine */ int dpttrs_(integer *, integer *, doublereal *, 
00044             doublereal *, doublereal *, integer *, integer *);
00045 
00046 
00047 /*  -- LAPACK routine (version 3.2) -- */
00048 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00049 /*     November 2006 */
00050 
00051 /*     .. Scalar Arguments .. */
00052 /*     .. */
00053 /*     .. Array Arguments .. */
00054 /*     .. */
00055 
00056 /*  Purpose */
00057 /*  ======= */
00058 
00059 /*  DPTRFS improves the computed solution to a system of linear */
00060 /*  equations when the coefficient matrix is symmetric positive definite */
00061 /*  and tridiagonal, and provides error bounds and backward error */
00062 /*  estimates for the solution. */
00063 
00064 /*  Arguments */
00065 /*  ========= */
00066 
00067 /*  N       (input) INTEGER */
00068 /*          The order of the matrix A.  N >= 0. */
00069 
00070 /*  NRHS    (input) INTEGER */
00071 /*          The number of right hand sides, i.e., the number of columns */
00072 /*          of the matrix B.  NRHS >= 0. */
00073 
00074 /*  D       (input) DOUBLE PRECISION array, dimension (N) */
00075 /*          The n diagonal elements of the tridiagonal matrix A. */
00076 
00077 /*  E       (input) DOUBLE PRECISION array, dimension (N-1) */
00078 /*          The (n-1) subdiagonal elements of the tridiagonal matrix A. */
00079 
00080 /*  DF      (input) DOUBLE PRECISION array, dimension (N) */
00081 /*          The n diagonal elements of the diagonal matrix D from the */
00082 /*          factorization computed by DPTTRF. */
00083 
00084 /*  EF      (input) DOUBLE PRECISION array, dimension (N-1) */
00085 /*          The (n-1) subdiagonal elements of the unit bidiagonal factor */
00086 /*          L from the factorization computed by DPTTRF. */
00087 
00088 /*  B       (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
00089 /*          The right hand side matrix B. */
00090 
00091 /*  LDB     (input) INTEGER */
00092 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00093 
00094 /*  X       (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
00095 /*          On entry, the solution matrix X, as computed by DPTTRS. */
00096 /*          On exit, the improved solution matrix X. */
00097 
00098 /*  LDX     (input) INTEGER */
00099 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00100 
00101 /*  FERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00102 /*          The forward error bound for each solution vector */
00103 /*          X(j) (the j-th column of the solution matrix X). */
00104 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00105 /*          is an estimated upper bound for the magnitude of the largest */
00106 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00107 /*          largest element in X(j). */
00108 
00109 /*  BERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00110 /*          The componentwise relative backward error of each solution */
00111 /*          vector X(j) (i.e., the smallest relative change in */
00112 /*          any element of A or B that makes X(j) an exact solution). */
00113 
00114 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (2*N) */
00115 
00116 /*  INFO    (output) INTEGER */
00117 /*          = 0:  successful exit */
00118 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00119 
00120 /*  Internal Parameters */
00121 /*  =================== */
00122 
00123 /*  ITMAX is the maximum number of steps of iterative refinement. */
00124 
00125 /*  ===================================================================== */
00126 
00127 /*     .. Parameters .. */
00128 /*     .. */
00129 /*     .. Local Scalars .. */
00130 /*     .. */
00131 /*     .. External Subroutines .. */
00132 /*     .. */
00133 /*     .. Intrinsic Functions .. */
00134 /*     .. */
00135 /*     .. External Functions .. */
00136 /*     .. */
00137 /*     .. Executable Statements .. */
00138 
00139 /*     Test the input parameters. */
00140 
00141     /* Parameter adjustments */
00142     --d__;
00143     --e;
00144     --df;
00145     --ef;
00146     b_dim1 = *ldb;
00147     b_offset = 1 + b_dim1;
00148     b -= b_offset;
00149     x_dim1 = *ldx;
00150     x_offset = 1 + x_dim1;
00151     x -= x_offset;
00152     --ferr;
00153     --berr;
00154     --work;
00155 
00156     /* Function Body */
00157     *info = 0;
00158     if (*n < 0) {
00159         *info = -1;
00160     } else if (*nrhs < 0) {
00161         *info = -2;
00162     } else if (*ldb < max(1,*n)) {
00163         *info = -8;
00164     } else if (*ldx < max(1,*n)) {
00165         *info = -10;
00166     }
00167     if (*info != 0) {
00168         i__1 = -(*info);
00169         xerbla_("DPTRFS", &i__1);
00170         return 0;
00171     }
00172 
00173 /*     Quick return if possible */
00174 
00175     if (*n == 0 || *nrhs == 0) {
00176         i__1 = *nrhs;
00177         for (j = 1; j <= i__1; ++j) {
00178             ferr[j] = 0.;
00179             berr[j] = 0.;
00180 /* L10: */
00181         }
00182         return 0;
00183     }
00184 
00185 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00186 
00187     nz = 4;
00188     eps = dlamch_("Epsilon");
00189     safmin = dlamch_("Safe minimum");
00190     safe1 = nz * safmin;
00191     safe2 = safe1 / eps;
00192 
00193 /*     Do for each right hand side */
00194 
00195     i__1 = *nrhs;
00196     for (j = 1; j <= i__1; ++j) {
00197 
00198         count = 1;
00199         lstres = 3.;
00200 L20:
00201 
00202 /*        Loop until stopping criterion is satisfied. */
00203 
00204 /*        Compute residual R = B - A * X.  Also compute */
00205 /*        abs(A)*abs(x) + abs(b) for use in the backward error bound. */
00206 
00207         if (*n == 1) {
00208             bi = b[j * b_dim1 + 1];
00209             dx = d__[1] * x[j * x_dim1 + 1];
00210             work[*n + 1] = bi - dx;
00211             work[1] = abs(bi) + abs(dx);
00212         } else {
00213             bi = b[j * b_dim1 + 1];
00214             dx = d__[1] * x[j * x_dim1 + 1];
00215             ex = e[1] * x[j * x_dim1 + 2];
00216             work[*n + 1] = bi - dx - ex;
00217             work[1] = abs(bi) + abs(dx) + abs(ex);
00218             i__2 = *n - 1;
00219             for (i__ = 2; i__ <= i__2; ++i__) {
00220                 bi = b[i__ + j * b_dim1];
00221                 cx = e[i__ - 1] * x[i__ - 1 + j * x_dim1];
00222                 dx = d__[i__] * x[i__ + j * x_dim1];
00223                 ex = e[i__] * x[i__ + 1 + j * x_dim1];
00224                 work[*n + i__] = bi - cx - dx - ex;
00225                 work[i__] = abs(bi) + abs(cx) + abs(dx) + abs(ex);
00226 /* L30: */
00227             }
00228             bi = b[*n + j * b_dim1];
00229             cx = e[*n - 1] * x[*n - 1 + j * x_dim1];
00230             dx = d__[*n] * x[*n + j * x_dim1];
00231             work[*n + *n] = bi - cx - dx;
00232             work[*n] = abs(bi) + abs(cx) + abs(dx);
00233         }
00234 
00235 /*        Compute componentwise relative backward error from formula */
00236 
00237 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00238 
00239 /*        where abs(Z) is the componentwise absolute value of the matrix */
00240 /*        or vector Z.  If the i-th component of the denominator is less */
00241 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00242 /*        numerator and denominator before dividing. */
00243 
00244         s = 0.;
00245         i__2 = *n;
00246         for (i__ = 1; i__ <= i__2; ++i__) {
00247             if (work[i__] > safe2) {
00248 /* Computing MAX */
00249                 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
00250                         i__];
00251                 s = max(d__2,d__3);
00252             } else {
00253 /* Computing MAX */
00254                 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) 
00255                         / (work[i__] + safe1);
00256                 s = max(d__2,d__3);
00257             }
00258 /* L40: */
00259         }
00260         berr[j] = s;
00261 
00262 /*        Test stopping criterion. Continue iterating if */
00263 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00264 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00265 /*              last iteration, and */
00266 /*           3) At most ITMAX iterations tried. */
00267 
00268         if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00269 
00270 /*           Update solution and try again. */
00271 
00272             dpttrs_(n, &c__1, &df[1], &ef[1], &work[*n + 1], n, info);
00273             daxpy_(n, &c_b11, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00274                     ;
00275             lstres = berr[j];
00276             ++count;
00277             goto L20;
00278         }
00279 
00280 /*        Bound error from formula */
00281 
00282 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00283 /*        norm( abs(inv(A))* */
00284 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00285 
00286 /*        where */
00287 /*          norm(Z) is the magnitude of the largest component of Z */
00288 /*          inv(A) is the inverse of A */
00289 /*          abs(Z) is the componentwise absolute value of the matrix or */
00290 /*             vector Z */
00291 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00292 /*          EPS is machine epsilon */
00293 
00294 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00295 /*        is incremented by SAFE1 if the i-th component of */
00296 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00297 
00298         i__2 = *n;
00299         for (i__ = 1; i__ <= i__2; ++i__) {
00300             if (work[i__] > safe2) {
00301                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00302                         work[i__];
00303             } else {
00304                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00305                         work[i__] + safe1;
00306             }
00307 /* L50: */
00308         }
00309         ix = idamax_(n, &work[1], &c__1);
00310         ferr[j] = work[ix];
00311 
00312 /*        Estimate the norm of inv(A). */
00313 
00314 /*        Solve M(A) * x = e, where M(A) = (m(i,j)) is given by */
00315 
00316 /*           m(i,j) =  abs(A(i,j)), i = j, */
00317 /*           m(i,j) = -abs(A(i,j)), i .ne. j, */
00318 
00319 /*        and e = [ 1, 1, ..., 1 ]'.  Note M(A) = M(L)*D*M(L)'. */
00320 
00321 /*        Solve M(L) * x = e. */
00322 
00323         work[1] = 1.;
00324         i__2 = *n;
00325         for (i__ = 2; i__ <= i__2; ++i__) {
00326             work[i__] = work[i__ - 1] * (d__1 = ef[i__ - 1], abs(d__1)) + 1.;
00327 /* L60: */
00328         }
00329 
00330 /*        Solve D * M(L)' * x = b. */
00331 
00332         work[*n] /= df[*n];
00333         for (i__ = *n - 1; i__ >= 1; --i__) {
00334             work[i__] = work[i__] / df[i__] + work[i__ + 1] * (d__1 = ef[i__],
00335                      abs(d__1));
00336 /* L70: */
00337         }
00338 
00339 /*        Compute norm(inv(A)) = max(x(i)), 1<=i<=n. */
00340 
00341         ix = idamax_(n, &work[1], &c__1);
00342         ferr[j] *= (d__1 = work[ix], abs(d__1));
00343 
00344 /*        Normalize error. */
00345 
00346         lstres = 0.;
00347         i__2 = *n;
00348         for (i__ = 1; i__ <= i__2; ++i__) {
00349 /* Computing MAX */
00350             d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00351             lstres = max(d__2,d__3);
00352 /* L80: */
00353         }
00354         if (lstres != 0.) {
00355             ferr[j] /= lstres;
00356         }
00357 
00358 /* L90: */
00359     }
00360 
00361     return 0;
00362 
00363 /*     End of DPTRFS */
00364 
00365 } /* dptrfs_ */


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