1: *> \brief \b DSYRFS
2: *
3: * =========== DOCUMENTATION ===========
4: *
5: * Online html documentation available at
6: * http://www.netlib.org/lapack/explore-html/
7: *
8: *> \htmlonly
9: *> Download DSYRFS + dependencies
10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsyrfs.f">
11: *> [TGZ]</a>
12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsyrfs.f">
13: *> [ZIP]</a>
14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsyrfs.f">
15: *> [TXT]</a>
16: *> \endhtmlonly
17: *
18: * Definition:
19: * ===========
20: *
21: * SUBROUTINE DSYRFS( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
22: * X, LDX, FERR, BERR, WORK, IWORK, INFO )
23: *
24: * .. Scalar Arguments ..
25: * CHARACTER UPLO
26: * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
27: * ..
28: * .. Array Arguments ..
29: * INTEGER IPIV( * ), IWORK( * )
30: * DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
31: * $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
32: * ..
33: *
34: *
35: *> \par Purpose:
36: * =============
37: *>
38: *> \verbatim
39: *>
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.
43: *> \endverbatim
44: *
45: * Arguments:
46: * ==========
47: *
48: *> \param[in] UPLO
49: *> \verbatim
50: *> UPLO is CHARACTER*1
51: *> = 'U': Upper triangle of A is stored;
52: *> = 'L': Lower triangle of A is stored.
53: *> \endverbatim
54: *>
55: *> \param[in] N
56: *> \verbatim
57: *> N is INTEGER
58: *> The order of the matrix A. N >= 0.
59: *> \endverbatim
60: *>
61: *> \param[in] NRHS
62: *> \verbatim
63: *> NRHS is INTEGER
64: *> The number of right hand sides, i.e., the number of columns
65: *> of the matrices B and X. NRHS >= 0.
66: *> \endverbatim
67: *>
68: *> \param[in] A
69: *> \verbatim
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
77: *> not referenced.
78: *> \endverbatim
79: *>
80: *> \param[in] LDA
81: *> \verbatim
82: *> LDA is INTEGER
83: *> The leading dimension of the array A. LDA >= max(1,N).
84: *> \endverbatim
85: *>
86: *> \param[in] AF
87: *> \verbatim
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.
93: *> \endverbatim
94: *>
95: *> \param[in] LDAF
96: *> \verbatim
97: *> LDAF is INTEGER
98: *> The leading dimension of the array AF. LDAF >= max(1,N).
99: *> \endverbatim
100: *>
101: *> \param[in] IPIV
102: *> \verbatim
103: *> IPIV is INTEGER array, dimension (N)
104: *> Details of the interchanges and the block structure of D
105: *> as determined by DSYTRF.
106: *> \endverbatim
107: *>
108: *> \param[in] B
109: *> \verbatim
110: *> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
111: *> The right hand side matrix B.
112: *> \endverbatim
113: *>
114: *> \param[in] LDB
115: *> \verbatim
116: *> LDB is INTEGER
117: *> The leading dimension of the array B. LDB >= max(1,N).
118: *> \endverbatim
119: *>
120: *> \param[in,out] X
121: *> \verbatim
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.
125: *> \endverbatim
126: *>
127: *> \param[in] LDX
128: *> \verbatim
129: *> LDX is INTEGER
130: *> The leading dimension of the array X. LDX >= max(1,N).
131: *> \endverbatim
132: *>
133: *> \param[out] FERR
134: *> \verbatim
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.
144: *> \endverbatim
145: *>
146: *> \param[out] BERR
147: *> \verbatim
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).
152: *> \endverbatim
153: *>
154: *> \param[out] WORK
155: *> \verbatim
156: *> WORK is DOUBLE PRECISION array, dimension (3*N)
157: *> \endverbatim
158: *>
159: *> \param[out] IWORK
160: *> \verbatim
161: *> IWORK is INTEGER array, dimension (N)
162: *> \endverbatim
163: *>
164: *> \param[out] INFO
165: *> \verbatim
166: *> INFO is INTEGER
167: *> = 0: successful exit
168: *> < 0: if INFO = -i, the i-th argument had an illegal value
169: *> \endverbatim
170: *
171: *> \par Internal Parameters:
172: * =========================
173: *>
174: *> \verbatim
175: *> ITMAX is the maximum number of steps of iterative refinement.
176: *> \endverbatim
177: *
178: * Authors:
179: * ========
180: *
181: *> \author Univ. of Tennessee
182: *> \author Univ. of California Berkeley
183: *> \author Univ. of Colorado Denver
184: *> \author NAG Ltd.
185: *
186: *> \ingroup doubleSYcomputational
187: *
188: * =====================================================================
189: SUBROUTINE DSYRFS( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
190: $ X, LDX, FERR, BERR, WORK, IWORK, INFO )
191: *
192: * -- LAPACK computational routine --
193: * -- LAPACK is a software package provided by Univ. of Tennessee, --
194: * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
195: *
196: * .. Scalar Arguments ..
197: CHARACTER UPLO
198: INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
199: * ..
200: * .. Array Arguments ..
201: INTEGER IPIV( * ), IWORK( * )
202: DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
203: $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
204: * ..
205: *
206: * =====================================================================
207: *
208: * .. Parameters ..
209: INTEGER ITMAX
210: PARAMETER ( ITMAX = 5 )
211: DOUBLE PRECISION ZERO
212: PARAMETER ( ZERO = 0.0D+0 )
213: DOUBLE PRECISION ONE
214: PARAMETER ( ONE = 1.0D+0 )
215: DOUBLE PRECISION TWO
216: PARAMETER ( TWO = 2.0D+0 )
217: DOUBLE PRECISION THREE
218: PARAMETER ( THREE = 3.0D+0 )
219: * ..
220: * .. Local Scalars ..
221: LOGICAL UPPER
222: INTEGER COUNT, I, J, K, KASE, NZ
223: DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
224: * ..
225: * .. Local Arrays ..
226: INTEGER ISAVE( 3 )
227: * ..
228: * .. External Subroutines ..
229: EXTERNAL DAXPY, DCOPY, DLACN2, DSYMV, DSYTRS, XERBLA
230: * ..
231: * .. Intrinsic Functions ..
232: INTRINSIC ABS, MAX
233: * ..
234: * .. External Functions ..
235: LOGICAL LSAME
236: DOUBLE PRECISION DLAMCH
237: EXTERNAL LSAME, DLAMCH
238: * ..
239: * .. Executable Statements ..
240: *
241: * Test the input parameters.
242: *
243: INFO = 0
244: UPPER = LSAME( UPLO, 'U' )
245: IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
246: INFO = -1
247: ELSE IF( N.LT.0 ) THEN
248: INFO = -2
249: ELSE IF( NRHS.LT.0 ) THEN
250: INFO = -3
251: ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
252: INFO = -5
253: ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
254: INFO = -7
255: ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
256: INFO = -10
257: ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
258: INFO = -12
259: END IF
260: IF( INFO.NE.0 ) THEN
261: CALL XERBLA( 'DSYRFS', -INFO )
262: RETURN
263: END IF
264: *
265: * Quick return if possible
266: *
267: IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
268: DO 10 J = 1, NRHS
269: FERR( J ) = ZERO
270: BERR( J ) = ZERO
271: 10 CONTINUE
272: RETURN
273: END IF
274: *
275: * NZ = maximum number of nonzero elements in each row of A, plus 1
276: *
277: NZ = N + 1
278: EPS = DLAMCH( 'Epsilon' )
279: SAFMIN = DLAMCH( 'Safe minimum' )
280: SAFE1 = NZ*SAFMIN
281: SAFE2 = SAFE1 / EPS
282: *
283: * Do for each right hand side
284: *
285: DO 140 J = 1, NRHS
286: *
287: COUNT = 1
288: LSTRES = THREE
289: 20 CONTINUE
290: *
291: * Loop until stopping criterion is satisfied.
292: *
293: * Compute residual R = B - A * X
294: *
295: CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
296: CALL DSYMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE,
297: $ WORK( N+1 ), 1 )
298: *
299: * Compute componentwise relative backward error from formula
300: *
301: * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
302: *
303: * where abs(Z) is the componentwise absolute value of the matrix
304: * or vector Z. If the i-th component of the denominator is less
305: * than SAFE2, then SAFE1 is added to the i-th components of the
306: * numerator and denominator before dividing.
307: *
308: DO 30 I = 1, N
309: WORK( I ) = ABS( B( I, J ) )
310: 30 CONTINUE
311: *
312: * Compute abs(A)*abs(X) + abs(B).
313: *
314: IF( UPPER ) THEN
315: DO 50 K = 1, N
316: S = ZERO
317: XK = ABS( X( K, J ) )
318: DO 40 I = 1, K - 1
319: WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
320: S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
321: 40 CONTINUE
322: WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK + S
323: 50 CONTINUE
324: ELSE
325: DO 70 K = 1, N
326: S = ZERO
327: XK = ABS( X( K, J ) )
328: WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK
329: DO 60 I = K + 1, N
330: WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
331: S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
332: 60 CONTINUE
333: WORK( K ) = WORK( K ) + S
334: 70 CONTINUE
335: END IF
336: S = ZERO
337: DO 80 I = 1, N
338: IF( WORK( I ).GT.SAFE2 ) THEN
339: S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
340: ELSE
341: S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
342: $ ( WORK( I )+SAFE1 ) )
343: END IF
344: 80 CONTINUE
345: BERR( J ) = S
346: *
347: * Test stopping criterion. Continue iterating if
348: * 1) The residual BERR(J) is larger than machine epsilon, and
349: * 2) BERR(J) decreased by at least a factor of 2 during the
350: * last iteration, and
351: * 3) At most ITMAX iterations tried.
352: *
353: IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
354: $ COUNT.LE.ITMAX ) THEN
355: *
356: * Update solution and try again.
357: *
358: CALL DSYTRS( UPLO, N, 1, AF, LDAF, IPIV, WORK( N+1 ), N,
359: $ INFO )
360: CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
361: LSTRES = BERR( J )
362: COUNT = COUNT + 1
363: GO TO 20
364: END IF
365: *
366: * Bound error from formula
367: *
368: * norm(X - XTRUE) / norm(X) .le. FERR =
369: * norm( abs(inv(A))*
370: * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
371: *
372: * where
373: * norm(Z) is the magnitude of the largest component of Z
374: * inv(A) is the inverse of A
375: * abs(Z) is the componentwise absolute value of the matrix or
376: * vector Z
377: * NZ is the maximum number of nonzeros in any row of A, plus 1
378: * EPS is machine epsilon
379: *
380: * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
381: * is incremented by SAFE1 if the i-th component of
382: * abs(A)*abs(X) + abs(B) is less than SAFE2.
383: *
384: * Use DLACN2 to estimate the infinity-norm of the matrix
385: * inv(A) * diag(W),
386: * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
387: *
388: DO 90 I = 1, N
389: IF( WORK( I ).GT.SAFE2 ) THEN
390: WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
391: ELSE
392: WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
393: END IF
394: 90 CONTINUE
395: *
396: KASE = 0
397: 100 CONTINUE
398: CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
399: $ KASE, ISAVE )
400: IF( KASE.NE.0 ) THEN
401: IF( KASE.EQ.1 ) THEN
402: *
403: * Multiply by diag(W)*inv(A**T).
404: *
405: CALL DSYTRS( UPLO, N, 1, AF, LDAF, IPIV, WORK( N+1 ), N,
406: $ INFO )
407: DO 110 I = 1, N
408: WORK( N+I ) = WORK( I )*WORK( N+I )
409: 110 CONTINUE
410: ELSE IF( KASE.EQ.2 ) THEN
411: *
412: * Multiply by inv(A)*diag(W).
413: *
414: DO 120 I = 1, N
415: WORK( N+I ) = WORK( I )*WORK( N+I )
416: 120 CONTINUE
417: CALL DSYTRS( UPLO, N, 1, AF, LDAF, IPIV, WORK( N+1 ), N,
418: $ INFO )
419: END IF
420: GO TO 100
421: END IF
422: *
423: * Normalize error.
424: *
425: LSTRES = ZERO
426: DO 130 I = 1, N
427: LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
428: 130 CONTINUE
429: IF( LSTRES.NE.ZERO )
430: $ FERR( J ) = FERR( J ) / LSTRES
431: *
432: 140 CONTINUE
433: *
434: RETURN
435: *
436: * End of DSYRFS
437: *
438: END
CVSweb interface <joel.bertrand@systella.fr>