LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zsyrfs.f
Go to the documentation of this file.
1*> \brief \b ZSYRFS
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download ZSYRFS + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsyrfs.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsyrfs.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsyrfs.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE ZSYRFS( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
20* X, LDX, FERR, BERR, WORK, RWORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER UPLO
24* INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
25* ..
26* .. Array Arguments ..
27* INTEGER IPIV( * )
28* DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
29* COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
30* $ WORK( * ), X( LDX, * )
31* ..
32*
33*
34*> \par Purpose:
35* =============
36*>
37*> \verbatim
38*>
39*> ZSYRFS improves the computed solution to a system of linear
40*> equations when the coefficient matrix is symmetric indefinite, and
41*> provides error bounds and backward error estimates for the solution.
42*> \endverbatim
43*
44* Arguments:
45* ==========
46*
47*> \param[in] UPLO
48*> \verbatim
49*> UPLO is CHARACTER*1
50*> = 'U': Upper triangle of A is stored;
51*> = 'L': Lower triangle of A is stored.
52*> \endverbatim
53*>
54*> \param[in] N
55*> \verbatim
56*> N is INTEGER
57*> The order of the matrix A. N >= 0.
58*> \endverbatim
59*>
60*> \param[in] NRHS
61*> \verbatim
62*> NRHS is INTEGER
63*> The number of right hand sides, i.e., the number of columns
64*> of the matrices B and X. NRHS >= 0.
65*> \endverbatim
66*>
67*> \param[in] A
68*> \verbatim
69*> A is COMPLEX*16 array, dimension (LDA,N)
70*> The symmetric matrix A. If UPLO = 'U', the leading N-by-N
71*> upper triangular part of A contains the upper triangular part
72*> of the matrix A, and the strictly lower triangular part of A
73*> is not referenced. If UPLO = 'L', the leading N-by-N lower
74*> triangular part of A contains the lower triangular part of
75*> the matrix A, and the strictly upper triangular part of A is
76*> not referenced.
77*> \endverbatim
78*>
79*> \param[in] LDA
80*> \verbatim
81*> LDA is INTEGER
82*> The leading dimension of the array A. LDA >= max(1,N).
83*> \endverbatim
84*>
85*> \param[in] AF
86*> \verbatim
87*> AF is COMPLEX*16 array, dimension (LDAF,N)
88*> The factored form of the matrix A. AF contains the block
89*> diagonal matrix D and the multipliers used to obtain the
90*> factor U or L from the factorization A = U*D*U**T or
91*> A = L*D*L**T as computed by ZSYTRF.
92*> \endverbatim
93*>
94*> \param[in] LDAF
95*> \verbatim
96*> LDAF is INTEGER
97*> The leading dimension of the array AF. LDAF >= max(1,N).
98*> \endverbatim
99*>
100*> \param[in] IPIV
101*> \verbatim
102*> IPIV is INTEGER array, dimension (N)
103*> Details of the interchanges and the block structure of D
104*> as determined by ZSYTRF.
105*> \endverbatim
106*>
107*> \param[in] B
108*> \verbatim
109*> B is COMPLEX*16 array, dimension (LDB,NRHS)
110*> The right hand side matrix B.
111*> \endverbatim
112*>
113*> \param[in] LDB
114*> \verbatim
115*> LDB is INTEGER
116*> The leading dimension of the array B. LDB >= max(1,N).
117*> \endverbatim
118*>
119*> \param[in,out] X
120*> \verbatim
121*> X is COMPLEX*16 array, dimension (LDX,NRHS)
122*> On entry, the solution matrix X, as computed by ZSYTRS.
123*> On exit, the improved solution matrix X.
124*> \endverbatim
125*>
126*> \param[in] LDX
127*> \verbatim
128*> LDX is INTEGER
129*> The leading dimension of the array X. LDX >= max(1,N).
130*> \endverbatim
131*>
132*> \param[out] FERR
133*> \verbatim
134*> FERR is DOUBLE PRECISION array, dimension (NRHS)
135*> The estimated forward error bound for each solution vector
136*> X(j) (the j-th column of the solution matrix X).
137*> If XTRUE is the true solution corresponding to X(j), FERR(j)
138*> is an estimated upper bound for the magnitude of the largest
139*> element in (X(j) - XTRUE) divided by the magnitude of the
140*> largest element in X(j). The estimate is as reliable as
141*> the estimate for RCOND, and is almost always a slight
142*> overestimate of the true error.
143*> \endverbatim
144*>
145*> \param[out] BERR
146*> \verbatim
147*> BERR is DOUBLE PRECISION array, dimension (NRHS)
148*> The componentwise relative backward error of each solution
149*> vector X(j) (i.e., the smallest relative change in
150*> any element of A or B that makes X(j) an exact solution).
151*> \endverbatim
152*>
153*> \param[out] WORK
154*> \verbatim
155*> WORK is COMPLEX*16 array, dimension (2*N)
156*> \endverbatim
157*>
158*> \param[out] RWORK
159*> \verbatim
160*> RWORK is DOUBLE PRECISION array, dimension (N)
161*> \endverbatim
162*>
163*> \param[out] INFO
164*> \verbatim
165*> INFO is INTEGER
166*> = 0: successful exit
167*> < 0: if INFO = -i, the i-th argument had an illegal value
168*> \endverbatim
169*
170*> \par Internal Parameters:
171* =========================
172*>
173*> \verbatim
174*> ITMAX is the maximum number of steps of iterative refinement.
175*> \endverbatim
176*
177* Authors:
178* ========
179*
180*> \author Univ. of Tennessee
181*> \author Univ. of California Berkeley
182*> \author Univ. of Colorado Denver
183*> \author NAG Ltd.
184*
185*> \ingroup herfs
186*
187* =====================================================================
188 SUBROUTINE zsyrfs( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B,
189 $ LDB,
190 $ X, LDX, FERR, BERR, WORK, RWORK, 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( * )
202 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
203 COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
204 $ work( * ), x( ldx, * )
205* ..
206*
207* =====================================================================
208*
209* .. Parameters ..
210 INTEGER ITMAX
211 PARAMETER ( ITMAX = 5 )
212 DOUBLE PRECISION ZERO
213 parameter( zero = 0.0d+0 )
214 COMPLEX*16 ONE
215 parameter( one = ( 1.0d+0, 0.0d+0 ) )
216 DOUBLE PRECISION TWO
217 parameter( two = 2.0d+0 )
218 DOUBLE PRECISION THREE
219 parameter( three = 3.0d+0 )
220* ..
221* .. Local Scalars ..
222 LOGICAL UPPER
223 INTEGER COUNT, I, J, K, KASE, NZ
224 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
225 COMPLEX*16 ZDUM
226* ..
227* .. Local Arrays ..
228 INTEGER ISAVE( 3 )
229* ..
230* .. External Subroutines ..
231 EXTERNAL xerbla, zaxpy, zcopy, zlacn2, zsymv,
232 $ zsytrs
233* ..
234* .. Intrinsic Functions ..
235 INTRINSIC abs, dble, dimag, max
236* ..
237* .. External Functions ..
238 LOGICAL LSAME
239 DOUBLE PRECISION DLAMCH
240 EXTERNAL lsame, dlamch
241* ..
242* .. Statement Functions ..
243 DOUBLE PRECISION CABS1
244* ..
245* .. Statement Function definitions ..
246 cabs1( zdum ) = abs( dble( zdum ) ) + abs( dimag( zdum ) )
247* ..
248* .. Executable Statements ..
249*
250* Test the input parameters.
251*
252 info = 0
253 upper = lsame( uplo, 'U' )
254 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
255 info = -1
256 ELSE IF( n.LT.0 ) THEN
257 info = -2
258 ELSE IF( nrhs.LT.0 ) THEN
259 info = -3
260 ELSE IF( lda.LT.max( 1, n ) ) THEN
261 info = -5
262 ELSE IF( ldaf.LT.max( 1, n ) ) THEN
263 info = -7
264 ELSE IF( ldb.LT.max( 1, n ) ) THEN
265 info = -10
266 ELSE IF( ldx.LT.max( 1, n ) ) THEN
267 info = -12
268 END IF
269 IF( info.NE.0 ) THEN
270 CALL xerbla( 'ZSYRFS', -info )
271 RETURN
272 END IF
273*
274* Quick return if possible
275*
276 IF( n.EQ.0 .OR. nrhs.EQ.0 ) THEN
277 DO 10 j = 1, nrhs
278 ferr( j ) = zero
279 berr( j ) = zero
280 10 CONTINUE
281 RETURN
282 END IF
283*
284* NZ = maximum number of nonzero elements in each row of A, plus 1
285*
286 nz = n + 1
287 eps = dlamch( 'Epsilon' )
288 safmin = dlamch( 'Safe minimum' )
289 safe1 = nz*safmin
290 safe2 = safe1 / eps
291*
292* Do for each right hand side
293*
294 DO 140 j = 1, nrhs
295*
296 count = 1
297 lstres = three
298 20 CONTINUE
299*
300* Loop until stopping criterion is satisfied.
301*
302* Compute residual R = B - A * X
303*
304 CALL zcopy( n, b( 1, j ), 1, work, 1 )
305 CALL zsymv( uplo, n, -one, a, lda, x( 1, j ), 1, one, work,
306 $ 1 )
307*
308* Compute componentwise relative backward error from formula
309*
310* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
311*
312* where abs(Z) is the componentwise absolute value of the matrix
313* or vector Z. If the i-th component of the denominator is less
314* than SAFE2, then SAFE1 is added to the i-th components of the
315* numerator and denominator before dividing.
316*
317 DO 30 i = 1, n
318 rwork( i ) = cabs1( b( i, j ) )
319 30 CONTINUE
320*
321* Compute abs(A)*abs(X) + abs(B).
322*
323 IF( upper ) THEN
324 DO 50 k = 1, n
325 s = zero
326 xk = cabs1( x( k, j ) )
327 DO 40 i = 1, k - 1
328 rwork( i ) = rwork( i ) + cabs1( a( i, k ) )*xk
329 s = s + cabs1( a( i, k ) )*cabs1( x( i, j ) )
330 40 CONTINUE
331 rwork( k ) = rwork( k ) + cabs1( a( k, k ) )*xk + s
332 50 CONTINUE
333 ELSE
334 DO 70 k = 1, n
335 s = zero
336 xk = cabs1( x( k, j ) )
337 rwork( k ) = rwork( k ) + cabs1( a( k, k ) )*xk
338 DO 60 i = k + 1, n
339 rwork( i ) = rwork( i ) + cabs1( a( i, k ) )*xk
340 s = s + cabs1( a( i, k ) )*cabs1( x( i, j ) )
341 60 CONTINUE
342 rwork( k ) = rwork( k ) + s
343 70 CONTINUE
344 END IF
345 s = zero
346 DO 80 i = 1, n
347 IF( rwork( i ).GT.safe2 ) THEN
348 s = max( s, cabs1( work( i ) ) / rwork( i ) )
349 ELSE
350 s = max( s, ( cabs1( work( i ) )+safe1 ) /
351 $ ( rwork( i )+safe1 ) )
352 END IF
353 80 CONTINUE
354 berr( j ) = s
355*
356* Test stopping criterion. Continue iterating if
357* 1) The residual BERR(J) is larger than machine epsilon, and
358* 2) BERR(J) decreased by at least a factor of 2 during the
359* last iteration, and
360* 3) At most ITMAX iterations tried.
361*
362 IF( berr( j ).GT.eps .AND. two*berr( j ).LE.lstres .AND.
363 $ count.LE.itmax ) THEN
364*
365* Update solution and try again.
366*
367 CALL zsytrs( uplo, n, 1, af, ldaf, ipiv, work, n, info )
368 CALL zaxpy( n, one, work, 1, x( 1, j ), 1 )
369 lstres = berr( j )
370 count = count + 1
371 GO TO 20
372 END IF
373*
374* Bound error from formula
375*
376* norm(X - XTRUE) / norm(X) .le. FERR =
377* norm( abs(inv(A))*
378* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
379*
380* where
381* norm(Z) is the magnitude of the largest component of Z
382* inv(A) is the inverse of A
383* abs(Z) is the componentwise absolute value of the matrix or
384* vector Z
385* NZ is the maximum number of nonzeros in any row of A, plus 1
386* EPS is machine epsilon
387*
388* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
389* is incremented by SAFE1 if the i-th component of
390* abs(A)*abs(X) + abs(B) is less than SAFE2.
391*
392* Use ZLACN2 to estimate the infinity-norm of the matrix
393* inv(A) * diag(W),
394* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
395*
396 DO 90 i = 1, n
397 IF( rwork( i ).GT.safe2 ) THEN
398 rwork( i ) = cabs1( work( i ) ) + nz*eps*rwork( i )
399 ELSE
400 rwork( i ) = cabs1( work( i ) ) + nz*eps*rwork( i ) +
401 $ safe1
402 END IF
403 90 CONTINUE
404*
405 kase = 0
406 100 CONTINUE
407 CALL zlacn2( n, work( n+1 ), work, ferr( j ), kase, isave )
408 IF( kase.NE.0 ) THEN
409 IF( kase.EQ.1 ) THEN
410*
411* Multiply by diag(W)*inv(A**T).
412*
413 CALL zsytrs( uplo, n, 1, af, ldaf, ipiv, work, n,
414 $ info )
415 DO 110 i = 1, n
416 work( i ) = rwork( i )*work( i )
417 110 CONTINUE
418 ELSE IF( kase.EQ.2 ) THEN
419*
420* Multiply by inv(A)*diag(W).
421*
422 DO 120 i = 1, n
423 work( i ) = rwork( i )*work( i )
424 120 CONTINUE
425 CALL zsytrs( uplo, n, 1, af, ldaf, ipiv, work, n,
426 $ info )
427 END IF
428 GO TO 100
429 END IF
430*
431* Normalize error.
432*
433 lstres = zero
434 DO 130 i = 1, n
435 lstres = max( lstres, cabs1( x( i, j ) ) )
436 130 CONTINUE
437 IF( lstres.NE.zero )
438 $ ferr( j ) = ferr( j ) / lstres
439*
440 140 CONTINUE
441*
442 RETURN
443*
444* End of ZSYRFS
445*
446 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine zaxpy(n, za, zx, incx, zy, incy)
ZAXPY
Definition zaxpy.f:88
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
Definition zcopy.f:81
subroutine zsymv(uplo, n, alpha, a, lda, x, incx, beta, y, incy)
ZSYMV computes a matrix-vector product for a complex symmetric matrix.
Definition zsymv.f:156
subroutine zsyrfs(uplo, n, nrhs, a, lda, af, ldaf, ipiv, b, ldb, x, ldx, ferr, berr, work, rwork, info)
ZSYRFS
Definition zsyrfs.f:191
subroutine zsytrs(uplo, n, nrhs, a, lda, ipiv, b, ldb, info)
ZSYTRS
Definition zsytrs.f:118
subroutine zlacn2(n, v, x, est, kase, isave)
ZLACN2 estimates the 1-norm of a square matrix, using reverse communication for evaluating matrix-vec...
Definition zlacn2.f:131