3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZGBRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgbrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgbrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgbrfs.f">
21 * SUBROUTINE ZGBRFS( TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, LDAFB,
22 * IPIV, B, LDB, X, LDX, FERR, BERR, WORK, RWORK,
25 * .. Scalar Arguments ..
27 * INTEGER INFO, KL, KU, LDAB, LDAFB, LDB, LDX, N, NRHS
29 * .. Array Arguments ..
31 * DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
32 * COMPLEX*16 AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
33 * $ WORK( * ), X( LDX, * )
42 *> ZGBRFS improves the computed solution to a system of linear
43 *> equations when the coefficient matrix is banded, and provides
44 *> error bounds and backward error estimates for the solution.
52 *> TRANS is CHARACTER*1
53 *> Specifies the form of the system of equations:
54 *> = 'N': A * X = B (No transpose)
55 *> = 'T': A**T * X = B (Transpose)
56 *> = 'C': A**H * X = B (Conjugate transpose)
62 *> The order of the matrix A. N >= 0.
68 *> The number of subdiagonals within the band of A. KL >= 0.
74 *> The number of superdiagonals within the band of A. KU >= 0.
80 *> The number of right hand sides, i.e., the number of columns
81 *> of the matrices B and X. NRHS >= 0.
86 *> AB is COMPLEX*16 array, dimension (LDAB,N)
87 *> The original band matrix A, stored in rows 1 to KL+KU+1.
88 *> The j-th column of A is stored in the j-th column of the
89 *> array AB as follows:
90 *> AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl).
96 *> The leading dimension of the array AB. LDAB >= KL+KU+1.
101 *> AFB is COMPLEX*16 array, dimension (LDAFB,N)
102 *> Details of the LU factorization of the band matrix A, as
103 *> computed by ZGBTRF. U is stored as an upper triangular band
104 *> matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and
105 *> the multipliers used during the factorization are stored in
106 *> rows KL+KU+2 to 2*KL+KU+1.
112 *> The leading dimension of the array AFB. LDAFB >= 2*KL*KU+1.
117 *> IPIV is INTEGER array, dimension (N)
118 *> The pivot indices from ZGBTRF; for 1<=i<=N, row i of the
119 *> matrix was interchanged with row IPIV(i).
124 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
125 *> The right hand side matrix B.
131 *> The leading dimension of the array B. LDB >= max(1,N).
136 *> X is COMPLEX*16 array, dimension (LDX,NRHS)
137 *> On entry, the solution matrix X, as computed by ZGBTRS.
138 *> On exit, the improved solution matrix X.
144 *> The leading dimension of the array X. LDX >= max(1,N).
149 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
150 *> The estimated forward error bound for each solution vector
151 *> X(j) (the j-th column of the solution matrix X).
152 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
153 *> is an estimated upper bound for the magnitude of the largest
154 *> element in (X(j) - XTRUE) divided by the magnitude of the
155 *> largest element in X(j). The estimate is as reliable as
156 *> the estimate for RCOND, and is almost always a slight
157 *> overestimate of the true error.
162 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
163 *> The componentwise relative backward error of each solution
164 *> vector X(j) (i.e., the smallest relative change in
165 *> any element of A or B that makes X(j) an exact solution).
170 *> WORK is COMPLEX*16 array, dimension (2*N)
175 *> RWORK is DOUBLE PRECISION array, dimension (N)
181 *> = 0: successful exit
182 *> < 0: if INFO = -i, the i-th argument had an illegal value
185 *> \par Internal Parameters:
186 * =========================
189 *> ITMAX is the maximum number of steps of iterative refinement.
195 *> \author Univ. of Tennessee
196 *> \author Univ. of California Berkeley
197 *> \author Univ. of Colorado Denver
200 *> \date November 2011
202 *> \ingroup complex16GBcomputational
204 * =====================================================================
205 SUBROUTINE ZGBRFS( TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, LDAFB,
206 $ IPIV, B, LDB, X, LDX, FERR, BERR, WORK, RWORK,
209 * -- LAPACK computational routine (version 3.4.0) --
210 * -- LAPACK is a software package provided by Univ. of Tennessee, --
211 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
214 * .. Scalar Arguments ..
216 INTEGER INFO, KL, KU, LDAB, LDAFB, LDB, LDX, N, NRHS
218 * .. Array Arguments ..
220 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
221 COMPLEX*16 AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
222 $ WORK( * ), X( LDX, * )
225 * =====================================================================
229 PARAMETER ( ITMAX = 5 )
230 DOUBLE PRECISION ZERO
231 PARAMETER ( ZERO = 0.0D+0 )
233 PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ) )
235 PARAMETER ( TWO = 2.0D+0 )
236 DOUBLE PRECISION THREE
237 PARAMETER ( THREE = 3.0D+0 )
239 * .. Local Scalars ..
241 CHARACTER TRANSN, TRANST
242 INTEGER COUNT, I, J, K, KASE, KK, NZ
243 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
249 * .. External Subroutines ..
250 EXTERNAL XERBLA, ZAXPY, ZCOPY, ZGBMV, ZGBTRS, ZLACN2
252 * .. Intrinsic Functions ..
253 INTRINSIC ABS, DBLE, DIMAG, MAX, MIN
255 * .. External Functions ..
257 DOUBLE PRECISION DLAMCH
258 EXTERNAL LSAME, DLAMCH
260 * .. Statement Functions ..
261 DOUBLE PRECISION CABS1
263 * .. Statement Function definitions ..
264 CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
266 * .. Executable Statements ..
268 * Test the input parameters.
271 NOTRAN = LSAME( TRANS, 'N' )
272 IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
273 $ LSAME( TRANS, 'C' ) ) THEN
275 ELSE IF( N.LT.0 ) THEN
277 ELSE IF( KL.LT.0 ) THEN
279 ELSE IF( KU.LT.0 ) THEN
281 ELSE IF( NRHS.LT.0 ) THEN
283 ELSE IF( LDAB.LT.KL+KU+1 ) THEN
285 ELSE IF( LDAFB.LT.2*KL+KU+1 ) THEN
287 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
289 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
293 CALL XERBLA( 'ZGBRFS', -INFO )
297 * Quick return if possible
299 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
315 * NZ = maximum number of nonzero elements in each row of A, plus 1
317 NZ = MIN( KL+KU+2, N+1 )
318 EPS = DLAMCH( 'Epsilon' )
319 SAFMIN = DLAMCH( 'Safe minimum' )
323 * Do for each right hand side
331 * Loop until stopping criterion is satisfied.
333 * Compute residual R = B - op(A) * X,
334 * where op(A) = A, A**T, or A**H, depending on TRANS.
336 CALL ZCOPY( N, B( 1, J ), 1, WORK, 1 )
337 CALL ZGBMV( TRANS, N, N, KL, KU, -CONE, AB, LDAB, X( 1, J ), 1,
340 * Compute componentwise relative backward error from formula
342 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
344 * where abs(Z) is the componentwise absolute value of the matrix
345 * or vector Z. If the i-th component of the denominator is less
346 * than SAFE2, then SAFE1 is added to the i-th components of the
347 * numerator and denominator before dividing.
350 RWORK( I ) = CABS1( B( I, J ) )
353 * Compute abs(op(A))*abs(X) + abs(B).
358 XK = CABS1( X( K, J ) )
359 DO 40 I = MAX( 1, K-KU ), MIN( N, K+KL )
360 RWORK( I ) = RWORK( I ) + CABS1( AB( KK+I, K ) )*XK
367 DO 60 I = MAX( 1, K-KU ), MIN( N, K+KL )
368 S = S + CABS1( AB( KK+I, K ) )*CABS1( X( I, J ) )
370 RWORK( K ) = RWORK( K ) + S
375 IF( RWORK( I ).GT.SAFE2 ) THEN
376 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
378 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
379 $ ( RWORK( I )+SAFE1 ) )
384 * Test stopping criterion. Continue iterating if
385 * 1) The residual BERR(J) is larger than machine epsilon, and
386 * 2) BERR(J) decreased by at least a factor of 2 during the
387 * last iteration, and
388 * 3) At most ITMAX iterations tried.
390 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
391 $ COUNT.LE.ITMAX ) THEN
393 * Update solution and try again.
395 CALL ZGBTRS( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV, WORK, N,
397 CALL ZAXPY( N, CONE, WORK, 1, X( 1, J ), 1 )
403 * Bound error from formula
405 * norm(X - XTRUE) / norm(X) .le. FERR =
406 * norm( abs(inv(op(A)))*
407 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
410 * norm(Z) is the magnitude of the largest component of Z
411 * inv(op(A)) is the inverse of op(A)
412 * abs(Z) is the componentwise absolute value of the matrix or
414 * NZ is the maximum number of nonzeros in any row of A, plus 1
415 * EPS is machine epsilon
417 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
418 * is incremented by SAFE1 if the i-th component of
419 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
421 * Use ZLACN2 to estimate the infinity-norm of the matrix
422 * inv(op(A)) * diag(W),
423 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
426 IF( RWORK( I ).GT.SAFE2 ) THEN
427 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
429 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
436 CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
440 * Multiply by diag(W)*inv(op(A)**H).
442 CALL ZGBTRS( TRANST, N, KL, KU, 1, AFB, LDAFB, IPIV,
445 WORK( I ) = RWORK( I )*WORK( I )
449 * Multiply by inv(op(A))*diag(W).
452 WORK( I ) = RWORK( I )*WORK( I )
454 CALL ZGBTRS( TRANSN, N, KL, KU, 1, AFB, LDAFB, IPIV,
464 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
467 $ FERR( J ) = FERR( J ) / LSTRES