00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__1 = 1;
00019 static doublereal c_b11 = 1.;
00020
00021 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
00027 integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2;
00028 doublereal d__1, d__2, d__3;
00029
00030
00031 integer i__, j;
00032 doublereal s, bi, cx, dx, ex;
00033 integer ix, nz;
00034 doublereal eps, safe1, safe2;
00035 extern 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 int xerbla_(char *, integer *);
00042 doublereal lstres;
00043 extern int dpttrs_(integer *, integer *, doublereal *,
00044 doublereal *, doublereal *, integer *, integer *);
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
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
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
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
00181 }
00182 return 0;
00183 }
00184
00185
00186
00187 nz = 4;
00188 eps = dlamch_("Epsilon");
00189 safmin = dlamch_("Safe minimum");
00190 safe1 = nz * safmin;
00191 safe2 = safe1 / eps;
00192
00193
00194
00195 i__1 = *nrhs;
00196 for (j = 1; j <= i__1; ++j) {
00197
00198 count = 1;
00199 lstres = 3.;
00200 L20:
00201
00202
00203
00204
00205
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
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
00236
00237
00238
00239
00240
00241
00242
00243
00244 s = 0.;
00245 i__2 = *n;
00246 for (i__ = 1; i__ <= i__2; ++i__) {
00247 if (work[i__] > safe2) {
00248
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
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
00259 }
00260 berr[j] = s;
00261
00262
00263
00264
00265
00266
00267
00268 if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00269
00270
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
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
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
00308 }
00309 ix = idamax_(n, &work[1], &c__1);
00310 ferr[j] = work[ix];
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
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
00328 }
00329
00330
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
00337 }
00338
00339
00340
00341 ix = idamax_(n, &work[1], &c__1);
00342 ferr[j] *= (d__1 = work[ix], abs(d__1));
00343
00344
00345
00346 lstres = 0.;
00347 i__2 = *n;
00348 for (i__ = 1; i__ <= i__2; ++i__) {
00349
00350 d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00351 lstres = max(d__2,d__3);
00352
00353 }
00354 if (lstres != 0.) {
00355 ferr[j] /= lstres;
00356 }
00357
00358
00359 }
00360
00361 return 0;
00362
00363
00364
00365 }