3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSYRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsyrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsyrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsyrfs.f">
21 * SUBROUTINE DSYRFS( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
22 * X, LDX, FERR, BERR, WORK, IWORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
29 * INTEGER IPIV( * ), IWORK( * )
30 * DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
31 * $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
40 *> DSYRFS improves the computed solution to a system of linear
41 *> equations when the coefficient matrix is symmetric indefinite, and
42 *> provides error bounds and backward error estimates for the solution.
50 *> UPLO is CHARACTER*1
51 *> = 'U': Upper triangle of A is stored;
52 *> = 'L': Lower triangle of A is stored.
58 *> The order of the matrix A. N >= 0.
64 *> The number of right hand sides, i.e., the number of columns
65 *> of the matrices B and X. NRHS >= 0.
70 *> A is DOUBLE PRECISION array, dimension (LDA,N)
71 *> The symmetric matrix A. If UPLO = 'U', the leading N-by-N
72 *> upper triangular part of A contains the upper triangular part
73 *> of the matrix A, and the strictly lower triangular part of A
74 *> is not referenced. If UPLO = 'L', the leading N-by-N lower
75 *> triangular part of A contains the lower triangular part of
76 *> the matrix A, and the strictly upper triangular part of A is
83 *> The leading dimension of the array A. LDA >= max(1,N).
88 *> AF is DOUBLE PRECISION array, dimension (LDAF,N)
89 *> The factored form of the matrix A. AF contains the block
90 *> diagonal matrix D and the multipliers used to obtain the
91 *> factor U or L from the factorization A = U*D*U**T or
92 *> A = L*D*L**T as computed by DSYTRF.
98 *> The leading dimension of the array AF. LDAF >= max(1,N).
103 *> IPIV is INTEGER array, dimension (N)
104 *> Details of the interchanges and the block structure of D
105 *> as determined by DSYTRF.
110 *> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
111 *> The right hand side matrix B.
117 *> The leading dimension of the array B. LDB >= max(1,N).
122 *> X is DOUBLE PRECISION array, dimension (LDX,NRHS)
123 *> On entry, the solution matrix X, as computed by DSYTRS.
124 *> On exit, the improved solution matrix X.
130 *> The leading dimension of the array X. LDX >= max(1,N).
135 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
136 *> The estimated forward error bound for each solution vector
137 *> X(j) (the j-th column of the solution matrix X).
138 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
139 *> is an estimated upper bound for the magnitude of the largest
140 *> element in (X(j) - XTRUE) divided by the magnitude of the
141 *> largest element in X(j). The estimate is as reliable as
142 *> the estimate for RCOND, and is almost always a slight
143 *> overestimate of the true error.
148 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
149 *> The componentwise relative backward error of each solution
150 *> vector X(j) (i.e., the smallest relative change in
151 *> any element of A or B that makes X(j) an exact solution).
156 *> WORK is DOUBLE PRECISION array, dimension (3*N)
161 *> IWORK is INTEGER array, dimension (N)
167 *> = 0: successful exit
168 *> < 0: if INFO = -i, the i-th argument had an illegal value
171 *> \par Internal Parameters:
172 * =========================
175 *> ITMAX is the maximum number of steps of iterative refinement.
181 *> \author Univ. of Tennessee
182 *> \author Univ. of California Berkeley
183 *> \author Univ. of Colorado Denver
186 *> \date November 2011
188 *> \ingroup doubleSYcomputational
190 * =====================================================================
191 SUBROUTINE DSYRFS( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
192 $ X, LDX, FERR, BERR, WORK, IWORK, INFO )
194 * -- LAPACK computational routine (version 3.4.0) --
195 * -- LAPACK is a software package provided by Univ. of Tennessee, --
196 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
199 * .. Scalar Arguments ..
201 INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
203 * .. Array Arguments ..
204 INTEGER IPIV( * ), IWORK( * )
205 DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
206 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
209 * =====================================================================
213 PARAMETER ( ITMAX = 5 )
214 DOUBLE PRECISION ZERO
215 PARAMETER ( ZERO = 0.0D+0 )
217 PARAMETER ( ONE = 1.0D+0 )
219 PARAMETER ( TWO = 2.0D+0 )
220 DOUBLE PRECISION THREE
221 PARAMETER ( THREE = 3.0D+0 )
223 * .. Local Scalars ..
225 INTEGER COUNT, I, J, K, KASE, NZ
226 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
231 * .. External Subroutines ..
232 EXTERNAL DAXPY, DCOPY, DLACN2, DSYMV, DSYTRS, XERBLA
234 * .. Intrinsic Functions ..
237 * .. External Functions ..
239 DOUBLE PRECISION DLAMCH
240 EXTERNAL LSAME, DLAMCH
242 * .. Executable Statements ..
244 * Test the input parameters.
247 UPPER = LSAME( UPLO, 'U' )
248 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
250 ELSE IF( N.LT.0 ) THEN
252 ELSE IF( NRHS.LT.0 ) THEN
254 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
256 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
258 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
260 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
264 CALL XERBLA( 'DSYRFS', -INFO )
268 * Quick return if possible
270 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
278 * NZ = maximum number of nonzero elements in each row of A, plus 1
281 EPS = DLAMCH( 'Epsilon' )
282 SAFMIN = DLAMCH( 'Safe minimum' )
286 * Do for each right hand side
294 * Loop until stopping criterion is satisfied.
296 * Compute residual R = B - A * X
298 CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
299 CALL DSYMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE,
302 * Compute componentwise relative backward error from formula
304 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
306 * where abs(Z) is the componentwise absolute value of the matrix
307 * or vector Z. If the i-th component of the denominator is less
308 * than SAFE2, then SAFE1 is added to the i-th components of the
309 * numerator and denominator before dividing.
312 WORK( I ) = ABS( B( I, J ) )
315 * Compute abs(A)*abs(X) + abs(B).
320 XK = ABS( X( K, J ) )
322 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
323 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
325 WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK + S
330 XK = ABS( X( K, J ) )
331 WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK
333 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
334 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
336 WORK( K ) = WORK( K ) + S
341 IF( WORK( I ).GT.SAFE2 ) THEN
342 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
344 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
345 $ ( WORK( I )+SAFE1 ) )
350 * Test stopping criterion. Continue iterating if
351 * 1) The residual BERR(J) is larger than machine epsilon, and
352 * 2) BERR(J) decreased by at least a factor of 2 during the
353 * last iteration, and
354 * 3) At most ITMAX iterations tried.
356 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
357 $ COUNT.LE.ITMAX ) THEN
359 * Update solution and try again.
361 CALL DSYTRS( UPLO, N, 1, AF, LDAF, IPIV, WORK( N+1 ), N,
363 CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
369 * Bound error from formula
371 * norm(X - XTRUE) / norm(X) .le. FERR =
373 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
376 * norm(Z) is the magnitude of the largest component of Z
377 * inv(A) is the inverse of A
378 * abs(Z) is the componentwise absolute value of the matrix or
380 * NZ is the maximum number of nonzeros in any row of A, plus 1
381 * EPS is machine epsilon
383 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
384 * is incremented by SAFE1 if the i-th component of
385 * abs(A)*abs(X) + abs(B) is less than SAFE2.
387 * Use DLACN2 to estimate the infinity-norm of the matrix
389 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
392 IF( WORK( I ).GT.SAFE2 ) THEN
393 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
395 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
401 CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
406 * Multiply by diag(W)*inv(A**T).
408 CALL DSYTRS( UPLO, N, 1, AF, LDAF, IPIV, WORK( N+1 ), N,
411 WORK( N+I ) = WORK( I )*WORK( N+I )
413 ELSE IF( KASE.EQ.2 ) THEN
415 * Multiply by inv(A)*diag(W).
418 WORK( N+I ) = WORK( I )*WORK( N+I )
420 CALL DSYTRS( UPLO, N, 1, AF, LDAF, IPIV, WORK( N+1 ), N,
430 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
433 $ FERR( J ) = FERR( J ) / LSTRES