LAPACK 3.3.0
|
00001 SUBROUTINE DPTRFS( N, NRHS, D, E, DF, EF, B, LDB, X, LDX, FERR, 00002 $ BERR, WORK, INFO ) 00003 * 00004 * -- LAPACK routine (version 3.2) -- 00005 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00006 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00007 * November 2006 00008 * 00009 * .. Scalar Arguments .. 00010 INTEGER INFO, LDB, LDX, N, NRHS 00011 * .. 00012 * .. Array Arguments .. 00013 DOUBLE PRECISION B( LDB, * ), BERR( * ), D( * ), DF( * ), 00014 $ E( * ), EF( * ), FERR( * ), WORK( * ), 00015 $ X( LDX, * ) 00016 * .. 00017 * 00018 * Purpose 00019 * ======= 00020 * 00021 * DPTRFS improves the computed solution to a system of linear 00022 * equations when the coefficient matrix is symmetric positive definite 00023 * and tridiagonal, and provides error bounds and backward error 00024 * estimates for the solution. 00025 * 00026 * Arguments 00027 * ========= 00028 * 00029 * N (input) INTEGER 00030 * The order of the matrix A. N >= 0. 00031 * 00032 * NRHS (input) INTEGER 00033 * The number of right hand sides, i.e., the number of columns 00034 * of the matrix B. NRHS >= 0. 00035 * 00036 * D (input) DOUBLE PRECISION array, dimension (N) 00037 * The n diagonal elements of the tridiagonal matrix A. 00038 * 00039 * E (input) DOUBLE PRECISION array, dimension (N-1) 00040 * The (n-1) subdiagonal elements of the tridiagonal matrix A. 00041 * 00042 * DF (input) DOUBLE PRECISION array, dimension (N) 00043 * The n diagonal elements of the diagonal matrix D from the 00044 * factorization computed by DPTTRF. 00045 * 00046 * EF (input) DOUBLE PRECISION array, dimension (N-1) 00047 * The (n-1) subdiagonal elements of the unit bidiagonal factor 00048 * L from the factorization computed by DPTTRF. 00049 * 00050 * B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) 00051 * The right hand side matrix B. 00052 * 00053 * LDB (input) INTEGER 00054 * The leading dimension of the array B. LDB >= max(1,N). 00055 * 00056 * X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) 00057 * On entry, the solution matrix X, as computed by DPTTRS. 00058 * On exit, the improved solution matrix X. 00059 * 00060 * LDX (input) INTEGER 00061 * The leading dimension of the array X. LDX >= max(1,N). 00062 * 00063 * FERR (output) DOUBLE PRECISION array, dimension (NRHS) 00064 * The forward error bound for each solution vector 00065 * X(j) (the j-th column of the solution matrix X). 00066 * If XTRUE is the true solution corresponding to X(j), FERR(j) 00067 * is an estimated upper bound for the magnitude of the largest 00068 * element in (X(j) - XTRUE) divided by the magnitude of the 00069 * largest element in X(j). 00070 * 00071 * BERR (output) DOUBLE PRECISION array, dimension (NRHS) 00072 * The componentwise relative backward error of each solution 00073 * vector X(j) (i.e., the smallest relative change in 00074 * any element of A or B that makes X(j) an exact solution). 00075 * 00076 * WORK (workspace) DOUBLE PRECISION array, dimension (2*N) 00077 * 00078 * INFO (output) INTEGER 00079 * = 0: successful exit 00080 * < 0: if INFO = -i, the i-th argument had an illegal value 00081 * 00082 * Internal Parameters 00083 * =================== 00084 * 00085 * ITMAX is the maximum number of steps of iterative refinement. 00086 * 00087 * ===================================================================== 00088 * 00089 * .. Parameters .. 00090 INTEGER ITMAX 00091 PARAMETER ( ITMAX = 5 ) 00092 DOUBLE PRECISION ZERO 00093 PARAMETER ( ZERO = 0.0D+0 ) 00094 DOUBLE PRECISION ONE 00095 PARAMETER ( ONE = 1.0D+0 ) 00096 DOUBLE PRECISION TWO 00097 PARAMETER ( TWO = 2.0D+0 ) 00098 DOUBLE PRECISION THREE 00099 PARAMETER ( THREE = 3.0D+0 ) 00100 * .. 00101 * .. Local Scalars .. 00102 INTEGER COUNT, I, IX, J, NZ 00103 DOUBLE PRECISION BI, CX, DX, EPS, EX, LSTRES, S, SAFE1, SAFE2, 00104 $ SAFMIN 00105 * .. 00106 * .. External Subroutines .. 00107 EXTERNAL DAXPY, DPTTRS, XERBLA 00108 * .. 00109 * .. Intrinsic Functions .. 00110 INTRINSIC ABS, MAX 00111 * .. 00112 * .. External Functions .. 00113 INTEGER IDAMAX 00114 DOUBLE PRECISION DLAMCH 00115 EXTERNAL IDAMAX, DLAMCH 00116 * .. 00117 * .. Executable Statements .. 00118 * 00119 * Test the input parameters. 00120 * 00121 INFO = 0 00122 IF( N.LT.0 ) THEN 00123 INFO = -1 00124 ELSE IF( NRHS.LT.0 ) THEN 00125 INFO = -2 00126 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN 00127 INFO = -8 00128 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN 00129 INFO = -10 00130 END IF 00131 IF( INFO.NE.0 ) THEN 00132 CALL XERBLA( 'DPTRFS', -INFO ) 00133 RETURN 00134 END IF 00135 * 00136 * Quick return if possible 00137 * 00138 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN 00139 DO 10 J = 1, NRHS 00140 FERR( J ) = ZERO 00141 BERR( J ) = ZERO 00142 10 CONTINUE 00143 RETURN 00144 END IF 00145 * 00146 * NZ = maximum number of nonzero elements in each row of A, plus 1 00147 * 00148 NZ = 4 00149 EPS = DLAMCH( 'Epsilon' ) 00150 SAFMIN = DLAMCH( 'Safe minimum' ) 00151 SAFE1 = NZ*SAFMIN 00152 SAFE2 = SAFE1 / EPS 00153 * 00154 * Do for each right hand side 00155 * 00156 DO 90 J = 1, NRHS 00157 * 00158 COUNT = 1 00159 LSTRES = THREE 00160 20 CONTINUE 00161 * 00162 * Loop until stopping criterion is satisfied. 00163 * 00164 * Compute residual R = B - A * X. Also compute 00165 * abs(A)*abs(x) + abs(b) for use in the backward error bound. 00166 * 00167 IF( N.EQ.1 ) THEN 00168 BI = B( 1, J ) 00169 DX = D( 1 )*X( 1, J ) 00170 WORK( N+1 ) = BI - DX 00171 WORK( 1 ) = ABS( BI ) + ABS( DX ) 00172 ELSE 00173 BI = B( 1, J ) 00174 DX = D( 1 )*X( 1, J ) 00175 EX = E( 1 )*X( 2, J ) 00176 WORK( N+1 ) = BI - DX - EX 00177 WORK( 1 ) = ABS( BI ) + ABS( DX ) + ABS( EX ) 00178 DO 30 I = 2, N - 1 00179 BI = B( I, J ) 00180 CX = E( I-1 )*X( I-1, J ) 00181 DX = D( I )*X( I, J ) 00182 EX = E( I )*X( I+1, J ) 00183 WORK( N+I ) = BI - CX - DX - EX 00184 WORK( I ) = ABS( BI ) + ABS( CX ) + ABS( DX ) + ABS( EX ) 00185 30 CONTINUE 00186 BI = B( N, J ) 00187 CX = E( N-1 )*X( N-1, J ) 00188 DX = D( N )*X( N, J ) 00189 WORK( N+N ) = BI - CX - DX 00190 WORK( N ) = ABS( BI ) + ABS( CX ) + ABS( DX ) 00191 END IF 00192 * 00193 * Compute componentwise relative backward error from formula 00194 * 00195 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) 00196 * 00197 * where abs(Z) is the componentwise absolute value of the matrix 00198 * or vector Z. If the i-th component of the denominator is less 00199 * than SAFE2, then SAFE1 is added to the i-th components of the 00200 * numerator and denominator before dividing. 00201 * 00202 S = ZERO 00203 DO 40 I = 1, N 00204 IF( WORK( I ).GT.SAFE2 ) THEN 00205 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) ) 00206 ELSE 00207 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) / 00208 $ ( WORK( I )+SAFE1 ) ) 00209 END IF 00210 40 CONTINUE 00211 BERR( J ) = S 00212 * 00213 * Test stopping criterion. Continue iterating if 00214 * 1) The residual BERR(J) is larger than machine epsilon, and 00215 * 2) BERR(J) decreased by at least a factor of 2 during the 00216 * last iteration, and 00217 * 3) At most ITMAX iterations tried. 00218 * 00219 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND. 00220 $ COUNT.LE.ITMAX ) THEN 00221 * 00222 * Update solution and try again. 00223 * 00224 CALL DPTTRS( N, 1, DF, EF, WORK( N+1 ), N, INFO ) 00225 CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 ) 00226 LSTRES = BERR( J ) 00227 COUNT = COUNT + 1 00228 GO TO 20 00229 END IF 00230 * 00231 * Bound error from formula 00232 * 00233 * norm(X - XTRUE) / norm(X) .le. FERR = 00234 * norm( abs(inv(A))* 00235 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) 00236 * 00237 * where 00238 * norm(Z) is the magnitude of the largest component of Z 00239 * inv(A) is the inverse of A 00240 * abs(Z) is the componentwise absolute value of the matrix or 00241 * vector Z 00242 * NZ is the maximum number of nonzeros in any row of A, plus 1 00243 * EPS is machine epsilon 00244 * 00245 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) 00246 * is incremented by SAFE1 if the i-th component of 00247 * abs(A)*abs(X) + abs(B) is less than SAFE2. 00248 * 00249 DO 50 I = 1, N 00250 IF( WORK( I ).GT.SAFE2 ) THEN 00251 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) 00252 ELSE 00253 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1 00254 END IF 00255 50 CONTINUE 00256 IX = IDAMAX( N, WORK, 1 ) 00257 FERR( J ) = WORK( IX ) 00258 * 00259 * Estimate the norm of inv(A). 00260 * 00261 * Solve M(A) * x = e, where M(A) = (m(i,j)) is given by 00262 * 00263 * m(i,j) = abs(A(i,j)), i = j, 00264 * m(i,j) = -abs(A(i,j)), i .ne. j, 00265 * 00266 * and e = [ 1, 1, ..., 1 ]'. Note M(A) = M(L)*D*M(L)'. 00267 * 00268 * Solve M(L) * x = e. 00269 * 00270 WORK( 1 ) = ONE 00271 DO 60 I = 2, N 00272 WORK( I ) = ONE + WORK( I-1 )*ABS( EF( I-1 ) ) 00273 60 CONTINUE 00274 * 00275 * Solve D * M(L)' * x = b. 00276 * 00277 WORK( N ) = WORK( N ) / DF( N ) 00278 DO 70 I = N - 1, 1, -1 00279 WORK( I ) = WORK( I ) / DF( I ) + WORK( I+1 )*ABS( EF( I ) ) 00280 70 CONTINUE 00281 * 00282 * Compute norm(inv(A)) = max(x(i)), 1<=i<=n. 00283 * 00284 IX = IDAMAX( N, WORK, 1 ) 00285 FERR( J ) = FERR( J )*ABS( WORK( IX ) ) 00286 * 00287 * Normalize error. 00288 * 00289 LSTRES = ZERO 00290 DO 80 I = 1, N 00291 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) ) 00292 80 CONTINUE 00293 IF( LSTRES.NE.ZERO ) 00294 $ FERR( J ) = FERR( J ) / LSTRES 00295 * 00296 90 CONTINUE 00297 * 00298 RETURN 00299 * 00300 * End of DPTRFS 00301 * 00302 END