LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
dposvx.f
Go to the documentation of this file.
1*> \brief <b> DPOSVX computes the solution to system of linear equations A * X = B for PO matrices</b>
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download DPOSVX + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dposvx.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dposvx.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dposvx.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE DPOSVX( FACT, UPLO, N, NRHS, A, LDA, AF, LDAF, EQUED,
20* S, B, LDB, X, LDX, RCOND, FERR, BERR, WORK,
21* IWORK, INFO )
22*
23* .. Scalar Arguments ..
24* CHARACTER EQUED, FACT, UPLO
25* INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
26* DOUBLE PRECISION RCOND
27* ..
28* .. Array Arguments ..
29* INTEGER IWORK( * )
30* DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
31* $ BERR( * ), FERR( * ), S( * ), WORK( * ),
32* $ X( LDX, * )
33* ..
34*
35*
36*> \par Purpose:
37* =============
38*>
39*> \verbatim
40*>
41*> DPOSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to
42*> compute the solution to a real system of linear equations
43*> A * X = B,
44*> where A is an N-by-N symmetric positive definite matrix and X and B
45*> are N-by-NRHS matrices.
46*>
47*> Error bounds on the solution and a condition estimate are also
48*> provided.
49*> \endverbatim
50*
51*> \par Description:
52* =================
53*>
54*> \verbatim
55*>
56*> The following steps are performed:
57*>
58*> 1. If FACT = 'E', real scaling factors are computed to equilibrate
59*> the system:
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.
64*>
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**T* U, if UPLO = 'U', or
68*> A = L * L**T, if UPLO = 'L',
69*> where U is an upper triangular matrix and L is a lower triangular
70*> matrix.
71*>
72*> 3. If the leading principal minor of order i is not positive,
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
78*> described below.
79*>
80*> 4. The system of equations is solved for X using the factored form
81*> of A.
82*>
83*> 5. Iterative refinement is applied to improve the computed solution
84*> matrix and calculate error bounds and backward error estimates
85*> for it.
86*>
87*> 6. If equilibration was used, the matrix X is premultiplied by
88*> diag(S) so that it solves the original system before
89*> equilibration.
90*> \endverbatim
91*
92* Arguments:
93* ==========
94*
95*> \param[in] FACT
96*> \verbatim
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, AF contains the factored form of A.
102*> If EQUED = 'Y', the matrix A has been equilibrated
103*> with scaling factors given by S. A and AF will not
104*> be modified.
105*> = 'N': The matrix A will be copied to AF and factored.
106*> = 'E': The matrix A will be equilibrated if necessary, then
107*> copied to AF and factored.
108*> \endverbatim
109*>
110*> \param[in] UPLO
111*> \verbatim
112*> UPLO is CHARACTER*1
113*> = 'U': Upper triangle of A is stored;
114*> = 'L': Lower triangle of A is stored.
115*> \endverbatim
116*>
117*> \param[in] N
118*> \verbatim
119*> N is INTEGER
120*> The number of linear equations, i.e., the order of the
121*> matrix A. N >= 0.
122*> \endverbatim
123*>
124*> \param[in] NRHS
125*> \verbatim
126*> NRHS is INTEGER
127*> The number of right hand sides, i.e., the number of columns
128*> of the matrices B and X. NRHS >= 0.
129*> \endverbatim
130*>
131*> \param[in,out] A
132*> \verbatim
133*> A is DOUBLE PRECISION array, dimension (LDA,N)
134*> On entry, the symmetric matrix A, except if FACT = 'F' and
135*> EQUED = 'Y', then A must contain the equilibrated matrix
136*> diag(S)*A*diag(S). If UPLO = 'U', the leading
137*> N-by-N upper triangular part of A contains the upper
138*> triangular part of the matrix A, and the strictly lower
139*> triangular part of A is not referenced. If UPLO = 'L', the
140*> leading N-by-N lower triangular part of A contains the lower
141*> triangular part of the matrix A, and the strictly upper
142*> triangular part of A is not referenced. A is not modified if
143*> FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit.
144*>
145*> On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by
146*> diag(S)*A*diag(S).
147*> \endverbatim
148*>
149*> \param[in] LDA
150*> \verbatim
151*> LDA is INTEGER
152*> The leading dimension of the array A. LDA >= max(1,N).
153*> \endverbatim
154*>
155*> \param[in,out] AF
156*> \verbatim
157*> AF is DOUBLE PRECISION array, dimension (LDAF,N)
158*> If FACT = 'F', then AF is an input argument and on entry
159*> contains the triangular factor U or L from the Cholesky
160*> factorization A = U**T*U or A = L*L**T, in the same storage
161*> format as A. If EQUED .ne. 'N', then AF is the factored form
162*> of the equilibrated matrix diag(S)*A*diag(S).
163*>
164*> If FACT = 'N', then AF is an output argument and on exit
165*> returns the triangular factor U or L from the Cholesky
166*> factorization A = U**T*U or A = L*L**T of the original
167*> matrix A.
168*>
169*> If FACT = 'E', then AF is an output argument and on exit
170*> returns the triangular factor U or L from the Cholesky
171*> factorization A = U**T*U or A = L*L**T of the equilibrated
172*> matrix A (see the description of A for the form of the
173*> equilibrated matrix).
174*> \endverbatim
175*>
176*> \param[in] LDAF
177*> \verbatim
178*> LDAF is INTEGER
179*> The leading dimension of the array AF. LDAF >= max(1,N).
180*> \endverbatim
181*>
182*> \param[in,out] EQUED
183*> \verbatim
184*> EQUED is CHARACTER*1
185*> Specifies the form of equilibration that was done.
186*> = 'N': No equilibration (always true if FACT = 'N').
187*> = 'Y': Equilibration was done, i.e., A has been replaced by
188*> diag(S) * A * diag(S).
189*> EQUED is an input argument if FACT = 'F'; otherwise, it is an
190*> output argument.
191*> \endverbatim
192*>
193*> \param[in,out] S
194*> \verbatim
195*> S is DOUBLE PRECISION array, dimension (N)
196*> The scale factors for A; not accessed if EQUED = 'N'. S is
197*> an input argument if FACT = 'F'; otherwise, S is an output
198*> argument. If FACT = 'F' and EQUED = 'Y', each element of S
199*> must be positive.
200*> \endverbatim
201*>
202*> \param[in,out] B
203*> \verbatim
204*> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
205*> On entry, the N-by-NRHS right hand side matrix B.
206*> On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y',
207*> B is overwritten by diag(S) * B.
208*> \endverbatim
209*>
210*> \param[in] LDB
211*> \verbatim
212*> LDB is INTEGER
213*> The leading dimension of the array B. LDB >= max(1,N).
214*> \endverbatim
215*>
216*> \param[out] X
217*> \verbatim
218*> X is DOUBLE PRECISION array, dimension (LDX,NRHS)
219*> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to
220*> the original system of equations. Note that if EQUED = 'Y',
221*> A and B are modified on exit, and the solution to the
222*> equilibrated system is inv(diag(S))*X.
223*> \endverbatim
224*>
225*> \param[in] LDX
226*> \verbatim
227*> LDX is INTEGER
228*> The leading dimension of the array X. LDX >= max(1,N).
229*> \endverbatim
230*>
231*> \param[out] RCOND
232*> \verbatim
233*> RCOND is DOUBLE PRECISION
234*> The estimate of the reciprocal condition number of the matrix
235*> A after equilibration (if done). If RCOND is less than the
236*> machine precision (in particular, if RCOND = 0), the matrix
237*> is singular to working precision. This condition is
238*> indicated by a return code of INFO > 0.
239*> \endverbatim
240*>
241*> \param[out] FERR
242*> \verbatim
243*> FERR is DOUBLE PRECISION array, dimension (NRHS)
244*> The estimated forward error bound for each solution vector
245*> X(j) (the j-th column of the solution matrix X).
246*> If XTRUE is the true solution corresponding to X(j), FERR(j)
247*> is an estimated upper bound for the magnitude of the largest
248*> element in (X(j) - XTRUE) divided by the magnitude of the
249*> largest element in X(j). The estimate is as reliable as
250*> the estimate for RCOND, and is almost always a slight
251*> overestimate of the true error.
252*> \endverbatim
253*>
254*> \param[out] BERR
255*> \verbatim
256*> BERR is DOUBLE PRECISION array, dimension (NRHS)
257*> The componentwise relative backward error of each solution
258*> vector X(j) (i.e., the smallest relative change in
259*> any element of A or B that makes X(j) an exact solution).
260*> \endverbatim
261*>
262*> \param[out] WORK
263*> \verbatim
264*> WORK is DOUBLE PRECISION array, dimension (3*N)
265*> \endverbatim
266*>
267*> \param[out] IWORK
268*> \verbatim
269*> IWORK is INTEGER array, dimension (N)
270*> \endverbatim
271*>
272*> \param[out] INFO
273*> \verbatim
274*> INFO is INTEGER
275*> = 0: successful exit
276*> < 0: if INFO = -i, the i-th argument had an illegal value
277*> > 0: if INFO = i, and i is
278*> <= N: the leading principal minor of order i of A
279*> is not positive, so the factorization could not
280*> be completed, and the solution has not been
281*> computed. RCOND = 0 is returned.
282*> = N+1: U is nonsingular, but RCOND is less than machine
283*> precision, meaning that the matrix is singular
284*> to working precision. Nevertheless, the
285*> solution and error bounds are computed because
286*> there are a number of situations where the
287*> computed solution can be more accurate than the
288*> value of RCOND would suggest.
289*> \endverbatim
290*
291* Authors:
292* ========
293*
294*> \author Univ. of Tennessee
295*> \author Univ. of California Berkeley
296*> \author Univ. of Colorado Denver
297*> \author NAG Ltd.
298*
299*> \ingroup posvx
300*
301* =====================================================================
302 SUBROUTINE dposvx( FACT, UPLO, N, NRHS, A, LDA, AF, LDAF,
303 $ EQUED,
304 $ S, B, LDB, X, LDX, RCOND, FERR, BERR, WORK,
305 $ IWORK, INFO )
306*
307* -- LAPACK driver routine --
308* -- LAPACK is a software package provided by Univ. of Tennessee, --
309* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
310*
311* .. Scalar Arguments ..
312 CHARACTER EQUED, FACT, UPLO
313 INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
314 DOUBLE PRECISION RCOND
315* ..
316* .. Array Arguments ..
317 INTEGER IWORK( * )
318 DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
319 $ BERR( * ), FERR( * ), S( * ), WORK( * ),
320 $ x( ldx, * )
321* ..
322*
323* =====================================================================
324*
325* .. Parameters ..
326 DOUBLE PRECISION ZERO, ONE
327 PARAMETER ( ZERO = 0.0d+0, one = 1.0d+0 )
328* ..
329* .. Local Scalars ..
330 LOGICAL EQUIL, NOFACT, RCEQU
331 INTEGER I, INFEQU, J
332 DOUBLE PRECISION AMAX, ANORM, BIGNUM, SCOND, SMAX, SMIN, SMLNUM
333* ..
334* .. External Functions ..
335 LOGICAL LSAME
336 DOUBLE PRECISION DLAMCH, DLANSY
337 EXTERNAL LSAME, DLAMCH, DLANSY
338* ..
339* .. External Subroutines ..
340 EXTERNAL dlacpy, dlaqsy, dpocon, dpoequ, dporfs,
341 $ dpotrf,
342 $ dpotrs, xerbla
343* ..
344* .. Intrinsic Functions ..
345 INTRINSIC max, min
346* ..
347* .. Executable Statements ..
348*
349 info = 0
350 nofact = lsame( fact, 'N' )
351 equil = lsame( fact, 'E' )
352 IF( nofact .OR. equil ) THEN
353 equed = 'N'
354 rcequ = .false.
355 ELSE
356 rcequ = lsame( equed, 'Y' )
357 smlnum = dlamch( 'Safe minimum' )
358 bignum = one / smlnum
359 END IF
360*
361* Test the input parameters.
362*
363 IF( .NOT.nofact .AND.
364 $ .NOT.equil .AND.
365 $ .NOT.lsame( fact, 'F' ) )
366 $ THEN
367 info = -1
368 ELSE IF( .NOT.lsame( uplo, 'U' ) .AND.
369 $ .NOT.lsame( uplo, 'L' ) )
370 $ THEN
371 info = -2
372 ELSE IF( n.LT.0 ) THEN
373 info = -3
374 ELSE IF( nrhs.LT.0 ) THEN
375 info = -4
376 ELSE IF( lda.LT.max( 1, n ) ) THEN
377 info = -6
378 ELSE IF( ldaf.LT.max( 1, n ) ) THEN
379 info = -8
380 ELSE IF( lsame( fact, 'F' ) .AND. .NOT.
381 $ ( rcequ .OR. lsame( equed, 'N' ) ) ) THEN
382 info = -9
383 ELSE
384 IF( rcequ ) THEN
385 smin = bignum
386 smax = zero
387 DO 10 j = 1, n
388 smin = min( smin, s( j ) )
389 smax = max( smax, s( j ) )
390 10 CONTINUE
391 IF( smin.LE.zero ) THEN
392 info = -10
393 ELSE IF( n.GT.0 ) THEN
394 scond = max( smin, smlnum ) / min( smax, bignum )
395 ELSE
396 scond = one
397 END IF
398 END IF
399 IF( info.EQ.0 ) THEN
400 IF( ldb.LT.max( 1, n ) ) THEN
401 info = -12
402 ELSE IF( ldx.LT.max( 1, n ) ) THEN
403 info = -14
404 END IF
405 END IF
406 END IF
407*
408 IF( info.NE.0 ) THEN
409 CALL xerbla( 'DPOSVX', -info )
410 RETURN
411 END IF
412*
413 IF( equil ) THEN
414*
415* Compute row and column scalings to equilibrate the matrix A.
416*
417 CALL dpoequ( n, a, lda, s, scond, amax, infequ )
418 IF( infequ.EQ.0 ) THEN
419*
420* Equilibrate the matrix.
421*
422 CALL dlaqsy( uplo, n, a, lda, s, scond, amax, equed )
423 rcequ = lsame( equed, 'Y' )
424 END IF
425 END IF
426*
427* Scale the right hand side.
428*
429 IF( rcequ ) THEN
430 DO 30 j = 1, nrhs
431 DO 20 i = 1, n
432 b( i, j ) = s( i )*b( i, j )
433 20 CONTINUE
434 30 CONTINUE
435 END IF
436*
437 IF( nofact .OR. equil ) THEN
438*
439* Compute the Cholesky factorization A = U**T *U or A = L*L**T.
440*
441 CALL dlacpy( uplo, n, n, a, lda, af, ldaf )
442 CALL dpotrf( uplo, n, af, ldaf, info )
443*
444* Return if INFO is non-zero.
445*
446 IF( info.GT.0 )THEN
447 rcond = zero
448 RETURN
449 END IF
450 END IF
451*
452* Compute the norm of the matrix A.
453*
454 anorm = dlansy( '1', uplo, n, a, lda, work )
455*
456* Compute the reciprocal of the condition number of A.
457*
458 CALL dpocon( uplo, n, af, ldaf, anorm, rcond, work, iwork,
459 $ info )
460*
461* Compute the solution matrix X.
462*
463 CALL dlacpy( 'Full', n, nrhs, b, ldb, x, ldx )
464 CALL dpotrs( uplo, n, nrhs, af, ldaf, x, ldx, info )
465*
466* Use iterative refinement to improve the computed solution and
467* compute error bounds and backward error estimates for it.
468*
469 CALL dporfs( uplo, n, nrhs, a, lda, af, ldaf, b, ldb, x, ldx,
470 $ ferr, berr, work, iwork, info )
471*
472* Transform the solution matrix X to a solution of the original
473* system.
474*
475 IF( rcequ ) THEN
476 DO 50 j = 1, nrhs
477 DO 40 i = 1, n
478 x( i, j ) = s( i )*x( i, j )
479 40 CONTINUE
480 50 CONTINUE
481 DO 60 j = 1, nrhs
482 ferr( j ) = ferr( j ) / scond
483 60 CONTINUE
484 END IF
485*
486* Set INFO = N+1 if the matrix is singular to working precision.
487*
488 IF( rcond.LT.dlamch( 'Epsilon' ) )
489 $ info = n + 1
490*
491 RETURN
492*
493* End of DPOSVX
494*
495 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine dlacpy(uplo, m, n, a, lda, b, ldb)
DLACPY copies all or part of one two-dimensional array to another.
Definition dlacpy.f:101
subroutine dlaqsy(uplo, n, a, lda, s, scond, amax, equed)
DLAQSY scales a symmetric/Hermitian matrix, using scaling factors computed by spoequ.
Definition dlaqsy.f:131
subroutine dpocon(uplo, n, a, lda, anorm, rcond, work, iwork, info)
DPOCON
Definition dpocon.f:119
subroutine dpoequ(n, a, lda, s, scond, amax, info)
DPOEQU
Definition dpoequ.f:110
subroutine dporfs(uplo, n, nrhs, a, lda, af, ldaf, b, ldb, x, ldx, ferr, berr, work, iwork, info)
DPORFS
Definition dporfs.f:181
subroutine dposvx(fact, uplo, n, nrhs, a, lda, af, ldaf, equed, s, b, ldb, x, ldx, rcond, ferr, berr, work, iwork, info)
DPOSVX computes the solution to system of linear equations A * X = B for PO matrices
Definition dposvx.f:306
subroutine dpotrf(uplo, n, a, lda, info)
DPOTRF
Definition dpotrf.f:105
subroutine dpotrs(uplo, n, nrhs, a, lda, b, ldb, info)
DPOTRS
Definition dpotrs.f:108