![]() |
LAPACK
3.4.1
LAPACK: Linear Algebra PACKage
|
00001 *> \brief \b ZPTRFS 00002 * 00003 * =========== DOCUMENTATION =========== 00004 * 00005 * Online html documentation available at 00006 * http://www.netlib.org/lapack/explore-html/ 00007 * 00008 *> \htmlonly 00009 *> Download ZPTRFS + dependencies 00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zptrfs.f"> 00011 *> [TGZ]</a> 00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zptrfs.f"> 00013 *> [ZIP]</a> 00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zptrfs.f"> 00015 *> [TXT]</a> 00016 *> \endhtmlonly 00017 * 00018 * Definition: 00019 * =========== 00020 * 00021 * SUBROUTINE ZPTRFS( UPLO, N, NRHS, D, E, DF, EF, B, LDB, X, LDX, 00022 * FERR, BERR, WORK, RWORK, INFO ) 00023 * 00024 * .. Scalar Arguments .. 00025 * CHARACTER UPLO 00026 * INTEGER INFO, LDB, LDX, N, NRHS 00027 * .. 00028 * .. Array Arguments .. 00029 * DOUBLE PRECISION BERR( * ), D( * ), DF( * ), FERR( * ), 00030 * $ RWORK( * ) 00031 * COMPLEX*16 B( LDB, * ), E( * ), EF( * ), WORK( * ), 00032 * $ X( LDX, * ) 00033 * .. 00034 * 00035 * 00036 *> \par Purpose: 00037 * ============= 00038 *> 00039 *> \verbatim 00040 *> 00041 *> ZPTRFS improves the computed solution to a system of linear 00042 *> equations when the coefficient matrix is Hermitian positive definite 00043 *> and tridiagonal, and provides error bounds and backward error 00044 *> estimates for the solution. 00045 *> \endverbatim 00046 * 00047 * Arguments: 00048 * ========== 00049 * 00050 *> \param[in] UPLO 00051 *> \verbatim 00052 *> UPLO is CHARACTER*1 00053 *> Specifies whether the superdiagonal or the subdiagonal of the 00054 *> tridiagonal matrix A is stored and the form of the 00055 *> factorization: 00056 *> = 'U': E is the superdiagonal of A, and A = U**H*D*U; 00057 *> = 'L': E is the subdiagonal of A, and A = L*D*L**H. 00058 *> (The two forms are equivalent if A is real.) 00059 *> \endverbatim 00060 *> 00061 *> \param[in] N 00062 *> \verbatim 00063 *> N is INTEGER 00064 *> The order of the matrix A. N >= 0. 00065 *> \endverbatim 00066 *> 00067 *> \param[in] NRHS 00068 *> \verbatim 00069 *> NRHS is INTEGER 00070 *> The number of right hand sides, i.e., the number of columns 00071 *> of the matrix B. NRHS >= 0. 00072 *> \endverbatim 00073 *> 00074 *> \param[in] D 00075 *> \verbatim 00076 *> D is DOUBLE PRECISION array, dimension (N) 00077 *> The n real diagonal elements of the tridiagonal matrix A. 00078 *> \endverbatim 00079 *> 00080 *> \param[in] E 00081 *> \verbatim 00082 *> E is COMPLEX*16 array, dimension (N-1) 00083 *> The (n-1) off-diagonal elements of the tridiagonal matrix A 00084 *> (see UPLO). 00085 *> \endverbatim 00086 *> 00087 *> \param[in] DF 00088 *> \verbatim 00089 *> DF is DOUBLE PRECISION array, dimension (N) 00090 *> The n diagonal elements of the diagonal matrix D from 00091 *> the factorization computed by ZPTTRF. 00092 *> \endverbatim 00093 *> 00094 *> \param[in] EF 00095 *> \verbatim 00096 *> EF is COMPLEX*16 array, dimension (N-1) 00097 *> The (n-1) off-diagonal elements of the unit bidiagonal 00098 *> factor U or L from the factorization computed by ZPTTRF 00099 *> (see UPLO). 00100 *> \endverbatim 00101 *> 00102 *> \param[in] B 00103 *> \verbatim 00104 *> B is COMPLEX*16 array, dimension (LDB,NRHS) 00105 *> The right hand side matrix B. 00106 *> \endverbatim 00107 *> 00108 *> \param[in] LDB 00109 *> \verbatim 00110 *> LDB is INTEGER 00111 *> The leading dimension of the array B. LDB >= max(1,N). 00112 *> \endverbatim 00113 *> 00114 *> \param[in,out] X 00115 *> \verbatim 00116 *> X is COMPLEX*16 array, dimension (LDX,NRHS) 00117 *> On entry, the solution matrix X, as computed by ZPTTRS. 00118 *> On exit, the improved solution matrix X. 00119 *> \endverbatim 00120 *> 00121 *> \param[in] LDX 00122 *> \verbatim 00123 *> LDX is INTEGER 00124 *> The leading dimension of the array X. LDX >= max(1,N). 00125 *> \endverbatim 00126 *> 00127 *> \param[out] FERR 00128 *> \verbatim 00129 *> FERR is DOUBLE PRECISION array, dimension (NRHS) 00130 *> The forward error bound for each solution vector 00131 *> X(j) (the j-th column of the solution matrix X). 00132 *> If XTRUE is the true solution corresponding to X(j), FERR(j) 00133 *> is an estimated upper bound for the magnitude of the largest 00134 *> element in (X(j) - XTRUE) divided by the magnitude of the 00135 *> largest element in X(j). 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 COMPLEX*16 array, dimension (N) 00149 *> \endverbatim 00150 *> 00151 *> \param[out] RWORK 00152 *> \verbatim 00153 *> RWORK is DOUBLE PRECISION 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 complex16OTHERcomputational 00181 * 00182 * ===================================================================== 00183 SUBROUTINE ZPTRFS( UPLO, N, NRHS, D, E, DF, EF, B, LDB, X, LDX, 00184 $ FERR, BERR, WORK, RWORK, 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, LDB, LDX, N, NRHS 00194 * .. 00195 * .. Array Arguments .. 00196 DOUBLE PRECISION BERR( * ), D( * ), DF( * ), FERR( * ), 00197 $ RWORK( * ) 00198 COMPLEX*16 B( LDB, * ), E( * ), EF( * ), WORK( * ), 00199 $ X( LDX, * ) 00200 * .. 00201 * 00202 * ===================================================================== 00203 * 00204 * .. Parameters .. 00205 INTEGER ITMAX 00206 PARAMETER ( ITMAX = 5 ) 00207 DOUBLE PRECISION ZERO 00208 PARAMETER ( ZERO = 0.0D+0 ) 00209 DOUBLE PRECISION ONE 00210 PARAMETER ( ONE = 1.0D+0 ) 00211 DOUBLE PRECISION TWO 00212 PARAMETER ( TWO = 2.0D+0 ) 00213 DOUBLE PRECISION THREE 00214 PARAMETER ( THREE = 3.0D+0 ) 00215 * .. 00216 * .. Local Scalars .. 00217 LOGICAL UPPER 00218 INTEGER COUNT, I, IX, J, NZ 00219 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN 00220 COMPLEX*16 BI, CX, DX, EX, ZDUM 00221 * .. 00222 * .. External Functions .. 00223 LOGICAL LSAME 00224 INTEGER IDAMAX 00225 DOUBLE PRECISION DLAMCH 00226 EXTERNAL LSAME, IDAMAX, DLAMCH 00227 * .. 00228 * .. External Subroutines .. 00229 EXTERNAL XERBLA, ZAXPY, ZPTTRS 00230 * .. 00231 * .. Intrinsic Functions .. 00232 INTRINSIC ABS, DBLE, DCMPLX, DCONJG, DIMAG, MAX 00233 * .. 00234 * .. Statement Functions .. 00235 DOUBLE PRECISION CABS1 00236 * .. 00237 * .. Statement Function definitions .. 00238 CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) ) 00239 * .. 00240 * .. Executable Statements .. 00241 * 00242 * Test the input parameters. 00243 * 00244 INFO = 0 00245 UPPER = LSAME( UPLO, 'U' ) 00246 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN 00247 INFO = -1 00248 ELSE IF( N.LT.0 ) THEN 00249 INFO = -2 00250 ELSE IF( NRHS.LT.0 ) THEN 00251 INFO = -3 00252 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN 00253 INFO = -9 00254 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN 00255 INFO = -11 00256 END IF 00257 IF( INFO.NE.0 ) THEN 00258 CALL XERBLA( 'ZPTRFS', -INFO ) 00259 RETURN 00260 END IF 00261 * 00262 * Quick return if possible 00263 * 00264 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN 00265 DO 10 J = 1, NRHS 00266 FERR( J ) = ZERO 00267 BERR( J ) = ZERO 00268 10 CONTINUE 00269 RETURN 00270 END IF 00271 * 00272 * NZ = maximum number of nonzero elements in each row of A, plus 1 00273 * 00274 NZ = 4 00275 EPS = DLAMCH( 'Epsilon' ) 00276 SAFMIN = DLAMCH( 'Safe minimum' ) 00277 SAFE1 = NZ*SAFMIN 00278 SAFE2 = SAFE1 / EPS 00279 * 00280 * Do for each right hand side 00281 * 00282 DO 100 J = 1, NRHS 00283 * 00284 COUNT = 1 00285 LSTRES = THREE 00286 20 CONTINUE 00287 * 00288 * Loop until stopping criterion is satisfied. 00289 * 00290 * Compute residual R = B - A * X. Also compute 00291 * abs(A)*abs(x) + abs(b) for use in the backward error bound. 00292 * 00293 IF( UPPER ) THEN 00294 IF( N.EQ.1 ) THEN 00295 BI = B( 1, J ) 00296 DX = D( 1 )*X( 1, J ) 00297 WORK( 1 ) = BI - DX 00298 RWORK( 1 ) = CABS1( BI ) + CABS1( DX ) 00299 ELSE 00300 BI = B( 1, J ) 00301 DX = D( 1 )*X( 1, J ) 00302 EX = E( 1 )*X( 2, J ) 00303 WORK( 1 ) = BI - DX - EX 00304 RWORK( 1 ) = CABS1( BI ) + CABS1( DX ) + 00305 $ CABS1( E( 1 ) )*CABS1( X( 2, J ) ) 00306 DO 30 I = 2, N - 1 00307 BI = B( I, J ) 00308 CX = DCONJG( E( I-1 ) )*X( I-1, J ) 00309 DX = D( I )*X( I, J ) 00310 EX = E( I )*X( I+1, J ) 00311 WORK( I ) = BI - CX - DX - EX 00312 RWORK( I ) = CABS1( BI ) + 00313 $ CABS1( E( I-1 ) )*CABS1( X( I-1, J ) ) + 00314 $ CABS1( DX ) + CABS1( E( I ) )* 00315 $ CABS1( X( I+1, J ) ) 00316 30 CONTINUE 00317 BI = B( N, J ) 00318 CX = DCONJG( E( N-1 ) )*X( N-1, J ) 00319 DX = D( N )*X( N, J ) 00320 WORK( N ) = BI - CX - DX 00321 RWORK( N ) = CABS1( BI ) + CABS1( E( N-1 ) )* 00322 $ CABS1( X( N-1, J ) ) + CABS1( DX ) 00323 END IF 00324 ELSE 00325 IF( N.EQ.1 ) THEN 00326 BI = B( 1, J ) 00327 DX = D( 1 )*X( 1, J ) 00328 WORK( 1 ) = BI - DX 00329 RWORK( 1 ) = CABS1( BI ) + CABS1( DX ) 00330 ELSE 00331 BI = B( 1, J ) 00332 DX = D( 1 )*X( 1, J ) 00333 EX = DCONJG( E( 1 ) )*X( 2, J ) 00334 WORK( 1 ) = BI - DX - EX 00335 RWORK( 1 ) = CABS1( BI ) + CABS1( DX ) + 00336 $ CABS1( E( 1 ) )*CABS1( X( 2, J ) ) 00337 DO 40 I = 2, N - 1 00338 BI = B( I, J ) 00339 CX = E( I-1 )*X( I-1, J ) 00340 DX = D( I )*X( I, J ) 00341 EX = DCONJG( E( I ) )*X( I+1, J ) 00342 WORK( I ) = BI - CX - DX - EX 00343 RWORK( I ) = CABS1( BI ) + 00344 $ CABS1( E( I-1 ) )*CABS1( X( I-1, J ) ) + 00345 $ CABS1( DX ) + CABS1( E( I ) )* 00346 $ CABS1( X( I+1, J ) ) 00347 40 CONTINUE 00348 BI = B( N, J ) 00349 CX = E( N-1 )*X( N-1, J ) 00350 DX = D( N )*X( N, J ) 00351 WORK( N ) = BI - CX - DX 00352 RWORK( N ) = CABS1( BI ) + CABS1( E( N-1 ) )* 00353 $ CABS1( X( N-1, J ) ) + CABS1( DX ) 00354 END IF 00355 END IF 00356 * 00357 * Compute componentwise relative backward error from formula 00358 * 00359 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) 00360 * 00361 * where abs(Z) is the componentwise absolute value of the matrix 00362 * or vector Z. If the i-th component of the denominator is less 00363 * than SAFE2, then SAFE1 is added to the i-th components of the 00364 * numerator and denominator before dividing. 00365 * 00366 S = ZERO 00367 DO 50 I = 1, N 00368 IF( RWORK( I ).GT.SAFE2 ) THEN 00369 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) ) 00370 ELSE 00371 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) / 00372 $ ( RWORK( I )+SAFE1 ) ) 00373 END IF 00374 50 CONTINUE 00375 BERR( J ) = S 00376 * 00377 * Test stopping criterion. Continue iterating if 00378 * 1) The residual BERR(J) is larger than machine epsilon, and 00379 * 2) BERR(J) decreased by at least a factor of 2 during the 00380 * last iteration, and 00381 * 3) At most ITMAX iterations tried. 00382 * 00383 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND. 00384 $ COUNT.LE.ITMAX ) THEN 00385 * 00386 * Update solution and try again. 00387 * 00388 CALL ZPTTRS( UPLO, N, 1, DF, EF, WORK, N, INFO ) 00389 CALL ZAXPY( N, DCMPLX( ONE ), WORK, 1, X( 1, J ), 1 ) 00390 LSTRES = BERR( J ) 00391 COUNT = COUNT + 1 00392 GO TO 20 00393 END IF 00394 * 00395 * Bound error from formula 00396 * 00397 * norm(X - XTRUE) / norm(X) .le. FERR = 00398 * norm( abs(inv(A))* 00399 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) 00400 * 00401 * where 00402 * norm(Z) is the magnitude of the largest component of Z 00403 * inv(A) is the inverse of A 00404 * abs(Z) is the componentwise absolute value of the matrix or 00405 * vector Z 00406 * NZ is the maximum number of nonzeros in any row of A, plus 1 00407 * EPS is machine epsilon 00408 * 00409 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) 00410 * is incremented by SAFE1 if the i-th component of 00411 * abs(A)*abs(X) + abs(B) is less than SAFE2. 00412 * 00413 DO 60 I = 1, N 00414 IF( RWORK( I ).GT.SAFE2 ) THEN 00415 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) 00416 ELSE 00417 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) + 00418 $ SAFE1 00419 END IF 00420 60 CONTINUE 00421 IX = IDAMAX( N, RWORK, 1 ) 00422 FERR( J ) = RWORK( IX ) 00423 * 00424 * Estimate the norm of inv(A). 00425 * 00426 * Solve M(A) * x = e, where M(A) = (m(i,j)) is given by 00427 * 00428 * m(i,j) = abs(A(i,j)), i = j, 00429 * m(i,j) = -abs(A(i,j)), i .ne. j, 00430 * 00431 * and e = [ 1, 1, ..., 1 ]**T. Note M(A) = M(L)*D*M(L)**H. 00432 * 00433 * Solve M(L) * x = e. 00434 * 00435 RWORK( 1 ) = ONE 00436 DO 70 I = 2, N 00437 RWORK( I ) = ONE + RWORK( I-1 )*ABS( EF( I-1 ) ) 00438 70 CONTINUE 00439 * 00440 * Solve D * M(L)**H * x = b. 00441 * 00442 RWORK( N ) = RWORK( N ) / DF( N ) 00443 DO 80 I = N - 1, 1, -1 00444 RWORK( I ) = RWORK( I ) / DF( I ) + 00445 $ RWORK( I+1 )*ABS( EF( I ) ) 00446 80 CONTINUE 00447 * 00448 * Compute norm(inv(A)) = max(x(i)), 1<=i<=n. 00449 * 00450 IX = IDAMAX( N, RWORK, 1 ) 00451 FERR( J ) = FERR( J )*ABS( RWORK( IX ) ) 00452 * 00453 * Normalize error. 00454 * 00455 LSTRES = ZERO 00456 DO 90 I = 1, N 00457 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) ) 00458 90 CONTINUE 00459 IF( LSTRES.NE.ZERO ) 00460 $ FERR( J ) = FERR( J ) / LSTRES 00461 * 00462 100 CONTINUE 00463 * 00464 RETURN 00465 * 00466 * End of ZPTRFS 00467 * 00468 END