3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZTRRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ztrrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ztrrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ztrrfs.f">
21 * SUBROUTINE ZTRRFS( UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, X,
22 * LDX, FERR, BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER DIAG, TRANS, UPLO
26 * INTEGER INFO, LDA, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
29 * DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
30 * COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * ),
40 *> ZTRRFS provides error bounds and backward error estimates for the
41 *> solution to a system of linear equations with a triangular
42 *> coefficient matrix.
44 *> The solution matrix X must be computed by ZTRTRS or some other
45 *> means before entering this routine. ZTRRFS 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 right hand sides, i.e., the number of columns
85 *> of the matrices B and X. NRHS >= 0.
90 *> A is COMPLEX*16 array, dimension (LDA,N)
91 *> The triangular matrix A. If UPLO = 'U', the leading N-by-N
92 *> upper triangular part of the array A contains the upper
93 *> triangular matrix, and the strictly lower triangular part of
94 *> A is not referenced. If UPLO = 'L', the leading N-by-N lower
95 *> triangular part of the array A contains the lower triangular
96 *> matrix, and the strictly upper triangular part of A is not
97 *> referenced. If DIAG = 'U', the diagonal elements of A are
98 *> also not referenced and are assumed to be 1.
104 *> The leading dimension of the array A. LDA >= max(1,N).
109 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
110 *> The right hand side matrix B.
116 *> The leading dimension of the array B. LDB >= max(1,N).
121 *> X is COMPLEX*16 array, dimension (LDX,NRHS)
122 *> The solution matrix X.
128 *> The leading dimension of the array X. LDX >= max(1,N).
133 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
134 *> The estimated forward error bound for each solution vector
135 *> X(j) (the j-th column of the solution matrix X).
136 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
137 *> is an estimated upper bound for the magnitude of the largest
138 *> element in (X(j) - XTRUE) divided by the magnitude of the
139 *> largest element in X(j). The estimate is as reliable as
140 *> the estimate for RCOND, and is almost always a slight
141 *> overestimate of the true error.
146 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
147 *> The componentwise relative backward error of each solution
148 *> vector X(j) (i.e., the smallest relative change in
149 *> any element of A or B that makes X(j) an exact solution).
154 *> WORK is COMPLEX*16 array, dimension (2*N)
159 *> RWORK is DOUBLE PRECISION array, dimension (N)
165 *> = 0: successful exit
166 *> < 0: if INFO = -i, the i-th argument had an illegal value
172 *> \author Univ. of Tennessee
173 *> \author Univ. of California Berkeley
174 *> \author Univ. of Colorado Denver
177 *> \date November 2011
179 *> \ingroup complex16OTHERcomputational
181 * =====================================================================
182 SUBROUTINE ZTRRFS( UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, X,
183 $ LDX, FERR, BERR, WORK, RWORK, INFO )
185 * -- LAPACK computational routine (version 3.4.0) --
186 * -- LAPACK is a software package provided by Univ. of Tennessee, --
187 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
190 * .. Scalar Arguments ..
191 CHARACTER DIAG, TRANS, UPLO
192 INTEGER INFO, LDA, LDB, LDX, N, NRHS
194 * .. Array Arguments ..
195 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
196 COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * ),
200 * =====================================================================
203 DOUBLE PRECISION ZERO
204 PARAMETER ( ZERO = 0.0D+0 )
206 PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
208 * .. Local Scalars ..
209 LOGICAL NOTRAN, NOUNIT, UPPER
210 CHARACTER TRANSN, TRANST
211 INTEGER I, J, K, KASE, NZ
212 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
218 * .. External Subroutines ..
219 EXTERNAL XERBLA, ZAXPY, ZCOPY, ZLACN2, ZTRMV, ZTRSV
221 * .. Intrinsic Functions ..
222 INTRINSIC ABS, DBLE, DIMAG, MAX
224 * .. External Functions ..
226 DOUBLE PRECISION DLAMCH
227 EXTERNAL LSAME, DLAMCH
229 * .. Statement Functions ..
230 DOUBLE PRECISION CABS1
232 * .. Statement Function definitions ..
233 CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
235 * .. Executable Statements ..
237 * Test the input parameters.
240 UPPER = LSAME( UPLO, 'U' )
241 NOTRAN = LSAME( TRANS, 'N' )
242 NOUNIT = LSAME( DIAG, 'N' )
244 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
246 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
247 $ LSAME( TRANS, 'C' ) ) THEN
249 ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
251 ELSE IF( N.LT.0 ) THEN
253 ELSE IF( NRHS.LT.0 ) THEN
255 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
257 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
259 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
263 CALL XERBLA( 'ZTRRFS', -INFO )
267 * Quick return if possible
269 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
285 * NZ = maximum number of nonzero elements in each row of A, plus 1
288 EPS = DLAMCH( 'Epsilon' )
289 SAFMIN = DLAMCH( 'Safe minimum' )
293 * Do for each right hand side
297 * Compute residual R = B - op(A) * X,
298 * where op(A) = A, A**T, or A**H, depending on TRANS.
300 CALL ZCOPY( N, X( 1, J ), 1, WORK, 1 )
301 CALL ZTRMV( UPLO, TRANS, DIAG, N, A, LDA, WORK, 1 )
302 CALL ZAXPY( N, -ONE, B( 1, J ), 1, WORK, 1 )
304 * Compute componentwise relative backward error from formula
306 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
308 * where abs(Z) is the componentwise absolute value of the matrix
309 * or vector Z. If the i-th component of the denominator is less
310 * than SAFE2, then SAFE1 is added to the i-th components of the
311 * numerator and denominator before dividing.
314 RWORK( I ) = CABS1( B( I, J ) )
319 * Compute abs(A)*abs(X) + abs(B).
324 XK = CABS1( X( K, J ) )
326 RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
331 XK = CABS1( X( K, J ) )
333 RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
335 RWORK( K ) = RWORK( K ) + XK
341 XK = CABS1( X( K, J ) )
343 RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
348 XK = CABS1( X( K, J ) )
350 RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
352 RWORK( K ) = RWORK( K ) + XK
358 * Compute abs(A**H)*abs(X) + abs(B).
365 S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
367 RWORK( K ) = RWORK( K ) + S
371 S = CABS1( X( K, J ) )
373 S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
375 RWORK( K ) = RWORK( K ) + S
383 S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
385 RWORK( K ) = RWORK( K ) + S
389 S = CABS1( X( K, J ) )
391 S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
393 RWORK( K ) = RWORK( K ) + S
400 IF( RWORK( I ).GT.SAFE2 ) THEN
401 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
403 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
404 $ ( RWORK( I )+SAFE1 ) )
409 * Bound error from formula
411 * norm(X - XTRUE) / norm(X) .le. FERR =
412 * norm( abs(inv(op(A)))*
413 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
416 * norm(Z) is the magnitude of the largest component of Z
417 * inv(op(A)) is the inverse of op(A)
418 * abs(Z) is the componentwise absolute value of the matrix or
420 * NZ is the maximum number of nonzeros in any row of A, plus 1
421 * EPS is machine epsilon
423 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
424 * is incremented by SAFE1 if the i-th component of
425 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
427 * Use ZLACN2 to estimate the infinity-norm of the matrix
428 * inv(op(A)) * diag(W),
429 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
432 IF( RWORK( I ).GT.SAFE2 ) THEN
433 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
435 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
442 CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
446 * Multiply by diag(W)*inv(op(A)**H).
448 CALL ZTRSV( UPLO, TRANST, DIAG, N, A, LDA, WORK, 1 )
450 WORK( I ) = RWORK( I )*WORK( I )
454 * Multiply by inv(op(A))*diag(W).
457 WORK( I ) = RWORK( I )*WORK( I )
459 CALL ZTRSV( UPLO, TRANSN, DIAG, N, A, LDA, WORK, 1 )
468 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
471 $ FERR( J ) = FERR( J ) / LSTRES