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