001:SUBROUTINESPBSVX( FACT, UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, 002: $ EQUED, S, B, LDB, X, LDX, RCOND, FERR, BERR, 003: $ WORK, IWORK, INFO ) 004:*005:* -- LAPACK driver routine (version 3.2) --006:* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..007:* November 2006008:*009:* .. Scalar Arguments ..010: CHARACTER EQUED, FACT, UPLO 011: INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS 012: REAL RCOND 013:* ..014:* .. Array Arguments ..015: INTEGERIWORK( * ) 016: REALAB( LDAB, * ),AFB( LDAFB, * ),B( LDB, * ), 017: $BERR( * ),FERR( * ),S( * ),WORK( * ), 018: $X( LDX, * ) 019:* ..020:*021:* Purpose022:* =======023:*024:* SPBSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to025:* compute the solution to a real system of linear equations026:* A * X = B,027:* where A is an N-by-N symmetric positive definite band matrix and X028:* and B are N-by-NRHS matrices.029:*030:* Error bounds on the solution and a condition estimate are also031:* provided.032:*033:* Description034:* ===========035:*036:* The following steps are performed:037:*038:* 1. If FACT = 'E', real scaling factors are computed to equilibrate039:* the system:040:* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B041:* Whether or not the system will be equilibrated depends on the042:* scaling of the matrix A, but if equilibration is used, A is043:* overwritten by diag(S)*A*diag(S) and B by diag(S)*B.044:*045:* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to046:* factor the matrix A (after equilibration if FACT = 'E') as047:* A = U**T * U, if UPLO = 'U', or048:* A = L * L**T, if UPLO = 'L',049:* where U is an upper triangular band matrix, and L is a lower050:* triangular band matrix.051:*052:* 3. If the leading i-by-i principal minor is not positive definite,053:* then the routine returns with INFO = i. Otherwise, the factored054:* form of A is used to estimate the condition number of the matrix055:* A. If the reciprocal of the condition number is less than machine056:* precision, INFO = N+1 is returned as a warning, but the routine057:* still goes on to solve for X and compute error bounds as058:* described below.059:*060:* 4. The system of equations is solved for X using the factored form061:* of A.062:*063:* 5. Iterative refinement is applied to improve the computed solution064:* matrix and calculate error bounds and backward error estimates065:* for it.066:*067:* 6. If equilibration was used, the matrix X is premultiplied by068:* diag(S) so that it solves the original system before069:* equilibration.070:*071:* Arguments072:* =========073:*074:* FACT (input) CHARACTER*1075:* Specifies whether or not the factored form of the matrix A is076:* supplied on entry, and if not, whether the matrix A should be077:* equilibrated before it is factored.078:* = 'F': On entry, AFB contains the factored form of A.079:* If EQUED = 'Y', the matrix A has been equilibrated080:* with scaling factors given by S. AB and AFB will not081:* be modified.082:* = 'N': The matrix A will be copied to AFB and factored.083:* = 'E': The matrix A will be equilibrated if necessary, then084:* copied to AFB and factored.085:*086:* UPLO (input) CHARACTER*1087:* = 'U': Upper triangle of A is stored;088:* = 'L': Lower triangle of A is stored.089:*090:* N (input) INTEGER091:* The number of linear equations, i.e., the order of the092:* matrix A. N >= 0.093:*094:* KD (input) INTEGER095:* The number of superdiagonals of the matrix A if UPLO = 'U',096:* or the number of subdiagonals if UPLO = 'L'. KD >= 0.097:*098:* NRHS (input) INTEGER099:* The number of right-hand sides, i.e., the number of columns100:* of the matrices B and X. NRHS >= 0.101:*102:* AB (input/output) REAL array, dimension (LDAB,N)103:* On entry, the upper or lower triangle of the symmetric band104:* matrix A, stored in the first KD+1 rows of the array, except105:* if FACT = 'F' and EQUED = 'Y', then A must contain the106:* equilibrated matrix diag(S)*A*diag(S). The j-th column of A107:* is stored in the j-th column of the array AB as follows:108:* if UPLO = 'U', AB(KD+1+i-j,j) = A(i,j) for max(1,j-KD)<=i<=j;109:* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(N,j+KD).110:* See below for further details.111:*112:* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by113:* diag(S)*A*diag(S).114:*115:* LDAB (input) INTEGER116:* The leading dimension of the array A. LDAB >= KD+1.117:*118:* AFB (input or output) REAL array, dimension (LDAFB,N)119:* If FACT = 'F', then AFB is an input argument and on entry120:* contains the triangular factor U or L from the Cholesky121:* factorization A = U**T*U or A = L*L**T of the band matrix122:* A, in the same storage format as A (see AB). If EQUED = 'Y',123:* then AFB is the factored form of the equilibrated matrix A.124:*125:* If FACT = 'N', then AFB is an output argument and on exit126:* returns the triangular factor U or L from the Cholesky127:* factorization A = U**T*U or A = L*L**T.128:*129:* If FACT = 'E', then AFB is an output argument and on exit130:* returns the triangular factor U or L from the Cholesky131:* factorization A = U**T*U or A = L*L**T of the equilibrated132:* matrix A (see the description of A for the form of the133:* equilibrated matrix).134:*135:* LDAFB (input) INTEGER136:* The leading dimension of the array AFB. LDAFB >= KD+1.137:*138:* EQUED (input or output) CHARACTER*1139:* Specifies the form of equilibration that was done.140:* = 'N': No equilibration (always true if FACT = 'N').141:* = 'Y': Equilibration was done, i.e., A has been replaced by142:* diag(S) * A * diag(S).143:* EQUED is an input argument if FACT = 'F'; otherwise, it is an144:* output argument.145:*146:* S (input or output) REAL array, dimension (N)147:* The scale factors for A; not accessed if EQUED = 'N'. S is148:* an input argument if FACT = 'F'; otherwise, S is an output149:* argument. If FACT = 'F' and EQUED = 'Y', each element of S150:* must be positive.151:*152:* B (input/output) REAL array, dimension (LDB,NRHS)153:* On entry, the N-by-NRHS right hand side matrix B.154:* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y',155:* B is overwritten by diag(S) * B.156:*157:* LDB (input) INTEGER158:* The leading dimension of the array B. LDB >= max(1,N).159:*160:* X (output) REAL array, dimension (LDX,NRHS)161:* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to162:* the original system of equations. Note that if EQUED = 'Y',163:* A and B are modified on exit, and the solution to the164:* equilibrated system is inv(diag(S))*X.165:*166:* LDX (input) INTEGER167:* The leading dimension of the array X. LDX >= max(1,N).168:*169:* RCOND (output) REAL170:* The estimate of the reciprocal condition number of the matrix171:* A after equilibration (if done). If RCOND is less than the172:* machine precision (in particular, if RCOND = 0), the matrix173:* is singular to working precision. This condition is174:* indicated by a return code of INFO > 0.175:*176:* FERR (output) REAL array, dimension (NRHS)177:* The estimated forward error bound for each solution vector178:* X(j) (the j-th column of the solution matrix X).179:* If XTRUE is the true solution corresponding to X(j), FERR(j)180:* is an estimated upper bound for the magnitude of the largest181:* element in (X(j) - XTRUE) divided by the magnitude of the182:* largest element in X(j). The estimate is as reliable as183:* the estimate for RCOND, and is almost always a slight184:* overestimate of the true error.185:*186:* BERR (output) REAL array, dimension (NRHS)187:* The componentwise relative backward error of each solution188:* vector X(j) (i.e., the smallest relative change in189:* any element of A or B that makes X(j) an exact solution).190:*191:* WORK (workspace) REAL array, dimension (3*N)192:*193:* IWORK (workspace) INTEGER array, dimension (N)194:*195:* INFO (output) INTEGER196:* = 0: successful exit197:* < 0: if INFO = -i, the i-th argument had an illegal value198:* > 0: if INFO = i, and i is199:* <= N: the leading minor of order i of A is200:* not positive definite, so the factorization201:* could not be completed, and the solution has not202:* been computed. RCOND = 0 is returned.203:* = N+1: U is nonsingular, but RCOND is less than machine204:* precision, meaning that the matrix is singular205:* to working precision. Nevertheless, the206:* solution and error bounds are computed because207:* there are a number of situations where the208:* computed solution can be more accurate than the209:* value of RCOND would suggest.210:*211:* Further Details212:* ===============213:*214:* The band storage scheme is illustrated by the following example, when215:* N = 6, KD = 2, and UPLO = 'U':216:*217:* Two-dimensional storage of the symmetric matrix A:218:*219:* a11 a12 a13220:* a22 a23 a24221:* a33 a34 a35222:* a44 a45 a46223:* a55 a56224:* (aij=conjg(aji)) a66225:*226:* Band storage of the upper triangle of A:227:*228:* * * a13 a24 a35 a46229:* * a12 a23 a34 a45 a56230:* a11 a22 a33 a44 a55 a66231:*232:* Similarly, if UPLO = 'L' the format of A is as follows:233:*234:* a11 a22 a33 a44 a55 a66235:* a21 a32 a43 a54 a65 *236:* a31 a42 a53 a64 * *237:*238:* Array elements marked * are not used by the routine.239:*240:* =====================================================================241:*242:* .. Parameters ..243: REAL ZERO, ONE 244:PARAMETER( ZERO = 0.0E+0, ONE = 1.0E+0 ) 245:* ..246:* .. Local Scalars ..247:LOGICALEQUIL, NOFACT, RCEQU, UPPER 248: INTEGER I, INFEQU, J, J1, J2 249: REAL AMAX, ANORM, BIGNUM, SCOND, SMAX, SMIN, SMLNUM 250:* ..251:* .. External Functions ..252:LOGICALLSAME 253: REAL SLAMCH, SLANSB 254:EXTERNALLSAME, SLAMCH, SLANSB 255:* ..256:* .. External Subroutines ..257:EXTERNALSCOPY, SLACPY, SLAQSB, SPBCON, SPBEQU, SPBRFS, 258: $ SPBTRF, SPBTRS, XERBLA 259:* ..260:* .. Intrinsic Functions ..261:INTRINSICMAX, MIN 262:* ..263:* .. Executable Statements ..264:*265: INFO = 0 266: NOFACT =LSAME( FACT, 'N' ) 267: EQUIL =LSAME( FACT, 'E' ) 268: UPPER =LSAME( UPLO, 'U' ) 269:IF( NOFACT .OR. EQUIL )THEN270: EQUED = 'N' 271: RCEQU = .FALSE. 272:ELSE273: RCEQU =LSAME( EQUED, 'Y' ) 274: SMLNUM =SLAMCH( 'Safe minimum' ) 275: BIGNUM = ONE / SMLNUM 276:ENDIF277:*278:* Test the input parameters.279:*280:IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) ) 281: $THEN282: INFO = -1 283:ELSEIF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) )THEN284: INFO = -2 285:ELSEIF( N.LT.0 )THEN286: INFO = -3 287:ELSEIF( KD.LT.0 )THEN288: INFO = -4 289:ELSEIF( NRHS.LT.0 )THEN290: INFO = -5 291:ELSEIF( LDAB.LT.KD+1 )THEN292: INFO = -7 293:ELSEIF( LDAFB.LT.KD+1 )THEN294: INFO = -9 295:ELSEIF(LSAME( FACT, 'F' ) .AND. .NOT. 296: $ ( RCEQU .OR.LSAME( EQUED, 'N' ) ) )THEN297: INFO = -10 298:ELSE299:IF( RCEQU )THEN300: SMIN = BIGNUM 301: SMAX = ZERO 302:DO10 J = 1, N 303: SMIN =MIN( SMIN,S( J ) ) 304: SMAX =MAX( SMAX,S( J ) ) 305: 10CONTINUE306:IF( SMIN.LE.ZERO )THEN307: INFO = -11 308:ELSEIF( N.GT.0 )THEN309: SCOND =MAX( SMIN, SMLNUM ) /MIN( SMAX, BIGNUM ) 310:ELSE311: SCOND = ONE 312:ENDIF313:ENDIF314:IF( INFO.EQ.0 )THEN315:IF( LDB.LT.MAX( 1, N ) )THEN316: INFO = -13 317:ELSEIF( LDX.LT.MAX( 1, N ) )THEN318: INFO = -15 319:ENDIF320:ENDIF321:ENDIF322:*323:IF( INFO.NE.0 )THEN324:CALLXERBLA( 'SPBSVX', -INFO ) 325:RETURN326:ENDIF327:*328:IF( EQUIL )THEN329:*330:* Compute row and column scalings to equilibrate the matrix A.331:*332:CALLSPBEQU( UPLO, N, KD, AB, LDAB, S, SCOND, AMAX, INFEQU ) 333:IF( INFEQU.EQ.0 )THEN334:*335:* Equilibrate the matrix.336:*337:CALLSLAQSB( UPLO, N, KD, AB, LDAB, S, SCOND, AMAX, EQUED ) 338: RCEQU =LSAME( EQUED, 'Y' ) 339:ENDIF340:ENDIF341:*342:* Scale the right-hand side.343:*344:IF( RCEQU )THEN345:DO30 J = 1, NRHS 346:DO20 I = 1, N 347:B( I, J ) =S( I )*B( I, J ) 348: 20CONTINUE349: 30CONTINUE350:ENDIF351:*352:IF( NOFACT .OR. EQUIL )THEN353:*354:* Compute the Cholesky factorization A = U'*U or A = L*L'.355:*356:IF( UPPER )THEN357:DO40 J = 1, N 358: J1 =MAX( J-KD, 1 ) 359:CALLSCOPY( J-J1+1,AB( KD+1-J+J1, J ), 1, 360: $AFB( KD+1-J+J1, J ), 1 ) 361: 40CONTINUE362:ELSE363:DO50 J = 1, N 364: J2 =MIN( J+KD, N ) 365:CALLSCOPY( J2-J+1,AB( 1, J ), 1,AFB( 1, J ), 1 ) 366: 50CONTINUE367:ENDIF368:*369:CALLSPBTRF( UPLO, N, KD, AFB, LDAFB, INFO ) 370:*371:* Return if INFO is non-zero.372:*373:IF( INFO.GT.0 )THEN374: RCOND = ZERO 375:RETURN376:ENDIF377:ENDIF378:*379:* Compute the norm of the matrix A.380:*381: ANORM =SLANSB( '1', UPLO, N, KD, AB, LDAB, WORK ) 382:*383:* Compute the reciprocal of the condition number of A.384:*385:CALLSPBCON( UPLO, N, KD, AFB, LDAFB, ANORM, RCOND, WORK, IWORK, 386: $ INFO ) 387:*388:* Compute the solution matrix X.389:*390:CALLSLACPY( 'Full', N, NRHS, B, LDB, X, LDX ) 391:CALLSPBTRS( UPLO, N, KD, NRHS, AFB, LDAFB, X, LDX, INFO ) 392:*393:* Use iterative refinement to improve the computed solution and394:* compute error bounds and backward error estimates for it.395:*396:CALLSPBRFS( UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, B, LDB, X, 397: $ LDX, FERR, BERR, WORK, IWORK, INFO ) 398:*399:* Transform the solution matrix X to a solution of the original400:* system.401:*402:IF( RCEQU )THEN403:DO70 J = 1, NRHS 404:DO60 I = 1, N 405:X( I, J ) =S( I )*X( I, J ) 406: 60CONTINUE407: 70CONTINUE408:DO80 J = 1, NRHS 409:FERR( J ) =FERR( J ) / SCOND 410: 80CONTINUE411:ENDIF412:*413:* Set INFO = N+1 if the matrix is singular to working precision.414:*415:IF( RCOND.LT.SLAMCH( 'Epsilon' ) ) 416: $ INFO = N + 1 417:*418:RETURN419:*420:* End of SPBSVX421:*422:END423: