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