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