cptrfs.c
Go to the documentation of this file.
00001 /* cptrfs.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 complex c_b16 = {1.f,0.f};
00020 
00021 /* Subroutine */ int cptrfs_(char *uplo, integer *n, integer *nrhs, real *d__, 
00022          complex *e, real *df, complex *ef, complex *b, integer *ldb, complex 
00023         *x, integer *ldx, real *ferr, real *berr, complex *work, real *rwork, 
00024         integer *info)
00025 {
00026     /* System generated locals */
00027     integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5, 
00028             i__6;
00029     real r__1, r__2, r__3, r__4, r__5, r__6, r__7, r__8, r__9, r__10, r__11, 
00030             r__12;
00031     complex q__1, q__2, q__3;
00032 
00033     /* Builtin functions */
00034     double r_imag(complex *);
00035     void r_cnjg(complex *, complex *);
00036     double c_abs(complex *);
00037 
00038     /* Local variables */
00039     integer i__, j;
00040     real s;
00041     complex bi, cx, dx, ex;
00042     integer ix, nz;
00043     real eps, safe1, safe2;
00044     extern logical lsame_(char *, char *);
00045     extern /* Subroutine */ int caxpy_(integer *, complex *, complex *, 
00046             integer *, complex *, integer *);
00047     integer count;
00048     logical upper;
00049     extern doublereal slamch_(char *);
00050     real safmin;
00051     extern /* Subroutine */ int xerbla_(char *, integer *);
00052     extern integer isamax_(integer *, real *, integer *);
00053     real lstres;
00054     extern /* Subroutine */ int cpttrs_(char *, integer *, integer *, real *, 
00055             complex *, complex *, integer *, integer *);
00056 
00057 
00058 /*  -- LAPACK routine (version 3.2) -- */
00059 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00060 /*     November 2006 */
00061 
00062 /*     .. Scalar Arguments .. */
00063 /*     .. */
00064 /*     .. Array Arguments .. */
00065 /*     .. */
00066 
00067 /*  Purpose */
00068 /*  ======= */
00069 
00070 /*  CPTRFS improves the computed solution to a system of linear */
00071 /*  equations when the coefficient matrix is Hermitian positive definite */
00072 /*  and tridiagonal, and provides error bounds and backward error */
00073 /*  estimates for the solution. */
00074 
00075 /*  Arguments */
00076 /*  ========= */
00077 
00078 /*  UPLO    (input) CHARACTER*1 */
00079 /*          Specifies whether the superdiagonal or the subdiagonal of the */
00080 /*          tridiagonal matrix A is stored and the form of the */
00081 /*          factorization: */
00082 /*          = 'U':  E is the superdiagonal of A, and A = U**H*D*U; */
00083 /*          = 'L':  E is the subdiagonal of A, and A = L*D*L**H. */
00084 /*          (The two forms are equivalent if A is real.) */
00085 
00086 /*  N       (input) INTEGER */
00087 /*          The order of the matrix A.  N >= 0. */
00088 
00089 /*  NRHS    (input) INTEGER */
00090 /*          The number of right hand sides, i.e., the number of columns */
00091 /*          of the matrix B.  NRHS >= 0. */
00092 
00093 /*  D       (input) REAL array, dimension (N) */
00094 /*          The n real diagonal elements of the tridiagonal matrix A. */
00095 
00096 /*  E       (input) COMPLEX array, dimension (N-1) */
00097 /*          The (n-1) off-diagonal elements of the tridiagonal matrix A */
00098 /*          (see UPLO). */
00099 
00100 /*  DF      (input) REAL array, dimension (N) */
00101 /*          The n diagonal elements of the diagonal matrix D from */
00102 /*          the factorization computed by CPTTRF. */
00103 
00104 /*  EF      (input) COMPLEX array, dimension (N-1) */
00105 /*          The (n-1) off-diagonal elements of the unit bidiagonal */
00106 /*          factor U or L from the factorization computed by CPTTRF */
00107 /*          (see UPLO). */
00108 
00109 /*  B       (input) COMPLEX array, dimension (LDB,NRHS) */
00110 /*          The right hand side matrix B. */
00111 
00112 /*  LDB     (input) INTEGER */
00113 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00114 
00115 /*  X       (input/output) COMPLEX array, dimension (LDX,NRHS) */
00116 /*          On entry, the solution matrix X, as computed by CPTTRS. */
00117 /*          On exit, the improved solution matrix X. */
00118 
00119 /*  LDX     (input) INTEGER */
00120 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00121 
00122 /*  FERR    (output) REAL array, dimension (NRHS) */
00123 /*          The forward error bound for each solution vector */
00124 /*          X(j) (the j-th column of the solution matrix X). */
00125 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00126 /*          is an estimated upper bound for the magnitude of the largest */
00127 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00128 /*          largest element in X(j). */
00129 
00130 /*  BERR    (output) REAL array, dimension (NRHS) */
00131 /*          The componentwise relative backward error of each solution */
00132 /*          vector X(j) (i.e., the smallest relative change in */
00133 /*          any element of A or B that makes X(j) an exact solution). */
00134 
00135 /*  WORK    (workspace) COMPLEX array, dimension (N) */
00136 
00137 /*  RWORK   (workspace) REAL array, dimension (N) */
00138 
00139 /*  INFO    (output) INTEGER */
00140 /*          = 0:  successful exit */
00141 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00142 
00143 /*  Internal Parameters */
00144 /*  =================== */
00145 
00146 /*  ITMAX is the maximum number of steps of iterative refinement. */
00147 
00148 /*  ===================================================================== */
00149 
00150 /*     .. Parameters .. */
00151 /*     .. */
00152 /*     .. Local Scalars .. */
00153 /*     .. */
00154 /*     .. External Functions .. */
00155 /*     .. */
00156 /*     .. External Subroutines .. */
00157 /*     .. */
00158 /*     .. Intrinsic Functions .. */
00159 /*     .. */
00160 /*     .. Statement Functions .. */
00161 /*     .. */
00162 /*     .. Statement Function definitions .. */
00163 /*     .. */
00164 /*     .. Executable Statements .. */
00165 
00166 /*     Test the input parameters. */
00167 
00168     /* Parameter adjustments */
00169     --d__;
00170     --e;
00171     --df;
00172     --ef;
00173     b_dim1 = *ldb;
00174     b_offset = 1 + b_dim1;
00175     b -= b_offset;
00176     x_dim1 = *ldx;
00177     x_offset = 1 + x_dim1;
00178     x -= x_offset;
00179     --ferr;
00180     --berr;
00181     --work;
00182     --rwork;
00183 
00184     /* Function Body */
00185     *info = 0;
00186     upper = lsame_(uplo, "U");
00187     if (! upper && ! lsame_(uplo, "L")) {
00188         *info = -1;
00189     } else if (*n < 0) {
00190         *info = -2;
00191     } else if (*nrhs < 0) {
00192         *info = -3;
00193     } else if (*ldb < max(1,*n)) {
00194         *info = -9;
00195     } else if (*ldx < max(1,*n)) {
00196         *info = -11;
00197     }
00198     if (*info != 0) {
00199         i__1 = -(*info);
00200         xerbla_("CPTRFS", &i__1);
00201         return 0;
00202     }
00203 
00204 /*     Quick return if possible */
00205 
00206     if (*n == 0 || *nrhs == 0) {
00207         i__1 = *nrhs;
00208         for (j = 1; j <= i__1; ++j) {
00209             ferr[j] = 0.f;
00210             berr[j] = 0.f;
00211 /* L10: */
00212         }
00213         return 0;
00214     }
00215 
00216 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00217 
00218     nz = 4;
00219     eps = slamch_("Epsilon");
00220     safmin = slamch_("Safe minimum");
00221     safe1 = nz * safmin;
00222     safe2 = safe1 / eps;
00223 
00224 /*     Do for each right hand side */
00225 
00226     i__1 = *nrhs;
00227     for (j = 1; j <= i__1; ++j) {
00228 
00229         count = 1;
00230         lstres = 3.f;
00231 L20:
00232 
00233 /*        Loop until stopping criterion is satisfied. */
00234 
00235 /*        Compute residual R = B - A * X.  Also compute */
00236 /*        abs(A)*abs(x) + abs(b) for use in the backward error bound. */
00237 
00238         if (upper) {
00239             if (*n == 1) {
00240                 i__2 = j * b_dim1 + 1;
00241                 bi.r = b[i__2].r, bi.i = b[i__2].i;
00242                 i__2 = j * x_dim1 + 1;
00243                 q__1.r = d__[1] * x[i__2].r, q__1.i = d__[1] * x[i__2].i;
00244                 dx.r = q__1.r, dx.i = q__1.i;
00245                 q__1.r = bi.r - dx.r, q__1.i = bi.i - dx.i;
00246                 work[1].r = q__1.r, work[1].i = q__1.i;
00247                 rwork[1] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi), 
00248                         dabs(r__2)) + ((r__3 = dx.r, dabs(r__3)) + (r__4 = 
00249                         r_imag(&dx), dabs(r__4)));
00250             } else {
00251                 i__2 = j * b_dim1 + 1;
00252                 bi.r = b[i__2].r, bi.i = b[i__2].i;
00253                 i__2 = j * x_dim1 + 1;
00254                 q__1.r = d__[1] * x[i__2].r, q__1.i = d__[1] * x[i__2].i;
00255                 dx.r = q__1.r, dx.i = q__1.i;
00256                 i__2 = j * x_dim1 + 2;
00257                 q__1.r = e[1].r * x[i__2].r - e[1].i * x[i__2].i, q__1.i = e[
00258                         1].r * x[i__2].i + e[1].i * x[i__2].r;
00259                 ex.r = q__1.r, ex.i = q__1.i;
00260                 q__2.r = bi.r - dx.r, q__2.i = bi.i - dx.i;
00261                 q__1.r = q__2.r - ex.r, q__1.i = q__2.i - ex.i;
00262                 work[1].r = q__1.r, work[1].i = q__1.i;
00263                 i__2 = j * x_dim1 + 2;
00264                 rwork[1] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi), 
00265                         dabs(r__2)) + ((r__3 = dx.r, dabs(r__3)) + (r__4 = 
00266                         r_imag(&dx), dabs(r__4))) + ((r__5 = e[1].r, dabs(
00267                         r__5)) + (r__6 = r_imag(&e[1]), dabs(r__6))) * ((r__7 
00268                         = x[i__2].r, dabs(r__7)) + (r__8 = r_imag(&x[j * 
00269                         x_dim1 + 2]), dabs(r__8)));
00270                 i__2 = *n - 1;
00271                 for (i__ = 2; i__ <= i__2; ++i__) {
00272                     i__3 = i__ + j * b_dim1;
00273                     bi.r = b[i__3].r, bi.i = b[i__3].i;
00274                     r_cnjg(&q__2, &e[i__ - 1]);
00275                     i__3 = i__ - 1 + j * x_dim1;
00276                     q__1.r = q__2.r * x[i__3].r - q__2.i * x[i__3].i, q__1.i =
00277                              q__2.r * x[i__3].i + q__2.i * x[i__3].r;
00278                     cx.r = q__1.r, cx.i = q__1.i;
00279                     i__3 = i__;
00280                     i__4 = i__ + j * x_dim1;
00281                     q__1.r = d__[i__3] * x[i__4].r, q__1.i = d__[i__3] * x[
00282                             i__4].i;
00283                     dx.r = q__1.r, dx.i = q__1.i;
00284                     i__3 = i__;
00285                     i__4 = i__ + 1 + j * x_dim1;
00286                     q__1.r = e[i__3].r * x[i__4].r - e[i__3].i * x[i__4].i, 
00287                             q__1.i = e[i__3].r * x[i__4].i + e[i__3].i * x[
00288                             i__4].r;
00289                     ex.r = q__1.r, ex.i = q__1.i;
00290                     i__3 = i__;
00291                     q__3.r = bi.r - cx.r, q__3.i = bi.i - cx.i;
00292                     q__2.r = q__3.r - dx.r, q__2.i = q__3.i - dx.i;
00293                     q__1.r = q__2.r - ex.r, q__1.i = q__2.i - ex.i;
00294                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00295                     i__3 = i__ - 1;
00296                     i__4 = i__ - 1 + j * x_dim1;
00297                     i__5 = i__;
00298                     i__6 = i__ + 1 + j * x_dim1;
00299                     rwork[i__] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&
00300                             bi), dabs(r__2)) + ((r__3 = e[i__3].r, dabs(r__3))
00301                              + (r__4 = r_imag(&e[i__ - 1]), dabs(r__4))) * ((
00302                             r__5 = x[i__4].r, dabs(r__5)) + (r__6 = r_imag(&x[
00303                             i__ - 1 + j * x_dim1]), dabs(r__6))) + ((r__7 = 
00304                             dx.r, dabs(r__7)) + (r__8 = r_imag(&dx), dabs(
00305                             r__8))) + ((r__9 = e[i__5].r, dabs(r__9)) + (
00306                             r__10 = r_imag(&e[i__]), dabs(r__10))) * ((r__11 =
00307                              x[i__6].r, dabs(r__11)) + (r__12 = r_imag(&x[i__ 
00308                             + 1 + j * x_dim1]), dabs(r__12)));
00309 /* L30: */
00310                 }
00311                 i__2 = *n + j * b_dim1;
00312                 bi.r = b[i__2].r, bi.i = b[i__2].i;
00313                 r_cnjg(&q__2, &e[*n - 1]);
00314                 i__2 = *n - 1 + j * x_dim1;
00315                 q__1.r = q__2.r * x[i__2].r - q__2.i * x[i__2].i, q__1.i = 
00316                         q__2.r * x[i__2].i + q__2.i * x[i__2].r;
00317                 cx.r = q__1.r, cx.i = q__1.i;
00318                 i__2 = *n;
00319                 i__3 = *n + j * x_dim1;
00320                 q__1.r = d__[i__2] * x[i__3].r, q__1.i = d__[i__2] * x[i__3]
00321                         .i;
00322                 dx.r = q__1.r, dx.i = q__1.i;
00323                 i__2 = *n;
00324                 q__2.r = bi.r - cx.r, q__2.i = bi.i - cx.i;
00325                 q__1.r = q__2.r - dx.r, q__1.i = q__2.i - dx.i;
00326                 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00327                 i__2 = *n - 1;
00328                 i__3 = *n - 1 + j * x_dim1;
00329                 rwork[*n] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi), 
00330                         dabs(r__2)) + ((r__3 = e[i__2].r, dabs(r__3)) + (r__4 
00331                         = r_imag(&e[*n - 1]), dabs(r__4))) * ((r__5 = x[i__3]
00332                         .r, dabs(r__5)) + (r__6 = r_imag(&x[*n - 1 + j * 
00333                         x_dim1]), dabs(r__6))) + ((r__7 = dx.r, dabs(r__7)) + 
00334                         (r__8 = r_imag(&dx), dabs(r__8)));
00335             }
00336         } else {
00337             if (*n == 1) {
00338                 i__2 = j * b_dim1 + 1;
00339                 bi.r = b[i__2].r, bi.i = b[i__2].i;
00340                 i__2 = j * x_dim1 + 1;
00341                 q__1.r = d__[1] * x[i__2].r, q__1.i = d__[1] * x[i__2].i;
00342                 dx.r = q__1.r, dx.i = q__1.i;
00343                 q__1.r = bi.r - dx.r, q__1.i = bi.i - dx.i;
00344                 work[1].r = q__1.r, work[1].i = q__1.i;
00345                 rwork[1] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi), 
00346                         dabs(r__2)) + ((r__3 = dx.r, dabs(r__3)) + (r__4 = 
00347                         r_imag(&dx), dabs(r__4)));
00348             } else {
00349                 i__2 = j * b_dim1 + 1;
00350                 bi.r = b[i__2].r, bi.i = b[i__2].i;
00351                 i__2 = j * x_dim1 + 1;
00352                 q__1.r = d__[1] * x[i__2].r, q__1.i = d__[1] * x[i__2].i;
00353                 dx.r = q__1.r, dx.i = q__1.i;
00354                 r_cnjg(&q__2, &e[1]);
00355                 i__2 = j * x_dim1 + 2;
00356                 q__1.r = q__2.r * x[i__2].r - q__2.i * x[i__2].i, q__1.i = 
00357                         q__2.r * x[i__2].i + q__2.i * x[i__2].r;
00358                 ex.r = q__1.r, ex.i = q__1.i;
00359                 q__2.r = bi.r - dx.r, q__2.i = bi.i - dx.i;
00360                 q__1.r = q__2.r - ex.r, q__1.i = q__2.i - ex.i;
00361                 work[1].r = q__1.r, work[1].i = q__1.i;
00362                 i__2 = j * x_dim1 + 2;
00363                 rwork[1] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi), 
00364                         dabs(r__2)) + ((r__3 = dx.r, dabs(r__3)) + (r__4 = 
00365                         r_imag(&dx), dabs(r__4))) + ((r__5 = e[1].r, dabs(
00366                         r__5)) + (r__6 = r_imag(&e[1]), dabs(r__6))) * ((r__7 
00367                         = x[i__2].r, dabs(r__7)) + (r__8 = r_imag(&x[j * 
00368                         x_dim1 + 2]), dabs(r__8)));
00369                 i__2 = *n - 1;
00370                 for (i__ = 2; i__ <= i__2; ++i__) {
00371                     i__3 = i__ + j * b_dim1;
00372                     bi.r = b[i__3].r, bi.i = b[i__3].i;
00373                     i__3 = i__ - 1;
00374                     i__4 = i__ - 1 + j * x_dim1;
00375                     q__1.r = e[i__3].r * x[i__4].r - e[i__3].i * x[i__4].i, 
00376                             q__1.i = e[i__3].r * x[i__4].i + e[i__3].i * x[
00377                             i__4].r;
00378                     cx.r = q__1.r, cx.i = q__1.i;
00379                     i__3 = i__;
00380                     i__4 = i__ + j * x_dim1;
00381                     q__1.r = d__[i__3] * x[i__4].r, q__1.i = d__[i__3] * x[
00382                             i__4].i;
00383                     dx.r = q__1.r, dx.i = q__1.i;
00384                     r_cnjg(&q__2, &e[i__]);
00385                     i__3 = i__ + 1 + j * x_dim1;
00386                     q__1.r = q__2.r * x[i__3].r - q__2.i * x[i__3].i, q__1.i =
00387                              q__2.r * x[i__3].i + q__2.i * x[i__3].r;
00388                     ex.r = q__1.r, ex.i = q__1.i;
00389                     i__3 = i__;
00390                     q__3.r = bi.r - cx.r, q__3.i = bi.i - cx.i;
00391                     q__2.r = q__3.r - dx.r, q__2.i = q__3.i - dx.i;
00392                     q__1.r = q__2.r - ex.r, q__1.i = q__2.i - ex.i;
00393                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00394                     i__3 = i__ - 1;
00395                     i__4 = i__ - 1 + j * x_dim1;
00396                     i__5 = i__;
00397                     i__6 = i__ + 1 + j * x_dim1;
00398                     rwork[i__] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&
00399                             bi), dabs(r__2)) + ((r__3 = e[i__3].r, dabs(r__3))
00400                              + (r__4 = r_imag(&e[i__ - 1]), dabs(r__4))) * ((
00401                             r__5 = x[i__4].r, dabs(r__5)) + (r__6 = r_imag(&x[
00402                             i__ - 1 + j * x_dim1]), dabs(r__6))) + ((r__7 = 
00403                             dx.r, dabs(r__7)) + (r__8 = r_imag(&dx), dabs(
00404                             r__8))) + ((r__9 = e[i__5].r, dabs(r__9)) + (
00405                             r__10 = r_imag(&e[i__]), dabs(r__10))) * ((r__11 =
00406                              x[i__6].r, dabs(r__11)) + (r__12 = r_imag(&x[i__ 
00407                             + 1 + j * x_dim1]), dabs(r__12)));
00408 /* L40: */
00409                 }
00410                 i__2 = *n + j * b_dim1;
00411                 bi.r = b[i__2].r, bi.i = b[i__2].i;
00412                 i__2 = *n - 1;
00413                 i__3 = *n - 1 + j * x_dim1;
00414                 q__1.r = e[i__2].r * x[i__3].r - e[i__2].i * x[i__3].i, 
00415                         q__1.i = e[i__2].r * x[i__3].i + e[i__2].i * x[i__3]
00416                         .r;
00417                 cx.r = q__1.r, cx.i = q__1.i;
00418                 i__2 = *n;
00419                 i__3 = *n + j * x_dim1;
00420                 q__1.r = d__[i__2] * x[i__3].r, q__1.i = d__[i__2] * x[i__3]
00421                         .i;
00422                 dx.r = q__1.r, dx.i = q__1.i;
00423                 i__2 = *n;
00424                 q__2.r = bi.r - cx.r, q__2.i = bi.i - cx.i;
00425                 q__1.r = q__2.r - dx.r, q__1.i = q__2.i - dx.i;
00426                 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00427                 i__2 = *n - 1;
00428                 i__3 = *n - 1 + j * x_dim1;
00429                 rwork[*n] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi), 
00430                         dabs(r__2)) + ((r__3 = e[i__2].r, dabs(r__3)) + (r__4 
00431                         = r_imag(&e[*n - 1]), dabs(r__4))) * ((r__5 = x[i__3]
00432                         .r, dabs(r__5)) + (r__6 = r_imag(&x[*n - 1 + j * 
00433                         x_dim1]), dabs(r__6))) + ((r__7 = dx.r, dabs(r__7)) + 
00434                         (r__8 = r_imag(&dx), dabs(r__8)));
00435             }
00436         }
00437 
00438 /*        Compute componentwise relative backward error from formula */
00439 
00440 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00441 
00442 /*        where abs(Z) is the componentwise absolute value of the matrix */
00443 /*        or vector Z.  If the i-th component of the denominator is less */
00444 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00445 /*        numerator and denominator before dividing. */
00446 
00447         s = 0.f;
00448         i__2 = *n;
00449         for (i__ = 1; i__ <= i__2; ++i__) {
00450             if (rwork[i__] > safe2) {
00451 /* Computing MAX */
00452                 i__3 = i__;
00453                 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00454                         r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00455                 s = dmax(r__3,r__4);
00456             } else {
00457 /* Computing MAX */
00458                 i__3 = i__;
00459                 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00460                         r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00461                          + safe1);
00462                 s = dmax(r__3,r__4);
00463             }
00464 /* L50: */
00465         }
00466         berr[j] = s;
00467 
00468 /*        Test stopping criterion. Continue iterating if */
00469 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00470 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00471 /*              last iteration, and */
00472 /*           3) At most ITMAX iterations tried. */
00473 
00474         if (berr[j] > eps && berr[j] * 2.f <= lstres && count <= 5) {
00475 
00476 /*           Update solution and try again. */
00477 
00478             cpttrs_(uplo, n, &c__1, &df[1], &ef[1], &work[1], n, info);
00479             caxpy_(n, &c_b16, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00480             lstres = berr[j];
00481             ++count;
00482             goto L20;
00483         }
00484 
00485 /*        Bound error from formula */
00486 
00487 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00488 /*        norm( abs(inv(A))* */
00489 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00490 
00491 /*        where */
00492 /*          norm(Z) is the magnitude of the largest component of Z */
00493 /*          inv(A) is the inverse of A */
00494 /*          abs(Z) is the componentwise absolute value of the matrix or */
00495 /*             vector Z */
00496 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00497 /*          EPS is machine epsilon */
00498 
00499 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00500 /*        is incremented by SAFE1 if the i-th component of */
00501 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00502 
00503         i__2 = *n;
00504         for (i__ = 1; i__ <= i__2; ++i__) {
00505             if (rwork[i__] > safe2) {
00506                 i__3 = i__;
00507                 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00508                         r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00509                         i__];
00510             } else {
00511                 i__3 = i__;
00512                 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00513                         r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00514                         i__] + safe1;
00515             }
00516 /* L60: */
00517         }
00518         ix = isamax_(n, &rwork[1], &c__1);
00519         ferr[j] = rwork[ix];
00520 
00521 /*        Estimate the norm of inv(A). */
00522 
00523 /*        Solve M(A) * x = e, where M(A) = (m(i,j)) is given by */
00524 
00525 /*           m(i,j) =  abs(A(i,j)), i = j, */
00526 /*           m(i,j) = -abs(A(i,j)), i .ne. j, */
00527 
00528 /*        and e = [ 1, 1, ..., 1 ]'.  Note M(A) = M(L)*D*M(L)'. */
00529 
00530 /*        Solve M(L) * x = e. */
00531 
00532         rwork[1] = 1.f;
00533         i__2 = *n;
00534         for (i__ = 2; i__ <= i__2; ++i__) {
00535             rwork[i__] = rwork[i__ - 1] * c_abs(&ef[i__ - 1]) + 1.f;
00536 /* L70: */
00537         }
00538 
00539 /*        Solve D * M(L)' * x = b. */
00540 
00541         rwork[*n] /= df[*n];
00542         for (i__ = *n - 1; i__ >= 1; --i__) {
00543             rwork[i__] = rwork[i__] / df[i__] + rwork[i__ + 1] * c_abs(&ef[
00544                     i__]);
00545 /* L80: */
00546         }
00547 
00548 /*        Compute norm(inv(A)) = max(x(i)), 1<=i<=n. */
00549 
00550         ix = isamax_(n, &rwork[1], &c__1);
00551         ferr[j] *= (r__1 = rwork[ix], dabs(r__1));
00552 
00553 /*        Normalize error. */
00554 
00555         lstres = 0.f;
00556         i__2 = *n;
00557         for (i__ = 1; i__ <= i__2; ++i__) {
00558 /* Computing MAX */
00559             r__1 = lstres, r__2 = c_abs(&x[i__ + j * x_dim1]);
00560             lstres = dmax(r__1,r__2);
00561 /* L90: */
00562         }
00563         if (lstres != 0.f) {
00564             ferr[j] /= lstres;
00565         }
00566 
00567 /* L100: */
00568     }
00569 
00570     return 0;
00571 
00572 /*     End of CPTRFS */
00573 
00574 } /* cptrfs_ */


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