LAPACK 3.3.1
Linear Algebra PACKage
|
00001 SUBROUTINE CGBSVX( FACT, TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, 00002 $ LDAFB, IPIV, EQUED, R, C, B, LDB, X, LDX, 00003 $ RCOND, FERR, BERR, WORK, RWORK, INFO ) 00004 * 00005 * -- LAPACK driver routine (version 3.2) -- 00006 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00007 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00008 * November 2006 00009 * 00010 * .. Scalar Arguments .. 00011 CHARACTER EQUED, FACT, TRANS 00012 INTEGER INFO, KL, KU, LDAB, LDAFB, LDB, LDX, N, NRHS 00013 REAL RCOND 00014 * .. 00015 * .. Array Arguments .. 00016 INTEGER IPIV( * ) 00017 REAL BERR( * ), C( * ), FERR( * ), R( * ), 00018 $ RWORK( * ) 00019 COMPLEX AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ), 00020 $ WORK( * ), X( LDX, * ) 00021 * .. 00022 * 00023 * Purpose 00024 * ======= 00025 * 00026 * CGBSVX uses the LU factorization to compute the solution to a complex 00027 * system of linear equations A * X = B, A**T * X = B, or A**H * X = B, 00028 * where A is a band matrix of order N with KL subdiagonals and KU 00029 * superdiagonals, and X and B are N-by-NRHS matrices. 00030 * 00031 * Error bounds on the solution and a condition estimate are also 00032 * provided. 00033 * 00034 * Description 00035 * =========== 00036 * 00037 * The following steps are performed by this subroutine: 00038 * 00039 * 1. If FACT = 'E', real scaling factors are computed to equilibrate 00040 * the system: 00041 * TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B 00042 * TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B 00043 * TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B 00044 * Whether or not the system will be equilibrated depends on the 00045 * scaling of the matrix A, but if equilibration is used, A is 00046 * overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N') 00047 * or diag(C)*B (if TRANS = 'T' or 'C'). 00048 * 00049 * 2. If FACT = 'N' or 'E', the LU decomposition is used to factor the 00050 * matrix A (after equilibration if FACT = 'E') as 00051 * A = L * U, 00052 * where L is a product of permutation and unit lower triangular 00053 * matrices with KL subdiagonals, and U is upper triangular with 00054 * KL+KU superdiagonals. 00055 * 00056 * 3. If some U(i,i)=0, so that U is exactly singular, then the routine 00057 * returns with INFO = i. Otherwise, the factored form of A is used 00058 * to estimate the condition number of the matrix A. If the 00059 * reciprocal of the condition number is less than machine precision, 00060 * INFO = N+1 is returned as a warning, but the routine still goes on 00061 * to solve for X and compute error bounds as described below. 00062 * 00063 * 4. The system of equations is solved for X using the factored form 00064 * of A. 00065 * 00066 * 5. Iterative refinement is applied to improve the computed solution 00067 * matrix and calculate error bounds and backward error estimates 00068 * for it. 00069 * 00070 * 6. If equilibration was used, the matrix X is premultiplied by 00071 * diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so 00072 * that it solves the original system before equilibration. 00073 * 00074 * Arguments 00075 * ========= 00076 * 00077 * FACT (input) CHARACTER*1 00078 * Specifies whether or not the factored form of the matrix A is 00079 * supplied on entry, and if not, whether the matrix A should be 00080 * equilibrated before it is factored. 00081 * = 'F': On entry, AFB and IPIV contain the factored form of 00082 * A. If EQUED is not 'N', the matrix A has been 00083 * equilibrated with scaling factors given by R and C. 00084 * AB, AFB, and IPIV are not modified. 00085 * = 'N': The matrix A will be copied to AFB and factored. 00086 * = 'E': The matrix A will be equilibrated if necessary, then 00087 * copied to AFB and factored. 00088 * 00089 * TRANS (input) CHARACTER*1 00090 * Specifies the form of the system of equations. 00091 * = 'N': A * X = B (No transpose) 00092 * = 'T': A**T * X = B (Transpose) 00093 * = 'C': A**H * X = B (Conjugate transpose) 00094 * 00095 * N (input) INTEGER 00096 * The number of linear equations, i.e., the order of the 00097 * matrix A. N >= 0. 00098 * 00099 * KL (input) INTEGER 00100 * The number of subdiagonals within the band of A. KL >= 0. 00101 * 00102 * KU (input) INTEGER 00103 * The number of superdiagonals within the band of A. KU >= 0. 00104 * 00105 * NRHS (input) INTEGER 00106 * The number of right hand sides, i.e., the number of columns 00107 * of the matrices B and X. NRHS >= 0. 00108 * 00109 * AB (input/output) COMPLEX array, dimension (LDAB,N) 00110 * On entry, the matrix A in band storage, in rows 1 to KL+KU+1. 00111 * The j-th column of A is stored in the j-th column of the 00112 * array AB as follows: 00113 * AB(KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+kl) 00114 * 00115 * If FACT = 'F' and EQUED is not 'N', then A must have been 00116 * equilibrated by the scaling factors in R and/or C. AB is not 00117 * modified if FACT = 'F' or 'N', or if FACT = 'E' and 00118 * EQUED = 'N' on exit. 00119 * 00120 * On exit, if EQUED .ne. 'N', A is scaled as follows: 00121 * EQUED = 'R': A := diag(R) * A 00122 * EQUED = 'C': A := A * diag(C) 00123 * EQUED = 'B': A := diag(R) * A * diag(C). 00124 * 00125 * LDAB (input) INTEGER 00126 * The leading dimension of the array AB. LDAB >= KL+KU+1. 00127 * 00128 * AFB (input or output) COMPLEX array, dimension (LDAFB,N) 00129 * If FACT = 'F', then AFB is an input argument and on entry 00130 * contains details of the LU factorization of the band matrix 00131 * A, as computed by CGBTRF. U is stored as an upper triangular 00132 * band matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, 00133 * and the multipliers used during the factorization are stored 00134 * in rows KL+KU+2 to 2*KL+KU+1. If EQUED .ne. 'N', then AFB is 00135 * the factored form of the equilibrated matrix A. 00136 * 00137 * If FACT = 'N', then AFB is an output argument and on exit 00138 * returns details of the LU factorization of A. 00139 * 00140 * If FACT = 'E', then AFB is an output argument and on exit 00141 * returns details of the LU factorization of the equilibrated 00142 * matrix A (see the description of AB for the form of the 00143 * equilibrated matrix). 00144 * 00145 * LDAFB (input) INTEGER 00146 * The leading dimension of the array AFB. LDAFB >= 2*KL+KU+1. 00147 * 00148 * IPIV (input or output) INTEGER array, dimension (N) 00149 * If FACT = 'F', then IPIV is an input argument and on entry 00150 * contains the pivot indices from the factorization A = L*U 00151 * as computed by CGBTRF; row i of the matrix was interchanged 00152 * with row IPIV(i). 00153 * 00154 * If FACT = 'N', then IPIV is an output argument and on exit 00155 * contains the pivot indices from the factorization A = L*U 00156 * of the original matrix A. 00157 * 00158 * If FACT = 'E', then IPIV is an output argument and on exit 00159 * contains the pivot indices from the factorization A = L*U 00160 * of the equilibrated matrix A. 00161 * 00162 * EQUED (input or output) CHARACTER*1 00163 * Specifies the form of equilibration that was done. 00164 * = 'N': No equilibration (always true if FACT = 'N'). 00165 * = 'R': Row equilibration, i.e., A has been premultiplied by 00166 * diag(R). 00167 * = 'C': Column equilibration, i.e., A has been postmultiplied 00168 * by diag(C). 00169 * = 'B': Both row and column equilibration, i.e., A has been 00170 * replaced by diag(R) * A * diag(C). 00171 * EQUED is an input argument if FACT = 'F'; otherwise, it is an 00172 * output argument. 00173 * 00174 * R (input or output) REAL array, dimension (N) 00175 * The row scale factors for A. If EQUED = 'R' or 'B', A is 00176 * multiplied on the left by diag(R); if EQUED = 'N' or 'C', R 00177 * is not accessed. R is an input argument if FACT = 'F'; 00178 * otherwise, R is an output argument. If FACT = 'F' and 00179 * EQUED = 'R' or 'B', each element of R must be positive. 00180 * 00181 * C (input or output) REAL array, dimension (N) 00182 * The column scale factors for A. If EQUED = 'C' or 'B', A is 00183 * multiplied on the right by diag(C); if EQUED = 'N' or 'R', C 00184 * is not accessed. C is an input argument if FACT = 'F'; 00185 * otherwise, C is an output argument. If FACT = 'F' and 00186 * EQUED = 'C' or 'B', each element of C must be positive. 00187 * 00188 * B (input/output) COMPLEX array, dimension (LDB,NRHS) 00189 * On entry, the right hand side matrix B. 00190 * On exit, 00191 * if EQUED = 'N', B is not modified; 00192 * if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by 00193 * diag(R)*B; 00194 * if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is 00195 * overwritten by diag(C)*B. 00196 * 00197 * LDB (input) INTEGER 00198 * The leading dimension of the array B. LDB >= max(1,N). 00199 * 00200 * X (output) COMPLEX array, dimension (LDX,NRHS) 00201 * If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X 00202 * to the original system of equations. Note that A and B are 00203 * modified on exit if EQUED .ne. 'N', and the solution to the 00204 * equilibrated system is inv(diag(C))*X if TRANS = 'N' and 00205 * EQUED = 'C' or 'B', or inv(diag(R))*X if TRANS = 'T' or 'C' 00206 * and EQUED = 'R' or 'B'. 00207 * 00208 * LDX (input) INTEGER 00209 * The leading dimension of the array X. LDX >= max(1,N). 00210 * 00211 * RCOND (output) REAL 00212 * The estimate of the reciprocal condition number of the matrix 00213 * A after equilibration (if done). If RCOND is less than the 00214 * machine precision (in particular, if RCOND = 0), the matrix 00215 * is singular to working precision. This condition is 00216 * indicated by a return code of INFO > 0. 00217 * 00218 * FERR (output) REAL array, dimension (NRHS) 00219 * The estimated forward error bound for each solution vector 00220 * X(j) (the j-th column of the solution matrix X). 00221 * If XTRUE is the true solution corresponding to X(j), FERR(j) 00222 * is an estimated upper bound for the magnitude of the largest 00223 * element in (X(j) - XTRUE) divided by the magnitude of the 00224 * largest element in X(j). The estimate is as reliable as 00225 * the estimate for RCOND, and is almost always a slight 00226 * overestimate of the true error. 00227 * 00228 * BERR (output) REAL array, dimension (NRHS) 00229 * The componentwise relative backward error of each solution 00230 * vector X(j) (i.e., the smallest relative change in 00231 * any element of A or B that makes X(j) an exact solution). 00232 * 00233 * WORK (workspace) COMPLEX array, dimension (2*N) 00234 * 00235 * RWORK (workspace/output) REAL array, dimension (N) 00236 * On exit, RWORK(1) contains the reciprocal pivot growth 00237 * factor norm(A)/norm(U). The "max absolute element" norm is 00238 * used. If RWORK(1) is much less than 1, then the stability 00239 * of the LU factorization of the (equilibrated) matrix A 00240 * could be poor. This also means that the solution X, condition 00241 * estimator RCOND, and forward error bound FERR could be 00242 * unreliable. If factorization fails with 0<INFO<=N, then 00243 * RWORK(1) contains the reciprocal pivot growth factor for the 00244 * leading INFO columns of A. 00245 * 00246 * INFO (output) INTEGER 00247 * = 0: successful exit 00248 * < 0: if INFO = -i, the i-th argument had an illegal value 00249 * > 0: if INFO = i, and i is 00250 * <= N: U(i,i) is exactly zero. The factorization 00251 * has been completed, but the factor U is exactly 00252 * singular, so the solution and error bounds 00253 * could not be computed. RCOND = 0 is returned. 00254 * = N+1: U is nonsingular, but RCOND is less than machine 00255 * precision, meaning that the matrix is singular 00256 * to working precision. Nevertheless, the 00257 * solution and error bounds are computed because 00258 * there are a number of situations where the 00259 * computed solution can be more accurate than the 00260 * value of RCOND would suggest. 00261 * 00262 * ===================================================================== 00263 * Moved setting of INFO = N+1 so INFO does not subsequently get 00264 * overwritten. Sven, 17 Mar 05. 00265 * ===================================================================== 00266 * 00267 * .. Parameters .. 00268 REAL ZERO, ONE 00269 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) 00270 * .. 00271 * .. Local Scalars .. 00272 LOGICAL COLEQU, EQUIL, NOFACT, NOTRAN, ROWEQU 00273 CHARACTER NORM 00274 INTEGER I, INFEQU, J, J1, J2 00275 REAL AMAX, ANORM, BIGNUM, COLCND, RCMAX, RCMIN, 00276 $ ROWCND, RPVGRW, SMLNUM 00277 * .. 00278 * .. External Functions .. 00279 LOGICAL LSAME 00280 REAL CLANGB, CLANTB, SLAMCH 00281 EXTERNAL LSAME, CLANGB, CLANTB, SLAMCH 00282 * .. 00283 * .. External Subroutines .. 00284 EXTERNAL CCOPY, CGBCON, CGBEQU, CGBRFS, CGBTRF, CGBTRS, 00285 $ CLACPY, CLAQGB, XERBLA 00286 * .. 00287 * .. Intrinsic Functions .. 00288 INTRINSIC ABS, MAX, MIN 00289 * .. 00290 * .. Executable Statements .. 00291 * 00292 INFO = 0 00293 NOFACT = LSAME( FACT, 'N' ) 00294 EQUIL = LSAME( FACT, 'E' ) 00295 NOTRAN = LSAME( TRANS, 'N' ) 00296 IF( NOFACT .OR. EQUIL ) THEN 00297 EQUED = 'N' 00298 ROWEQU = .FALSE. 00299 COLEQU = .FALSE. 00300 ELSE 00301 ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' ) 00302 COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' ) 00303 SMLNUM = SLAMCH( 'Safe minimum' ) 00304 BIGNUM = ONE / SMLNUM 00305 END IF 00306 * 00307 * Test the input parameters. 00308 * 00309 IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) ) 00310 $ THEN 00311 INFO = -1 00312 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT. 00313 $ LSAME( TRANS, 'C' ) ) THEN 00314 INFO = -2 00315 ELSE IF( N.LT.0 ) THEN 00316 INFO = -3 00317 ELSE IF( KL.LT.0 ) THEN 00318 INFO = -4 00319 ELSE IF( KU.LT.0 ) THEN 00320 INFO = -5 00321 ELSE IF( NRHS.LT.0 ) THEN 00322 INFO = -6 00323 ELSE IF( LDAB.LT.KL+KU+1 ) THEN 00324 INFO = -8 00325 ELSE IF( LDAFB.LT.2*KL+KU+1 ) THEN 00326 INFO = -10 00327 ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT. 00328 $ ( ROWEQU .OR. COLEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN 00329 INFO = -12 00330 ELSE 00331 IF( ROWEQU ) THEN 00332 RCMIN = BIGNUM 00333 RCMAX = ZERO 00334 DO 10 J = 1, N 00335 RCMIN = MIN( RCMIN, R( J ) ) 00336 RCMAX = MAX( RCMAX, R( J ) ) 00337 10 CONTINUE 00338 IF( RCMIN.LE.ZERO ) THEN 00339 INFO = -13 00340 ELSE IF( N.GT.0 ) THEN 00341 ROWCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM ) 00342 ELSE 00343 ROWCND = ONE 00344 END IF 00345 END IF 00346 IF( COLEQU .AND. INFO.EQ.0 ) THEN 00347 RCMIN = BIGNUM 00348 RCMAX = ZERO 00349 DO 20 J = 1, N 00350 RCMIN = MIN( RCMIN, C( J ) ) 00351 RCMAX = MAX( RCMAX, C( J ) ) 00352 20 CONTINUE 00353 IF( RCMIN.LE.ZERO ) THEN 00354 INFO = -14 00355 ELSE IF( N.GT.0 ) THEN 00356 COLCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM ) 00357 ELSE 00358 COLCND = ONE 00359 END IF 00360 END IF 00361 IF( INFO.EQ.0 ) THEN 00362 IF( LDB.LT.MAX( 1, N ) ) THEN 00363 INFO = -16 00364 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN 00365 INFO = -18 00366 END IF 00367 END IF 00368 END IF 00369 * 00370 IF( INFO.NE.0 ) THEN 00371 CALL XERBLA( 'CGBSVX', -INFO ) 00372 RETURN 00373 END IF 00374 * 00375 IF( EQUIL ) THEN 00376 * 00377 * Compute row and column scalings to equilibrate the matrix A. 00378 * 00379 CALL CGBEQU( N, N, KL, KU, AB, LDAB, R, C, ROWCND, COLCND, 00380 $ AMAX, INFEQU ) 00381 IF( INFEQU.EQ.0 ) THEN 00382 * 00383 * Equilibrate the matrix. 00384 * 00385 CALL CLAQGB( N, N, KL, KU, AB, LDAB, R, C, ROWCND, COLCND, 00386 $ AMAX, EQUED ) 00387 ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' ) 00388 COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' ) 00389 END IF 00390 END IF 00391 * 00392 * Scale the right hand side. 00393 * 00394 IF( NOTRAN ) THEN 00395 IF( ROWEQU ) THEN 00396 DO 40 J = 1, NRHS 00397 DO 30 I = 1, N 00398 B( I, J ) = R( I )*B( I, J ) 00399 30 CONTINUE 00400 40 CONTINUE 00401 END IF 00402 ELSE IF( COLEQU ) THEN 00403 DO 60 J = 1, NRHS 00404 DO 50 I = 1, N 00405 B( I, J ) = C( I )*B( I, J ) 00406 50 CONTINUE 00407 60 CONTINUE 00408 END IF 00409 * 00410 IF( NOFACT .OR. EQUIL ) THEN 00411 * 00412 * Compute the LU factorization of the band matrix A. 00413 * 00414 DO 70 J = 1, N 00415 J1 = MAX( J-KU, 1 ) 00416 J2 = MIN( J+KL, N ) 00417 CALL CCOPY( J2-J1+1, AB( KU+1-J+J1, J ), 1, 00418 $ AFB( KL+KU+1-J+J1, J ), 1 ) 00419 70 CONTINUE 00420 * 00421 CALL CGBTRF( N, N, KL, KU, AFB, LDAFB, IPIV, INFO ) 00422 * 00423 * Return if INFO is non-zero. 00424 * 00425 IF( INFO.GT.0 ) THEN 00426 * 00427 * Compute the reciprocal pivot growth factor of the 00428 * leading rank-deficient INFO columns of A. 00429 * 00430 ANORM = ZERO 00431 DO 90 J = 1, INFO 00432 DO 80 I = MAX( KU+2-J, 1 ), MIN( N+KU+1-J, KL+KU+1 ) 00433 ANORM = MAX( ANORM, ABS( AB( I, J ) ) ) 00434 80 CONTINUE 00435 90 CONTINUE 00436 RPVGRW = CLANTB( 'M', 'U', 'N', INFO, MIN( INFO-1, KL+KU ), 00437 $ AFB( MAX( 1, KL+KU+2-INFO ), 1 ), LDAFB, 00438 $ RWORK ) 00439 IF( RPVGRW.EQ.ZERO ) THEN 00440 RPVGRW = ONE 00441 ELSE 00442 RPVGRW = ANORM / RPVGRW 00443 END IF 00444 RWORK( 1 ) = RPVGRW 00445 RCOND = ZERO 00446 RETURN 00447 END IF 00448 END IF 00449 * 00450 * Compute the norm of the matrix A and the 00451 * reciprocal pivot growth factor RPVGRW. 00452 * 00453 IF( NOTRAN ) THEN 00454 NORM = '1' 00455 ELSE 00456 NORM = 'I' 00457 END IF 00458 ANORM = CLANGB( NORM, N, KL, KU, AB, LDAB, RWORK ) 00459 RPVGRW = CLANTB( 'M', 'U', 'N', N, KL+KU, AFB, LDAFB, RWORK ) 00460 IF( RPVGRW.EQ.ZERO ) THEN 00461 RPVGRW = ONE 00462 ELSE 00463 RPVGRW = CLANGB( 'M', N, KL, KU, AB, LDAB, RWORK ) / RPVGRW 00464 END IF 00465 * 00466 * Compute the reciprocal of the condition number of A. 00467 * 00468 CALL CGBCON( NORM, N, KL, KU, AFB, LDAFB, IPIV, ANORM, RCOND, 00469 $ WORK, RWORK, INFO ) 00470 * 00471 * Compute the solution matrix X. 00472 * 00473 CALL CLACPY( 'Full', N, NRHS, B, LDB, X, LDX ) 00474 CALL CGBTRS( TRANS, N, KL, KU, NRHS, AFB, LDAFB, IPIV, X, LDX, 00475 $ INFO ) 00476 * 00477 * Use iterative refinement to improve the computed solution and 00478 * compute error bounds and backward error estimates for it. 00479 * 00480 CALL CGBRFS( TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, LDAFB, IPIV, 00481 $ B, LDB, X, LDX, FERR, BERR, WORK, RWORK, INFO ) 00482 * 00483 * Transform the solution matrix X to a solution of the original 00484 * system. 00485 * 00486 IF( NOTRAN ) THEN 00487 IF( COLEQU ) THEN 00488 DO 110 J = 1, NRHS 00489 DO 100 I = 1, N 00490 X( I, J ) = C( I )*X( I, J ) 00491 100 CONTINUE 00492 110 CONTINUE 00493 DO 120 J = 1, NRHS 00494 FERR( J ) = FERR( J ) / COLCND 00495 120 CONTINUE 00496 END IF 00497 ELSE IF( ROWEQU ) THEN 00498 DO 140 J = 1, NRHS 00499 DO 130 I = 1, N 00500 X( I, J ) = R( I )*X( I, J ) 00501 130 CONTINUE 00502 140 CONTINUE 00503 DO 150 J = 1, NRHS 00504 FERR( J ) = FERR( J ) / ROWCND 00505 150 CONTINUE 00506 END IF 00507 * 00508 * Set INFO = N+1 if the matrix is singular to working precision. 00509 * 00510 IF( RCOND.LT.SLAMCH( 'Epsilon' ) ) 00511 $ INFO = N + 1 00512 * 00513 RWORK( 1 ) = RPVGRW 00514 RETURN 00515 * 00516 * End of CGBSVX 00517 * 00518 END