3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZTBRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ztbrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ztbrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ztbrfs.f">
21 * SUBROUTINE ZTBRFS( UPLO, TRANS, DIAG, N, KD, NRHS, AB, LDAB, B,
22 * LDB, X, LDX, FERR, BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER DIAG, TRANS, UPLO
26 * INTEGER INFO, KD, LDAB, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
29 * DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
30 * COMPLEX*16 AB( LDAB, * ), B( LDB, * ), WORK( * ),
40 *> ZTBRFS provides error bounds and backward error estimates for the
41 *> solution to a system of linear equations with a triangular band
42 *> coefficient matrix.
44 *> The solution matrix X must be computed by ZTBTRS or some other
45 *> means before entering this routine. ZTBRFS does not do iterative
46 *> refinement because doing so cannot improve the backward error.
54 *> UPLO is CHARACTER*1
55 *> = 'U': A is upper triangular;
56 *> = 'L': A is lower triangular.
61 *> TRANS is CHARACTER*1
62 *> Specifies the form of the system of equations:
63 *> = 'N': A * X = B (No transpose)
64 *> = 'T': A**T * X = B (Transpose)
65 *> = 'C': A**H * X = B (Conjugate transpose)
70 *> DIAG is CHARACTER*1
71 *> = 'N': A is non-unit triangular;
72 *> = 'U': A is unit triangular.
78 *> The order of the matrix A. N >= 0.
84 *> The number of superdiagonals or subdiagonals of the
85 *> triangular band matrix A. KD >= 0.
91 *> The number of right hand sides, i.e., the number of columns
92 *> of the matrices B and X. NRHS >= 0.
97 *> AB is COMPLEX*16 array, dimension (LDAB,N)
98 *> The upper or lower triangular band matrix A, stored in the
99 *> first kd+1 rows of the array. The j-th column of A is stored
100 *> in the j-th column of the array AB as follows:
101 *> if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
102 *> if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd).
103 *> If DIAG = 'U', the diagonal elements of A are not referenced
104 *> and are assumed to be 1.
110 *> The leading dimension of the array AB. LDAB >= KD+1.
115 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
116 *> The right hand side matrix B.
122 *> The leading dimension of the array B. LDB >= max(1,N).
127 *> X is COMPLEX*16 array, dimension (LDX,NRHS)
128 *> The solution matrix X.
134 *> The leading dimension of the array X. LDX >= max(1,N).
139 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
140 *> The estimated forward error bound for each solution vector
141 *> X(j) (the j-th column of the solution matrix X).
142 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
143 *> is an estimated upper bound for the magnitude of the largest
144 *> element in (X(j) - XTRUE) divided by the magnitude of the
145 *> largest element in X(j). The estimate is as reliable as
146 *> the estimate for RCOND, and is almost always a slight
147 *> overestimate of the true error.
152 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
153 *> The componentwise relative backward error of each solution
154 *> vector X(j) (i.e., the smallest relative change in
155 *> any element of A or B that makes X(j) an exact solution).
160 *> WORK is COMPLEX*16 array, dimension (2*N)
165 *> RWORK is DOUBLE PRECISION array, dimension (N)
171 *> = 0: successful exit
172 *> < 0: if INFO = -i, the i-th argument had an illegal value
178 *> \author Univ. of Tennessee
179 *> \author Univ. of California Berkeley
180 *> \author Univ. of Colorado Denver
183 *> \date November 2011
185 *> \ingroup complex16OTHERcomputational
187 * =====================================================================
188 SUBROUTINE ZTBRFS( UPLO, TRANS, DIAG, N, KD, NRHS, AB, LDAB, B,
189 $ LDB, X, LDX, FERR, BERR, WORK, RWORK, INFO )
191 * -- LAPACK computational routine (version 3.4.0) --
192 * -- LAPACK is a software package provided by Univ. of Tennessee, --
193 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
196 * .. Scalar Arguments ..
197 CHARACTER DIAG, TRANS, UPLO
198 INTEGER INFO, KD, LDAB, LDB, LDX, N, NRHS
200 * .. Array Arguments ..
201 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
202 COMPLEX*16 AB( LDAB, * ), B( LDB, * ), WORK( * ),
206 * =====================================================================
209 DOUBLE PRECISION ZERO
210 PARAMETER ( ZERO = 0.0D+0 )
212 PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
214 * .. Local Scalars ..
215 LOGICAL NOTRAN, NOUNIT, UPPER
216 CHARACTER TRANSN, TRANST
217 INTEGER I, J, K, KASE, NZ
218 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
224 * .. External Subroutines ..
225 EXTERNAL XERBLA, ZAXPY, ZCOPY, ZLACN2, ZTBMV, ZTBSV
227 * .. Intrinsic Functions ..
228 INTRINSIC ABS, DBLE, DIMAG, MAX, MIN
230 * .. External Functions ..
232 DOUBLE PRECISION DLAMCH
233 EXTERNAL LSAME, DLAMCH
235 * .. Statement Functions ..
236 DOUBLE PRECISION CABS1
238 * .. Statement Function definitions ..
239 CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
241 * .. Executable Statements ..
243 * Test the input parameters.
246 UPPER = LSAME( UPLO, 'U' )
247 NOTRAN = LSAME( TRANS, 'N' )
248 NOUNIT = LSAME( DIAG, 'N' )
250 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
252 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
253 $ LSAME( TRANS, 'C' ) ) THEN
255 ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
257 ELSE IF( N.LT.0 ) THEN
259 ELSE IF( KD.LT.0 ) THEN
261 ELSE IF( NRHS.LT.0 ) THEN
263 ELSE IF( LDAB.LT.KD+1 ) THEN
265 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
267 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
271 CALL XERBLA( 'ZTBRFS', -INFO )
275 * Quick return if possible
277 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
293 * NZ = maximum number of nonzero elements in each row of A, plus 1
296 EPS = DLAMCH( 'Epsilon' )
297 SAFMIN = DLAMCH( 'Safe minimum' )
301 * Do for each right hand side
305 * Compute residual R = B - op(A) * X,
306 * where op(A) = A, A**T, or A**H, depending on TRANS.
308 CALL ZCOPY( N, X( 1, J ), 1, WORK, 1 )
309 CALL ZTBMV( UPLO, TRANS, DIAG, N, KD, AB, LDAB, WORK, 1 )
310 CALL ZAXPY( N, -ONE, B( 1, J ), 1, WORK, 1 )
312 * Compute componentwise relative backward error from formula
314 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
316 * where abs(Z) is the componentwise absolute value of the matrix
317 * or vector Z. If the i-th component of the denominator is less
318 * than SAFE2, then SAFE1 is added to the i-th components of the
319 * numerator and denominator before dividing.
322 RWORK( I ) = CABS1( B( I, J ) )
327 * Compute abs(A)*abs(X) + abs(B).
332 XK = CABS1( X( K, J ) )
333 DO 30 I = MAX( 1, K-KD ), K
334 RWORK( I ) = RWORK( I ) +
335 $ CABS1( AB( KD+1+I-K, K ) )*XK
340 XK = CABS1( X( K, J ) )
341 DO 50 I = MAX( 1, K-KD ), K - 1
342 RWORK( I ) = RWORK( I ) +
343 $ CABS1( AB( KD+1+I-K, K ) )*XK
345 RWORK( K ) = RWORK( K ) + XK
351 XK = CABS1( X( K, J ) )
352 DO 70 I = K, MIN( N, K+KD )
353 RWORK( I ) = RWORK( I ) +
354 $ CABS1( AB( 1+I-K, K ) )*XK
359 XK = CABS1( X( K, J ) )
360 DO 90 I = K + 1, MIN( N, K+KD )
361 RWORK( I ) = RWORK( I ) +
362 $ CABS1( AB( 1+I-K, K ) )*XK
364 RWORK( K ) = RWORK( K ) + XK
370 * Compute abs(A**H)*abs(X) + abs(B).
376 DO 110 I = MAX( 1, K-KD ), K
377 S = S + CABS1( AB( KD+1+I-K, K ) )*
380 RWORK( K ) = RWORK( K ) + S
384 S = CABS1( X( K, J ) )
385 DO 130 I = MAX( 1, K-KD ), K - 1
386 S = S + CABS1( AB( KD+1+I-K, K ) )*
389 RWORK( K ) = RWORK( K ) + S
396 DO 150 I = K, MIN( N, K+KD )
397 S = S + CABS1( AB( 1+I-K, K ) )*
400 RWORK( K ) = RWORK( K ) + S
404 S = CABS1( X( K, J ) )
405 DO 170 I = K + 1, MIN( N, K+KD )
406 S = S + CABS1( AB( 1+I-K, K ) )*
409 RWORK( K ) = RWORK( K ) + S
416 IF( RWORK( I ).GT.SAFE2 ) THEN
417 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
419 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
420 $ ( RWORK( I )+SAFE1 ) )
425 * Bound error from formula
427 * norm(X - XTRUE) / norm(X) .le. FERR =
428 * norm( abs(inv(op(A)))*
429 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
432 * norm(Z) is the magnitude of the largest component of Z
433 * inv(op(A)) is the inverse of op(A)
434 * abs(Z) is the componentwise absolute value of the matrix or
436 * NZ is the maximum number of nonzeros in any row of A, plus 1
437 * EPS is machine epsilon
439 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
440 * is incremented by SAFE1 if the i-th component of
441 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
443 * Use ZLACN2 to estimate the infinity-norm of the matrix
444 * inv(op(A)) * diag(W),
445 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
448 IF( RWORK( I ).GT.SAFE2 ) THEN
449 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
451 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
458 CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
462 * Multiply by diag(W)*inv(op(A)**H).
464 CALL ZTBSV( UPLO, TRANST, DIAG, N, KD, AB, LDAB, WORK,
467 WORK( I ) = RWORK( I )*WORK( I )
471 * Multiply by inv(op(A))*diag(W).
474 WORK( I ) = RWORK( I )*WORK( I )
476 CALL ZTBSV( UPLO, TRANSN, DIAG, N, KD, AB, LDAB, WORK,
486 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
489 $ FERR( J ) = FERR( J ) / LSTRES