LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zgerfs.f
Go to the documentation of this file.
1*> \brief \b ZGERFS
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download ZGERFS + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgerfs.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgerfs.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgerfs.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE ZGERFS( TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
20* X, LDX, FERR, BERR, WORK, RWORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER TRANS
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*> ZGERFS improves the computed solution to a system of linear
40*> equations and provides error bounds and backward error estimates for
41*> the solution.
42*> \endverbatim
43*
44* Arguments:
45* ==========
46*
47*> \param[in] TRANS
48*> \verbatim
49*> TRANS is CHARACTER*1
50*> Specifies the form of the system of equations:
51*> = 'N': A * X = B (No transpose)
52*> = 'T': A**T * X = B (Transpose)
53*> = 'C': A**H * X = B (Conjugate transpose)
54*> \endverbatim
55*>
56*> \param[in] N
57*> \verbatim
58*> N is INTEGER
59*> The order of the matrix A. N >= 0.
60*> \endverbatim
61*>
62*> \param[in] NRHS
63*> \verbatim
64*> NRHS is INTEGER
65*> The number of right hand sides, i.e., the number of columns
66*> of the matrices B and X. NRHS >= 0.
67*> \endverbatim
68*>
69*> \param[in] A
70*> \verbatim
71*> A is COMPLEX*16 array, dimension (LDA,N)
72*> The original N-by-N matrix A.
73*> \endverbatim
74*>
75*> \param[in] LDA
76*> \verbatim
77*> LDA is INTEGER
78*> The leading dimension of the array A. LDA >= max(1,N).
79*> \endverbatim
80*>
81*> \param[in] AF
82*> \verbatim
83*> AF is COMPLEX*16 array, dimension (LDAF,N)
84*> The factors L and U from the factorization A = P*L*U
85*> as computed by ZGETRF.
86*> \endverbatim
87*>
88*> \param[in] LDAF
89*> \verbatim
90*> LDAF is INTEGER
91*> The leading dimension of the array AF. LDAF >= max(1,N).
92*> \endverbatim
93*>
94*> \param[in] IPIV
95*> \verbatim
96*> IPIV is INTEGER array, dimension (N)
97*> The pivot indices from ZGETRF; for 1<=i<=N, row i of the
98*> matrix was interchanged with row IPIV(i).
99*> \endverbatim
100*>
101*> \param[in] B
102*> \verbatim
103*> B is COMPLEX*16 array, dimension (LDB,NRHS)
104*> The right hand side matrix B.
105*> \endverbatim
106*>
107*> \param[in] LDB
108*> \verbatim
109*> LDB is INTEGER
110*> The leading dimension of the array B. LDB >= max(1,N).
111*> \endverbatim
112*>
113*> \param[in,out] X
114*> \verbatim
115*> X is COMPLEX*16 array, dimension (LDX,NRHS)
116*> On entry, the solution matrix X, as computed by ZGETRS.
117*> On exit, the improved solution matrix X.
118*> \endverbatim
119*>
120*> \param[in] LDX
121*> \verbatim
122*> LDX is INTEGER
123*> The leading dimension of the array X. LDX >= max(1,N).
124*> \endverbatim
125*>
126*> \param[out] FERR
127*> \verbatim
128*> FERR is DOUBLE PRECISION array, dimension (NRHS)
129*> The estimated forward error bound for each solution vector
130*> X(j) (the j-th column of the solution matrix X).
131*> If XTRUE is the true solution corresponding to X(j), FERR(j)
132*> is an estimated upper bound for the magnitude of the largest
133*> element in (X(j) - XTRUE) divided by the magnitude of the
134*> largest element in X(j). The estimate is as reliable as
135*> the estimate for RCOND, and is almost always a slight
136*> overestimate of the true error.
137*> \endverbatim
138*>
139*> \param[out] BERR
140*> \verbatim
141*> BERR is DOUBLE PRECISION array, dimension (NRHS)
142*> The componentwise relative backward error of each solution
143*> vector X(j) (i.e., the smallest relative change in
144*> any element of A or B that makes X(j) an exact solution).
145*> \endverbatim
146*>
147*> \param[out] WORK
148*> \verbatim
149*> WORK is COMPLEX*16 array, dimension (2*N)
150*> \endverbatim
151*>
152*> \param[out] RWORK
153*> \verbatim
154*> RWORK is DOUBLE PRECISION array, dimension (N)
155*> \endverbatim
156*>
157*> \param[out] INFO
158*> \verbatim
159*> INFO is INTEGER
160*> = 0: successful exit
161*> < 0: if INFO = -i, the i-th argument had an illegal value
162*> \endverbatim
163*
164*> \par Internal Parameters:
165* =========================
166*>
167*> \verbatim
168*> ITMAX is the maximum number of steps of iterative refinement.
169*> \endverbatim
170*
171* Authors:
172* ========
173*
174*> \author Univ. of Tennessee
175*> \author Univ. of California Berkeley
176*> \author Univ. of Colorado Denver
177*> \author NAG Ltd.
178*
179*> \ingroup gerfs
180*
181* =====================================================================
182 SUBROUTINE zgerfs( TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, B,
183 $ LDB,
184 $ X, LDX, FERR, BERR, WORK, RWORK, INFO )
185*
186* -- LAPACK computational routine --
187* -- LAPACK is a software package provided by Univ. of Tennessee, --
188* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
189*
190* .. Scalar Arguments ..
191 CHARACTER TRANS
192 INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
193* ..
194* .. Array Arguments ..
195 INTEGER IPIV( * )
196 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
197 COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
198 $ work( * ), x( ldx, * )
199* ..
200*
201* =====================================================================
202*
203* .. Parameters ..
204 INTEGER ITMAX
205 PARAMETER ( ITMAX = 5 )
206 DOUBLE PRECISION ZERO
207 parameter( zero = 0.0d+0 )
208 COMPLEX*16 ONE
209 parameter( one = ( 1.0d+0, 0.0d+0 ) )
210 DOUBLE PRECISION TWO
211 parameter( two = 2.0d+0 )
212 DOUBLE PRECISION THREE
213 parameter( three = 3.0d+0 )
214* ..
215* .. Local Scalars ..
216 LOGICAL NOTRAN
217 CHARACTER TRANSN, TRANST
218 INTEGER COUNT, I, J, K, KASE, NZ
219 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
220 COMPLEX*16 ZDUM
221* ..
222* .. Local Arrays ..
223 INTEGER ISAVE( 3 )
224* ..
225* .. External Functions ..
226 LOGICAL LSAME
227 DOUBLE PRECISION DLAMCH
228 EXTERNAL lsame, dlamch
229* ..
230* .. External Subroutines ..
231 EXTERNAL xerbla, zaxpy, zcopy, zgemv, zgetrs,
232 $ zlacn2
233* ..
234* .. Intrinsic Functions ..
235 INTRINSIC abs, dble, dimag, max
236* ..
237* .. Statement Functions ..
238 DOUBLE PRECISION CABS1
239* ..
240* .. Statement Function definitions ..
241 cabs1( zdum ) = abs( dble( zdum ) ) + abs( dimag( zdum ) )
242* ..
243* .. Executable Statements ..
244*
245* Test the input parameters.
246*
247 info = 0
248 notran = lsame( trans, 'N' )
249 IF( .NOT.notran .AND. .NOT.lsame( trans, 'T' ) .AND. .NOT.
250 $ lsame( trans, 'C' ) ) THEN
251 info = -1
252 ELSE IF( n.LT.0 ) THEN
253 info = -2
254 ELSE IF( nrhs.LT.0 ) THEN
255 info = -3
256 ELSE IF( lda.LT.max( 1, n ) ) THEN
257 info = -5
258 ELSE IF( ldaf.LT.max( 1, n ) ) THEN
259 info = -7
260 ELSE IF( ldb.LT.max( 1, n ) ) THEN
261 info = -10
262 ELSE IF( ldx.LT.max( 1, n ) ) THEN
263 info = -12
264 END IF
265 IF( info.NE.0 ) THEN
266 CALL xerbla( 'ZGERFS', -info )
267 RETURN
268 END IF
269*
270* Quick return if possible
271*
272 IF( n.EQ.0 .OR. nrhs.EQ.0 ) THEN
273 DO 10 j = 1, nrhs
274 ferr( j ) = zero
275 berr( j ) = zero
276 10 CONTINUE
277 RETURN
278 END IF
279*
280 IF( notran ) THEN
281 transn = 'N'
282 transt = 'C'
283 ELSE
284 transn = 'C'
285 transt = 'N'
286 END IF
287*
288* NZ = maximum number of nonzero elements in each row of A, plus 1
289*
290 nz = n + 1
291 eps = dlamch( 'Epsilon' )
292 safmin = dlamch( 'Safe minimum' )
293 safe1 = nz*safmin
294 safe2 = safe1 / eps
295*
296* Do for each right hand side
297*
298 DO 140 j = 1, nrhs
299*
300 count = 1
301 lstres = three
302 20 CONTINUE
303*
304* Loop until stopping criterion is satisfied.
305*
306* Compute residual R = B - op(A) * X,
307* where op(A) = A, A**T, or A**H, depending on TRANS.
308*
309 CALL zcopy( n, b( 1, j ), 1, work, 1 )
310 CALL zgemv( trans, n, n, -one, a, lda, x( 1, j ), 1, one,
311 $ work,
312 $ 1 )
313*
314* Compute componentwise relative backward error from formula
315*
316* max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
317*
318* where abs(Z) is the componentwise absolute value of the matrix
319* or vector Z. If the i-th component of the denominator is less
320* than SAFE2, then SAFE1 is added to the i-th components of the
321* numerator and denominator before dividing.
322*
323 DO 30 i = 1, n
324 rwork( i ) = cabs1( b( i, j ) )
325 30 CONTINUE
326*
327* Compute abs(op(A))*abs(X) + abs(B).
328*
329 IF( notran ) THEN
330 DO 50 k = 1, n
331 xk = cabs1( x( k, j ) )
332 DO 40 i = 1, n
333 rwork( i ) = rwork( i ) + cabs1( a( i, k ) )*xk
334 40 CONTINUE
335 50 CONTINUE
336 ELSE
337 DO 70 k = 1, n
338 s = zero
339 DO 60 i = 1, n
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 zgetrs( trans, 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(op(A)))*
378* ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
379*
380* where
381* norm(Z) is the magnitude of the largest component of Z
382* inv(op(A)) is the inverse of op(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(op(A))*abs(X)+abs(B))
389* is incremented by SAFE1 if the i-th component of
390* abs(op(A))*abs(X) + abs(B) is less than SAFE2.
391*
392* Use ZLACN2 to estimate the infinity-norm of the matrix
393* inv(op(A)) * diag(W),
394* where W = abs(R) + NZ*EPS*( abs(op(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(op(A)**H).
412*
413 CALL zgetrs( transt, 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
419*
420* Multiply by inv(op(A))*diag(W).
421*
422 DO 120 i = 1, n
423 work( i ) = rwork( i )*work( i )
424 120 CONTINUE
425 CALL zgetrs( transn, 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 ZGERFS
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 zgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
ZGEMV
Definition zgemv.f:160
subroutine zgerfs(trans, n, nrhs, a, lda, af, ldaf, ipiv, b, ldb, x, ldx, ferr, berr, work, rwork, info)
ZGERFS
Definition zgerfs.f:185
subroutine zgetrs(trans, n, nrhs, a, lda, ipiv, b, ldb, info)
ZGETRS
Definition zgetrs.f:119
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