1 *> \brief <b> CPBSVX computes the solution to system of linear equations A * X = B for OTHER matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CPBSVX + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cpbsvx.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cpbsvx.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cpbsvx.f">
21 * SUBROUTINE CPBSVX( FACT, UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB,
22 * EQUED, S, B, LDB, X, LDX, RCOND, FERR, BERR,
25 * .. Scalar Arguments ..
26 * CHARACTER EQUED, FACT, UPLO
27 * INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS
30 * .. Array Arguments ..
31 * REAL BERR( * ), FERR( * ), RWORK( * ), S( * )
32 * COMPLEX AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
33 * $ WORK( * ), X( LDX, * )
42 *> CPBSVX uses the Cholesky factorization A = U**H*U or A = L*L**H to
43 *> compute the solution to a complex system of linear equations
45 *> where A is an N-by-N Hermitian positive definite band matrix and X
46 *> and B are N-by-NRHS matrices.
48 *> Error bounds on the solution and a condition estimate are also
57 *> The following steps are performed:
59 *> 1. If FACT = 'E', real scaling factors are computed to equilibrate
61 *> diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B
62 *> Whether or not the system will be equilibrated depends on the
63 *> scaling of the matrix A, but if equilibration is used, A is
64 *> overwritten by diag(S)*A*diag(S) and B by diag(S)*B.
66 *> 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to
67 *> factor the matrix A (after equilibration if FACT = 'E') as
68 *> A = U**H * U, if UPLO = 'U', or
69 *> A = L * L**H, if UPLO = 'L',
70 *> where U is an upper triangular band matrix, and L is a lower
71 *> triangular band matrix.
73 *> 3. If the leading i-by-i principal minor is not positive definite,
74 *> then the routine returns with INFO = i. Otherwise, the factored
75 *> form of A is used to estimate the condition number of the matrix
76 *> A. If the reciprocal of the condition number is less than machine
77 *> precision, INFO = N+1 is returned as a warning, but the routine
78 *> still goes on to solve for X and compute error bounds as
81 *> 4. The system of equations is solved for X using the factored form
84 *> 5. Iterative refinement is applied to improve the computed solution
85 *> matrix and calculate error bounds and backward error estimates
88 *> 6. If equilibration was used, the matrix X is premultiplied by
89 *> diag(S) so that it solves the original system before
98 *> FACT is CHARACTER*1
99 *> Specifies whether or not the factored form of the matrix A is
100 *> supplied on entry, and if not, whether the matrix A should be
101 *> equilibrated before it is factored.
102 *> = 'F': On entry, AFB contains the factored form of A.
103 *> If EQUED = 'Y', the matrix A has been equilibrated
104 *> with scaling factors given by S. AB and AFB will not
106 *> = 'N': The matrix A will be copied to AFB and factored.
107 *> = 'E': The matrix A will be equilibrated if necessary, then
108 *> copied to AFB and factored.
113 *> UPLO is CHARACTER*1
114 *> = 'U': Upper triangle of A is stored;
115 *> = 'L': Lower triangle of A is stored.
121 *> The number of linear equations, i.e., the order of the
128 *> The number of superdiagonals of the matrix A if UPLO = 'U',
129 *> or the number of subdiagonals if UPLO = 'L'. KD >= 0.
135 *> The number of right-hand sides, i.e., the number of columns
136 *> of the matrices B and X. NRHS >= 0.
141 *> AB is COMPLEX array, dimension (LDAB,N)
142 *> On entry, the upper or lower triangle of the Hermitian band
143 *> matrix A, stored in the first KD+1 rows of the array, except
144 *> if FACT = 'F' and EQUED = 'Y', then A must contain the
145 *> equilibrated matrix diag(S)*A*diag(S). The j-th column of A
146 *> is stored in the j-th column of the array AB as follows:
147 *> if UPLO = 'U', AB(KD+1+i-j,j) = A(i,j) for max(1,j-KD)<=i<=j;
148 *> if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(N,j+KD).
149 *> See below for further details.
151 *> On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by
152 *> diag(S)*A*diag(S).
158 *> The leading dimension of the array A. LDAB >= KD+1.
161 *> \param[in,out] AFB
163 *> AFB is COMPLEX array, dimension (LDAFB,N)
164 *> If FACT = 'F', then AFB is an input argument and on entry
165 *> contains the triangular factor U or L from the Cholesky
166 *> factorization A = U**H*U or A = L*L**H of the band matrix
167 *> A, in the same storage format as A (see AB). If EQUED = 'Y',
168 *> then AFB is the factored form of the equilibrated matrix A.
170 *> If FACT = 'N', then AFB is an output argument and on exit
171 *> returns the triangular factor U or L from the Cholesky
172 *> factorization A = U**H*U or A = L*L**H.
174 *> If FACT = 'E', then AFB is an output argument and on exit
175 *> returns the triangular factor U or L from the Cholesky
176 *> factorization A = U**H*U or A = L*L**H of the equilibrated
177 *> matrix A (see the description of A for the form of the
178 *> equilibrated matrix).
184 *> The leading dimension of the array AFB. LDAFB >= KD+1.
187 *> \param[in,out] EQUED
189 *> EQUED is CHARACTER*1
190 *> Specifies the form of equilibration that was done.
191 *> = 'N': No equilibration (always true if FACT = 'N').
192 *> = 'Y': Equilibration was done, i.e., A has been replaced by
193 *> diag(S) * A * diag(S).
194 *> EQUED is an input argument if FACT = 'F'; otherwise, it is an
200 *> S is REAL array, dimension (N)
201 *> The scale factors for A; not accessed if EQUED = 'N'. S is
202 *> an input argument if FACT = 'F'; otherwise, S is an output
203 *> argument. If FACT = 'F' and EQUED = 'Y', each element of S
209 *> B is COMPLEX array, dimension (LDB,NRHS)
210 *> On entry, the N-by-NRHS right hand side matrix B.
211 *> On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y',
212 *> B is overwritten by diag(S) * B.
218 *> The leading dimension of the array B. LDB >= max(1,N).
223 *> X is COMPLEX array, dimension (LDX,NRHS)
224 *> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to
225 *> the original system of equations. Note that if EQUED = 'Y',
226 *> A and B are modified on exit, and the solution to the
227 *> equilibrated system is inv(diag(S))*X.
233 *> The leading dimension of the array X. LDX >= max(1,N).
239 *> The estimate of the reciprocal condition number of the matrix
240 *> A after equilibration (if done). If RCOND is less than the
241 *> machine precision (in particular, if RCOND = 0), the matrix
242 *> is singular to working precision. This condition is
243 *> indicated by a return code of INFO > 0.
248 *> FERR is REAL array, dimension (NRHS)
249 *> The estimated forward error bound for each solution vector
250 *> X(j) (the j-th column of the solution matrix X).
251 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
252 *> is an estimated upper bound for the magnitude of the largest
253 *> element in (X(j) - XTRUE) divided by the magnitude of the
254 *> largest element in X(j). The estimate is as reliable as
255 *> the estimate for RCOND, and is almost always a slight
256 *> overestimate of the true error.
261 *> BERR is REAL array, dimension (NRHS)
262 *> The componentwise relative backward error of each solution
263 *> vector X(j) (i.e., the smallest relative change in
264 *> any element of A or B that makes X(j) an exact solution).
269 *> WORK is COMPLEX array, dimension (2*N)
274 *> RWORK is REAL array, dimension (N)
280 *> = 0: successful exit
281 *> < 0: if INFO = -i, the i-th argument had an illegal value
282 *> > 0: if INFO = i, and i is
283 *> <= N: the leading minor of order i of A is
284 *> not positive definite, so the factorization
285 *> could not be completed, and the solution has not
286 *> been computed. RCOND = 0 is returned.
287 *> = N+1: U is nonsingular, but RCOND is less than machine
288 *> precision, meaning that the matrix is singular
289 *> to working precision. Nevertheless, the
290 *> solution and error bounds are computed because
291 *> there are a number of situations where the
292 *> computed solution can be more accurate than the
293 *> value of RCOND would suggest.
299 *> \author Univ. of Tennessee
300 *> \author Univ. of California Berkeley
301 *> \author Univ. of Colorado Denver
306 *> \ingroup complexOTHERsolve
308 *> \par Further Details:
309 * =====================
313 *> The band storage scheme is illustrated by the following example, when
314 *> N = 6, KD = 2, and UPLO = 'U':
316 *> Two-dimensional storage of the Hermitian matrix A:
323 *> (aij=conjg(aji)) a66
325 *> Band storage of the upper triangle of A:
327 *> * * a13 a24 a35 a46
328 *> * a12 a23 a34 a45 a56
329 *> a11 a22 a33 a44 a55 a66
331 *> Similarly, if UPLO = 'L' the format of A is as follows:
333 *> a11 a22 a33 a44 a55 a66
334 *> a21 a32 a43 a54 a65 *
335 *> a31 a42 a53 a64 * *
337 *> Array elements marked * are not used by the routine.
340 * =====================================================================
341 SUBROUTINE CPBSVX( FACT, UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB,
342 $ EQUED, S, B, LDB, X, LDX, RCOND, FERR, BERR,
343 $ WORK, RWORK, INFO )
345 * -- LAPACK driver routine (version 3.4.1) --
346 * -- LAPACK is a software package provided by Univ. of Tennessee, --
347 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
350 * .. Scalar Arguments ..
351 CHARACTER EQUED, FACT, UPLO
352 INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS
355 * .. Array Arguments ..
356 REAL BERR( * ), FERR( * ), RWORK( * ), S( * )
357 COMPLEX AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
358 $ WORK( * ), X( LDX, * )
361 * =====================================================================
365 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
367 * .. Local Scalars ..
368 LOGICAL EQUIL, NOFACT, RCEQU, UPPER
369 INTEGER I, INFEQU, J, J1, J2
370 REAL AMAX, ANORM, BIGNUM, SCOND, SMAX, SMIN, SMLNUM
372 * .. External Functions ..
375 EXTERNAL LSAME, CLANHB, SLAMCH
377 * .. External Subroutines ..
378 EXTERNAL CCOPY, CLACPY, CLAQHB, CPBCON, CPBEQU, CPBRFS,
379 $ CPBTRF, CPBTRS, XERBLA
381 * .. Intrinsic Functions ..
384 * .. Executable Statements ..
387 NOFACT = LSAME( FACT, 'N' )
388 EQUIL = LSAME( FACT, 'E' )
389 UPPER = LSAME( UPLO, 'U' )
390 IF( NOFACT .OR. EQUIL ) THEN
394 RCEQU = LSAME( EQUED, 'Y' )
395 SMLNUM = SLAMCH( 'Safe minimum' )
396 BIGNUM = ONE / SMLNUM
399 * Test the input parameters.
401 IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) )
404 ELSE IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
406 ELSE IF( N.LT.0 ) THEN
408 ELSE IF( KD.LT.0 ) THEN
410 ELSE IF( NRHS.LT.0 ) THEN
412 ELSE IF( LDAB.LT.KD+1 ) THEN
414 ELSE IF( LDAFB.LT.KD+1 ) THEN
416 ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT.
417 $ ( RCEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN
424 SMIN = MIN( SMIN, S( J ) )
425 SMAX = MAX( SMAX, S( J ) )
427 IF( SMIN.LE.ZERO ) THEN
429 ELSE IF( N.GT.0 ) THEN
430 SCOND = MAX( SMIN, SMLNUM ) / MIN( SMAX, BIGNUM )
436 IF( LDB.LT.MAX( 1, N ) ) THEN
438 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
445 CALL XERBLA( 'CPBSVX', -INFO )
451 * Compute row and column scalings to equilibrate the matrix A.
453 CALL CPBEQU( UPLO, N, KD, AB, LDAB, S, SCOND, AMAX, INFEQU )
454 IF( INFEQU.EQ.0 ) THEN
456 * Equilibrate the matrix.
458 CALL CLAQHB( UPLO, N, KD, AB, LDAB, S, SCOND, AMAX, EQUED )
459 RCEQU = LSAME( EQUED, 'Y' )
463 * Scale the right-hand side.
468 B( I, J ) = S( I )*B( I, J )
473 IF( NOFACT .OR. EQUIL ) THEN
475 * Compute the Cholesky factorization A = U**H *U or A = L*L**H.
480 CALL CCOPY( J-J1+1, AB( KD+1-J+J1, J ), 1,
481 $ AFB( KD+1-J+J1, J ), 1 )
486 CALL CCOPY( J2-J+1, AB( 1, J ), 1, AFB( 1, J ), 1 )
490 CALL CPBTRF( UPLO, N, KD, AFB, LDAFB, INFO )
492 * Return if INFO is non-zero.
500 * Compute the norm of the matrix A.
502 ANORM = CLANHB( '1', UPLO, N, KD, AB, LDAB, RWORK )
504 * Compute the reciprocal of the condition number of A.
506 CALL CPBCON( UPLO, N, KD, AFB, LDAFB, ANORM, RCOND, WORK, RWORK,
509 * Compute the solution matrix X.
511 CALL CLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
512 CALL CPBTRS( UPLO, N, KD, NRHS, AFB, LDAFB, X, LDX, INFO )
514 * Use iterative refinement to improve the computed solution and
515 * compute error bounds and backward error estimates for it.
517 CALL CPBRFS( UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, B, LDB, X,
518 $ LDX, FERR, BERR, WORK, RWORK, INFO )
520 * Transform the solution matrix X to a solution of the original
526 X( I, J ) = S( I )*X( I, J )
530 FERR( J ) = FERR( J ) / SCOND
534 * Set INFO = N+1 if the matrix is singular to working precision.
536 IF( RCOND.LT.SLAMCH( 'Epsilon' ) )