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