1 *> \brief <b> ZPPSVX 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 ZPPSVX + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zppsvx.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zppsvx.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zppsvx.f">
21 * SUBROUTINE ZPPSVX( FACT, UPLO, N, NRHS, AP, AFP, EQUED, S, B, LDB,
22 * X, LDX, RCOND, FERR, BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER EQUED, FACT, UPLO
26 * INTEGER INFO, LDB, LDX, N, NRHS
27 * DOUBLE PRECISION RCOND
29 * .. Array Arguments ..
30 * DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * ), S( * )
31 * COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
41 *> ZPPSVX uses the Cholesky factorization A = U**H * U or A = L * L**H to
42 *> compute the solution to a complex system of linear equations
44 *> where A is an N-by-N Hermitian positive definite matrix stored in
45 *> packed format and X and B are N-by-NRHS matrices.
47 *> Error bounds on the solution and a condition estimate are also
56 *> The following steps are performed:
58 *> 1. If FACT = 'E', real scaling factors are computed to equilibrate
60 *> diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B
61 *> Whether or not the system will be equilibrated depends on the
62 *> scaling of the matrix A, but if equilibration is used, A is
63 *> overwritten by diag(S)*A*diag(S) and B by diag(S)*B.
65 *> 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to
66 *> factor the matrix A (after equilibration if FACT = 'E') as
67 *> A = U**H * U , if UPLO = 'U', or
68 *> A = L * L**H, if UPLO = 'L',
69 *> where U is an upper triangular matrix, L is a lower triangular
70 *> matrix, and **H indicates conjugate transpose.
72 *> 3. If the leading i-by-i principal minor is not positive definite,
73 *> then the routine returns with INFO = i. Otherwise, the factored
74 *> form of A is used to estimate the condition number of the matrix
75 *> A. If the reciprocal of the condition number is less than machine
76 *> precision, INFO = N+1 is returned as a warning, but the routine
77 *> still goes on to solve for X and compute error bounds as
80 *> 4. The system of equations is solved for X using the factored form
83 *> 5. Iterative refinement is applied to improve the computed solution
84 *> matrix and calculate error bounds and backward error estimates
87 *> 6. If equilibration was used, the matrix X is premultiplied by
88 *> diag(S) so that it solves the original system before
97 *> FACT is CHARACTER*1
98 *> Specifies whether or not the factored form of the matrix A is
99 *> supplied on entry, and if not, whether the matrix A should be
100 *> equilibrated before it is factored.
101 *> = 'F': On entry, AFP contains the factored form of A.
102 *> If EQUED = 'Y', the matrix A has been equilibrated
103 *> with scaling factors given by S. AP and AFP will not
105 *> = 'N': The matrix A will be copied to AFP and factored.
106 *> = 'E': The matrix A will be equilibrated if necessary, then
107 *> copied to AFP and factored.
112 *> UPLO is CHARACTER*1
113 *> = 'U': Upper triangle of A is stored;
114 *> = 'L': Lower triangle of A is stored.
120 *> The number of linear equations, i.e., the order of the
127 *> The number of right hand sides, i.e., the number of columns
128 *> of the matrices B and X. NRHS >= 0.
133 *> AP is COMPLEX*16 array, dimension (N*(N+1)/2)
134 *> On entry, the upper or lower triangle of the Hermitian matrix
135 *> A, packed columnwise in a linear array, except if FACT = 'F'
136 *> and EQUED = 'Y', then A must contain the equilibrated matrix
137 *> diag(S)*A*diag(S). The j-th column of A is stored in the
138 *> array AP as follows:
139 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
140 *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
141 *> See below for further details. A is not modified if
142 *> FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit.
144 *> On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by
145 *> diag(S)*A*diag(S).
148 *> \param[in,out] AFP
150 *> AFP is COMPLEX*16 array, dimension (N*(N+1)/2)
151 *> If FACT = 'F', then AFP is an input argument and on entry
152 *> contains the triangular factor U or L from the Cholesky
153 *> factorization A = U**H*U or A = L*L**H, in the same storage
154 *> format as A. If EQUED .ne. 'N', then AFP is the factored
155 *> form of the equilibrated matrix A.
157 *> If FACT = 'N', then AFP is an output argument and on exit
158 *> returns the triangular factor U or L from the Cholesky
159 *> factorization A = U**H * U or A = L * L**H of the original
162 *> If FACT = 'E', then AFP is an output argument and on exit
163 *> returns the triangular factor U or L from the Cholesky
164 *> factorization A = U**H * U or A = L * L**H of the equilibrated
165 *> matrix A (see the description of AP for the form of the
166 *> equilibrated matrix).
169 *> \param[in,out] EQUED
171 *> EQUED is CHARACTER*1
172 *> Specifies the form of equilibration that was done.
173 *> = 'N': No equilibration (always true if FACT = 'N').
174 *> = 'Y': Equilibration was done, i.e., A has been replaced by
175 *> diag(S) * A * diag(S).
176 *> EQUED is an input argument if FACT = 'F'; otherwise, it is an
182 *> S is DOUBLE PRECISION array, dimension (N)
183 *> The scale factors for A; not accessed if EQUED = 'N'. S is
184 *> an input argument if FACT = 'F'; otherwise, S is an output
185 *> argument. If FACT = 'F' and EQUED = 'Y', each element of S
191 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
192 *> On entry, the N-by-NRHS right hand side matrix B.
193 *> On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y',
194 *> B is overwritten by diag(S) * B.
200 *> The leading dimension of the array B. LDB >= max(1,N).
205 *> X is COMPLEX*16 array, dimension (LDX,NRHS)
206 *> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to
207 *> the original system of equations. Note that if EQUED = 'Y',
208 *> A and B are modified on exit, and the solution to the
209 *> equilibrated system is inv(diag(S))*X.
215 *> The leading dimension of the array X. LDX >= max(1,N).
220 *> RCOND is DOUBLE PRECISION
221 *> The estimate of the reciprocal condition number of the matrix
222 *> A after equilibration (if done). If RCOND is less than the
223 *> machine precision (in particular, if RCOND = 0), the matrix
224 *> is singular to working precision. This condition is
225 *> indicated by a return code of INFO > 0.
230 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
231 *> The estimated forward error bound for each solution vector
232 *> X(j) (the j-th column of the solution matrix X).
233 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
234 *> is an estimated upper bound for the magnitude of the largest
235 *> element in (X(j) - XTRUE) divided by the magnitude of the
236 *> largest element in X(j). The estimate is as reliable as
237 *> the estimate for RCOND, and is almost always a slight
238 *> overestimate of the true error.
243 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
244 *> The componentwise relative backward error of each solution
245 *> vector X(j) (i.e., the smallest relative change in
246 *> any element of A or B that makes X(j) an exact solution).
251 *> WORK is COMPLEX*16 array, dimension (2*N)
256 *> RWORK is DOUBLE PRECISION array, dimension (N)
262 *> = 0: successful exit
263 *> < 0: if INFO = -i, the i-th argument had an illegal value
264 *> > 0: if INFO = i, and i is
265 *> <= N: the leading minor of order i of A is
266 *> not positive definite, so the factorization
267 *> could not be completed, and the solution has not
268 *> been computed. RCOND = 0 is returned.
269 *> = N+1: U is nonsingular, but RCOND is less than machine
270 *> precision, meaning that the matrix is singular
271 *> to working precision. Nevertheless, the
272 *> solution and error bounds are computed because
273 *> there are a number of situations where the
274 *> computed solution can be more accurate than the
275 *> value of RCOND would suggest.
281 *> \author Univ. of Tennessee
282 *> \author Univ. of California Berkeley
283 *> \author Univ. of Colorado Denver
288 *> \ingroup complex16OTHERsolve
290 *> \par Further Details:
291 * =====================
295 *> The packed storage scheme is illustrated by the following example
296 *> when N = 4, UPLO = 'U':
298 *> Two-dimensional storage of the Hermitian matrix A:
302 *> a33 a34 (aij = conjg(aji))
305 *> Packed storage of the upper triangle of A:
307 *> AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ]
310 * =====================================================================
311 SUBROUTINE ZPPSVX( FACT, UPLO, N, NRHS, AP, AFP, EQUED, S, B, LDB,
312 $ X, LDX, RCOND, FERR, BERR, WORK, RWORK, INFO )
314 * -- LAPACK driver routine (version 3.4.1) --
315 * -- LAPACK is a software package provided by Univ. of Tennessee, --
316 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
319 * .. Scalar Arguments ..
320 CHARACTER EQUED, FACT, UPLO
321 INTEGER INFO, LDB, LDX, N, NRHS
322 DOUBLE PRECISION RCOND
324 * .. Array Arguments ..
325 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * ), S( * )
326 COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
330 * =====================================================================
333 DOUBLE PRECISION ZERO, ONE
334 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
336 * .. Local Scalars ..
337 LOGICAL EQUIL, NOFACT, RCEQU
339 DOUBLE PRECISION AMAX, ANORM, BIGNUM, SCOND, SMAX, SMIN, SMLNUM
341 * .. External Functions ..
343 DOUBLE PRECISION DLAMCH, ZLANHP
344 EXTERNAL LSAME, DLAMCH, ZLANHP
346 * .. External Subroutines ..
347 EXTERNAL XERBLA, ZCOPY, ZLACPY, ZLAQHP, ZPPCON, ZPPEQU,
348 $ ZPPRFS, ZPPTRF, ZPPTRS
350 * .. Intrinsic Functions ..
353 * .. Executable Statements ..
356 NOFACT = LSAME( FACT, 'N' )
357 EQUIL = LSAME( FACT, 'E' )
358 IF( NOFACT .OR. EQUIL ) THEN
362 RCEQU = LSAME( EQUED, 'Y' )
363 SMLNUM = DLAMCH( 'Safe minimum' )
364 BIGNUM = ONE / SMLNUM
367 * Test the input parameters.
369 IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) )
372 ELSE IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) )
375 ELSE IF( N.LT.0 ) THEN
377 ELSE IF( NRHS.LT.0 ) THEN
379 ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT.
380 $ ( RCEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN
387 SMIN = MIN( SMIN, S( J ) )
388 SMAX = MAX( SMAX, S( J ) )
390 IF( SMIN.LE.ZERO ) THEN
392 ELSE IF( N.GT.0 ) THEN
393 SCOND = MAX( SMIN, SMLNUM ) / MIN( SMAX, BIGNUM )
399 IF( LDB.LT.MAX( 1, N ) ) THEN
401 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
408 CALL XERBLA( 'ZPPSVX', -INFO )
414 * Compute row and column scalings to equilibrate the matrix A.
416 CALL ZPPEQU( UPLO, N, AP, S, SCOND, AMAX, INFEQU )
417 IF( INFEQU.EQ.0 ) THEN
419 * Equilibrate the matrix.
421 CALL ZLAQHP( UPLO, N, AP, S, SCOND, AMAX, EQUED )
422 RCEQU = LSAME( EQUED, 'Y' )
426 * Scale the right-hand side.
431 B( I, J ) = S( I )*B( I, J )
436 IF( NOFACT .OR. EQUIL ) THEN
438 * Compute the Cholesky factorization A = U**H * U or A = L * L**H.
440 CALL ZCOPY( N*( N+1 ) / 2, AP, 1, AFP, 1 )
441 CALL ZPPTRF( UPLO, N, AFP, INFO )
443 * Return if INFO is non-zero.
451 * Compute the norm of the matrix A.
453 ANORM = ZLANHP( 'I', UPLO, N, AP, RWORK )
455 * Compute the reciprocal of the condition number of A.
457 CALL ZPPCON( UPLO, N, AFP, ANORM, RCOND, WORK, RWORK, INFO )
459 * Compute the solution matrix X.
461 CALL ZLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
462 CALL ZPPTRS( UPLO, N, NRHS, AFP, X, LDX, INFO )
464 * Use iterative refinement to improve the computed solution and
465 * compute error bounds and backward error estimates for it.
467 CALL ZPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR, BERR,
468 $ WORK, RWORK, INFO )
470 * Transform the solution matrix X to a solution of the original
476 X( I, J ) = S( I )*X( I, J )
480 FERR( J ) = FERR( J ) / SCOND
484 * Set INFO = N+1 if the matrix is singular to working precision.
486 IF( RCOND.LT.DLAMCH( 'Epsilon' ) )