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