![]() |
LAPACK
3.4.1
LAPACK: Linear Algebra PACKage
|
00001 *> \brief \b DSPRFS 00002 * 00003 * =========== DOCUMENTATION =========== 00004 * 00005 * Online html documentation available at 00006 * http://www.netlib.org/lapack/explore-html/ 00007 * 00008 *> \htmlonly 00009 *> Download DSPRFS + dependencies 00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsprfs.f"> 00011 *> [TGZ]</a> 00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsprfs.f"> 00013 *> [ZIP]</a> 00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsprfs.f"> 00015 *> [TXT]</a> 00016 *> \endhtmlonly 00017 * 00018 * Definition: 00019 * =========== 00020 * 00021 * SUBROUTINE DSPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX, 00022 * FERR, BERR, WORK, IWORK, INFO ) 00023 * 00024 * .. Scalar Arguments .. 00025 * CHARACTER UPLO 00026 * INTEGER INFO, LDB, LDX, N, NRHS 00027 * .. 00028 * .. Array Arguments .. 00029 * INTEGER IPIV( * ), IWORK( * ) 00030 * DOUBLE PRECISION AFP( * ), AP( * ), B( LDB, * ), BERR( * ), 00031 * $ FERR( * ), WORK( * ), X( LDX, * ) 00032 * .. 00033 * 00034 * 00035 *> \par Purpose: 00036 * ============= 00037 *> 00038 *> \verbatim 00039 *> 00040 *> DSPRFS improves the computed solution to a system of linear 00041 *> equations when the coefficient matrix is symmetric indefinite 00042 *> and packed, and provides error bounds and backward error estimates 00043 *> for the solution. 00044 *> \endverbatim 00045 * 00046 * Arguments: 00047 * ========== 00048 * 00049 *> \param[in] UPLO 00050 *> \verbatim 00051 *> UPLO is CHARACTER*1 00052 *> = 'U': Upper triangle of A is stored; 00053 *> = 'L': Lower triangle of A is stored. 00054 *> \endverbatim 00055 *> 00056 *> \param[in] N 00057 *> \verbatim 00058 *> N is INTEGER 00059 *> The order of the matrix A. N >= 0. 00060 *> \endverbatim 00061 *> 00062 *> \param[in] NRHS 00063 *> \verbatim 00064 *> NRHS is INTEGER 00065 *> The number of right hand sides, i.e., the number of columns 00066 *> of the matrices B and X. NRHS >= 0. 00067 *> \endverbatim 00068 *> 00069 *> \param[in] AP 00070 *> \verbatim 00071 *> AP is DOUBLE PRECISION array, dimension (N*(N+1)/2) 00072 *> The upper or lower triangle of the symmetric matrix A, packed 00073 *> columnwise in a linear array. The j-th column of A is stored 00074 *> in the array AP as follows: 00075 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; 00076 *> if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. 00077 *> \endverbatim 00078 *> 00079 *> \param[in] AFP 00080 *> \verbatim 00081 *> AFP is DOUBLE PRECISION array, dimension (N*(N+1)/2) 00082 *> The factored form of the matrix A. AFP contains the block 00083 *> diagonal matrix D and the multipliers used to obtain the 00084 *> factor U or L from the factorization A = U*D*U**T or 00085 *> A = L*D*L**T as computed by DSPTRF, stored as a packed 00086 *> triangular matrix. 00087 *> \endverbatim 00088 *> 00089 *> \param[in] IPIV 00090 *> \verbatim 00091 *> IPIV is INTEGER array, dimension (N) 00092 *> Details of the interchanges and the block structure of D 00093 *> as determined by DSPTRF. 00094 *> \endverbatim 00095 *> 00096 *> \param[in] B 00097 *> \verbatim 00098 *> B is DOUBLE PRECISION array, dimension (LDB,NRHS) 00099 *> The right hand side matrix B. 00100 *> \endverbatim 00101 *> 00102 *> \param[in] LDB 00103 *> \verbatim 00104 *> LDB is INTEGER 00105 *> The leading dimension of the array B. LDB >= max(1,N). 00106 *> \endverbatim 00107 *> 00108 *> \param[in,out] X 00109 *> \verbatim 00110 *> X is DOUBLE PRECISION array, dimension (LDX,NRHS) 00111 *> On entry, the solution matrix X, as computed by DSPTRS. 00112 *> On exit, the improved solution matrix X. 00113 *> \endverbatim 00114 *> 00115 *> \param[in] LDX 00116 *> \verbatim 00117 *> LDX is INTEGER 00118 *> The leading dimension of the array X. LDX >= max(1,N). 00119 *> \endverbatim 00120 *> 00121 *> \param[out] FERR 00122 *> \verbatim 00123 *> FERR is DOUBLE PRECISION array, dimension (NRHS) 00124 *> The estimated forward error bound for each solution vector 00125 *> X(j) (the j-th column of the solution matrix X). 00126 *> If XTRUE is the true solution corresponding to X(j), FERR(j) 00127 *> is an estimated upper bound for the magnitude of the largest 00128 *> element in (X(j) - XTRUE) divided by the magnitude of the 00129 *> largest element in X(j). The estimate is as reliable as 00130 *> the estimate for RCOND, and is almost always a slight 00131 *> overestimate of the true error. 00132 *> \endverbatim 00133 *> 00134 *> \param[out] BERR 00135 *> \verbatim 00136 *> BERR is DOUBLE PRECISION array, dimension (NRHS) 00137 *> The componentwise relative backward error of each solution 00138 *> vector X(j) (i.e., the smallest relative change in 00139 *> any element of A or B that makes X(j) an exact solution). 00140 *> \endverbatim 00141 *> 00142 *> \param[out] WORK 00143 *> \verbatim 00144 *> WORK is DOUBLE PRECISION array, dimension (3*N) 00145 *> \endverbatim 00146 *> 00147 *> \param[out] IWORK 00148 *> \verbatim 00149 *> IWORK is INTEGER array, dimension (N) 00150 *> \endverbatim 00151 *> 00152 *> \param[out] INFO 00153 *> \verbatim 00154 *> INFO is INTEGER 00155 *> = 0: successful exit 00156 *> < 0: if INFO = -i, the i-th argument had an illegal value 00157 *> \endverbatim 00158 * 00159 *> \par Internal Parameters: 00160 * ========================= 00161 *> 00162 *> \verbatim 00163 *> ITMAX is the maximum number of steps of iterative refinement. 00164 *> \endverbatim 00165 * 00166 * Authors: 00167 * ======== 00168 * 00169 *> \author Univ. of Tennessee 00170 *> \author Univ. of California Berkeley 00171 *> \author Univ. of Colorado Denver 00172 *> \author NAG Ltd. 00173 * 00174 *> \date November 2011 00175 * 00176 *> \ingroup doubleOTHERcomputational 00177 * 00178 * ===================================================================== 00179 SUBROUTINE DSPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX, 00180 $ FERR, BERR, WORK, IWORK, INFO ) 00181 * 00182 * -- LAPACK computational routine (version 3.4.0) -- 00183 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00184 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00185 * November 2011 00186 * 00187 * .. Scalar Arguments .. 00188 CHARACTER UPLO 00189 INTEGER INFO, LDB, LDX, N, NRHS 00190 * .. 00191 * .. Array Arguments .. 00192 INTEGER IPIV( * ), IWORK( * ) 00193 DOUBLE PRECISION AFP( * ), AP( * ), B( LDB, * ), BERR( * ), 00194 $ FERR( * ), WORK( * ), X( LDX, * ) 00195 * .. 00196 * 00197 * ===================================================================== 00198 * 00199 * .. Parameters .. 00200 INTEGER ITMAX 00201 PARAMETER ( ITMAX = 5 ) 00202 DOUBLE PRECISION ZERO 00203 PARAMETER ( ZERO = 0.0D+0 ) 00204 DOUBLE PRECISION ONE 00205 PARAMETER ( ONE = 1.0D+0 ) 00206 DOUBLE PRECISION TWO 00207 PARAMETER ( TWO = 2.0D+0 ) 00208 DOUBLE PRECISION THREE 00209 PARAMETER ( THREE = 3.0D+0 ) 00210 * .. 00211 * .. Local Scalars .. 00212 LOGICAL UPPER 00213 INTEGER COUNT, I, IK, J, K, KASE, KK, NZ 00214 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK 00215 * .. 00216 * .. Local Arrays .. 00217 INTEGER ISAVE( 3 ) 00218 * .. 00219 * .. External Subroutines .. 00220 EXTERNAL DAXPY, DCOPY, DLACN2, DSPMV, DSPTRS, XERBLA 00221 * .. 00222 * .. Intrinsic Functions .. 00223 INTRINSIC ABS, MAX 00224 * .. 00225 * .. External Functions .. 00226 LOGICAL LSAME 00227 DOUBLE PRECISION DLAMCH 00228 EXTERNAL LSAME, DLAMCH 00229 * .. 00230 * .. Executable Statements .. 00231 * 00232 * Test the input parameters. 00233 * 00234 INFO = 0 00235 UPPER = LSAME( UPLO, 'U' ) 00236 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN 00237 INFO = -1 00238 ELSE IF( N.LT.0 ) THEN 00239 INFO = -2 00240 ELSE IF( NRHS.LT.0 ) THEN 00241 INFO = -3 00242 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN 00243 INFO = -8 00244 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN 00245 INFO = -10 00246 END IF 00247 IF( INFO.NE.0 ) THEN 00248 CALL XERBLA( 'DSPRFS', -INFO ) 00249 RETURN 00250 END IF 00251 * 00252 * Quick return if possible 00253 * 00254 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN 00255 DO 10 J = 1, NRHS 00256 FERR( J ) = ZERO 00257 BERR( J ) = ZERO 00258 10 CONTINUE 00259 RETURN 00260 END IF 00261 * 00262 * NZ = maximum number of nonzero elements in each row of A, plus 1 00263 * 00264 NZ = N + 1 00265 EPS = DLAMCH( 'Epsilon' ) 00266 SAFMIN = DLAMCH( 'Safe minimum' ) 00267 SAFE1 = NZ*SAFMIN 00268 SAFE2 = SAFE1 / EPS 00269 * 00270 * Do for each right hand side 00271 * 00272 DO 140 J = 1, NRHS 00273 * 00274 COUNT = 1 00275 LSTRES = THREE 00276 20 CONTINUE 00277 * 00278 * Loop until stopping criterion is satisfied. 00279 * 00280 * Compute residual R = B - A * X 00281 * 00282 CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 ) 00283 CALL DSPMV( UPLO, N, -ONE, AP, X( 1, J ), 1, ONE, WORK( N+1 ), 00284 $ 1 ) 00285 * 00286 * Compute componentwise relative backward error from formula 00287 * 00288 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) 00289 * 00290 * where abs(Z) is the componentwise absolute value of the matrix 00291 * or vector Z. If the i-th component of the denominator is less 00292 * than SAFE2, then SAFE1 is added to the i-th components of the 00293 * numerator and denominator before dividing. 00294 * 00295 DO 30 I = 1, N 00296 WORK( I ) = ABS( B( I, J ) ) 00297 30 CONTINUE 00298 * 00299 * Compute abs(A)*abs(X) + abs(B). 00300 * 00301 KK = 1 00302 IF( UPPER ) THEN 00303 DO 50 K = 1, N 00304 S = ZERO 00305 XK = ABS( X( K, J ) ) 00306 IK = KK 00307 DO 40 I = 1, K - 1 00308 WORK( I ) = WORK( I ) + ABS( AP( IK ) )*XK 00309 S = S + ABS( AP( IK ) )*ABS( X( I, J ) ) 00310 IK = IK + 1 00311 40 CONTINUE 00312 WORK( K ) = WORK( K ) + ABS( AP( KK+K-1 ) )*XK + S 00313 KK = KK + K 00314 50 CONTINUE 00315 ELSE 00316 DO 70 K = 1, N 00317 S = ZERO 00318 XK = ABS( X( K, J ) ) 00319 WORK( K ) = WORK( K ) + ABS( AP( KK ) )*XK 00320 IK = KK + 1 00321 DO 60 I = K + 1, N 00322 WORK( I ) = WORK( I ) + ABS( AP( IK ) )*XK 00323 S = S + ABS( AP( IK ) )*ABS( X( I, J ) ) 00324 IK = IK + 1 00325 60 CONTINUE 00326 WORK( K ) = WORK( K ) + S 00327 KK = KK + ( N-K+1 ) 00328 70 CONTINUE 00329 END IF 00330 S = ZERO 00331 DO 80 I = 1, N 00332 IF( WORK( I ).GT.SAFE2 ) THEN 00333 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) ) 00334 ELSE 00335 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) / 00336 $ ( WORK( I )+SAFE1 ) ) 00337 END IF 00338 80 CONTINUE 00339 BERR( J ) = S 00340 * 00341 * Test stopping criterion. Continue iterating if 00342 * 1) The residual BERR(J) is larger than machine epsilon, and 00343 * 2) BERR(J) decreased by at least a factor of 2 during the 00344 * last iteration, and 00345 * 3) At most ITMAX iterations tried. 00346 * 00347 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND. 00348 $ COUNT.LE.ITMAX ) THEN 00349 * 00350 * Update solution and try again. 00351 * 00352 CALL DSPTRS( UPLO, N, 1, AFP, IPIV, WORK( N+1 ), N, INFO ) 00353 CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 ) 00354 LSTRES = BERR( J ) 00355 COUNT = COUNT + 1 00356 GO TO 20 00357 END IF 00358 * 00359 * Bound error from formula 00360 * 00361 * norm(X - XTRUE) / norm(X) .le. FERR = 00362 * norm( abs(inv(A))* 00363 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) 00364 * 00365 * where 00366 * norm(Z) is the magnitude of the largest component of Z 00367 * inv(A) is the inverse of A 00368 * abs(Z) is the componentwise absolute value of the matrix or 00369 * vector Z 00370 * NZ is the maximum number of nonzeros in any row of A, plus 1 00371 * EPS is machine epsilon 00372 * 00373 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) 00374 * is incremented by SAFE1 if the i-th component of 00375 * abs(A)*abs(X) + abs(B) is less than SAFE2. 00376 * 00377 * Use DLACN2 to estimate the infinity-norm of the matrix 00378 * inv(A) * diag(W), 00379 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) 00380 * 00381 DO 90 I = 1, N 00382 IF( WORK( I ).GT.SAFE2 ) THEN 00383 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) 00384 ELSE 00385 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1 00386 END IF 00387 90 CONTINUE 00388 * 00389 KASE = 0 00390 100 CONTINUE 00391 CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ), 00392 $ KASE, ISAVE ) 00393 IF( KASE.NE.0 ) THEN 00394 IF( KASE.EQ.1 ) THEN 00395 * 00396 * Multiply by diag(W)*inv(A**T). 00397 * 00398 CALL DSPTRS( UPLO, N, 1, AFP, IPIV, WORK( N+1 ), N, 00399 $ INFO ) 00400 DO 110 I = 1, N 00401 WORK( N+I ) = WORK( I )*WORK( N+I ) 00402 110 CONTINUE 00403 ELSE IF( KASE.EQ.2 ) THEN 00404 * 00405 * Multiply by inv(A)*diag(W). 00406 * 00407 DO 120 I = 1, N 00408 WORK( N+I ) = WORK( I )*WORK( N+I ) 00409 120 CONTINUE 00410 CALL DSPTRS( UPLO, N, 1, AFP, IPIV, WORK( N+1 ), N, 00411 $ INFO ) 00412 END IF 00413 GO TO 100 00414 END IF 00415 * 00416 * Normalize error. 00417 * 00418 LSTRES = ZERO 00419 DO 130 I = 1, N 00420 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) ) 00421 130 CONTINUE 00422 IF( LSTRES.NE.ZERO ) 00423 $ FERR( J ) = FERR( J ) / LSTRES 00424 * 00425 140 CONTINUE 00426 * 00427 RETURN 00428 * 00429 * End of DSPRFS 00430 * 00431 END