3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DTRRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrrfs.f">
21 * SUBROUTINE DTRRFS( UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, X,
22 * LDX, FERR, BERR, WORK, IWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER DIAG, TRANS, UPLO
26 * INTEGER INFO, LDA, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
30 * DOUBLE PRECISION A( LDA, * ), B( LDB, * ), BERR( * ), FERR( * ),
31 * $ WORK( * ), X( LDX, * )
40 *> DTRRFS 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 DTRTRS or some other
45 *> means before entering this routine. DTRRFS 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 = 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION array, dimension (3*N)
159 *> IWORK is INTEGER 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 doubleOTHERcomputational
181 * =====================================================================
182 SUBROUTINE DTRRFS( UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, X,
183 $ LDX, FERR, BERR, WORK, IWORK, 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 ..
196 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), BERR( * ), FERR( * ),
197 $ WORK( * ), X( LDX, * )
200 * =====================================================================
203 DOUBLE PRECISION ZERO
204 PARAMETER ( ZERO = 0.0D+0 )
206 PARAMETER ( ONE = 1.0D+0 )
208 * .. Local Scalars ..
209 LOGICAL NOTRAN, NOUNIT, UPPER
211 INTEGER I, J, K, KASE, NZ
212 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
217 * .. External Subroutines ..
218 EXTERNAL DAXPY, DCOPY, DLACN2, DTRMV, DTRSV, XERBLA
220 * .. Intrinsic Functions ..
223 * .. External Functions ..
225 DOUBLE PRECISION DLAMCH
226 EXTERNAL LSAME, DLAMCH
228 * .. Executable Statements ..
230 * Test the input parameters.
233 UPPER = LSAME( UPLO, 'U' )
234 NOTRAN = LSAME( TRANS, 'N' )
235 NOUNIT = LSAME( DIAG, 'N' )
237 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
239 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
240 $ LSAME( TRANS, 'C' ) ) THEN
242 ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
244 ELSE IF( N.LT.0 ) THEN
246 ELSE IF( NRHS.LT.0 ) THEN
248 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
250 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
252 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
256 CALL XERBLA( 'DTRRFS', -INFO )
260 * Quick return if possible
262 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
276 * NZ = maximum number of nonzero elements in each row of A, plus 1
279 EPS = DLAMCH( 'Epsilon' )
280 SAFMIN = DLAMCH( 'Safe minimum' )
284 * Do for each right hand side
288 * Compute residual R = B - op(A) * X,
289 * where op(A) = A or A**T, depending on TRANS.
291 CALL DCOPY( N, X( 1, J ), 1, WORK( N+1 ), 1 )
292 CALL DTRMV( UPLO, TRANS, DIAG, N, A, LDA, WORK( N+1 ), 1 )
293 CALL DAXPY( N, -ONE, B( 1, J ), 1, WORK( N+1 ), 1 )
295 * Compute componentwise relative backward error from formula
297 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
299 * where abs(Z) is the componentwise absolute value of the matrix
300 * or vector Z. If the i-th component of the denominator is less
301 * than SAFE2, then SAFE1 is added to the i-th components of the
302 * numerator and denominator before dividing.
305 WORK( I ) = ABS( B( I, J ) )
310 * Compute abs(A)*abs(X) + abs(B).
315 XK = ABS( X( K, J ) )
317 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
322 XK = ABS( X( K, J ) )
324 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
326 WORK( K ) = WORK( K ) + XK
332 XK = ABS( X( K, J ) )
334 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
339 XK = ABS( X( K, J ) )
341 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
343 WORK( K ) = WORK( K ) + XK
349 * Compute abs(A**T)*abs(X) + abs(B).
356 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
358 WORK( K ) = WORK( K ) + S
364 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
366 WORK( K ) = WORK( K ) + S
374 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
376 WORK( K ) = WORK( K ) + S
382 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
384 WORK( K ) = WORK( K ) + S
391 IF( WORK( I ).GT.SAFE2 ) THEN
392 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
394 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
395 $ ( WORK( I )+SAFE1 ) )
400 * Bound error from formula
402 * norm(X - XTRUE) / norm(X) .le. FERR =
403 * norm( abs(inv(op(A)))*
404 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
407 * norm(Z) is the magnitude of the largest component of Z
408 * inv(op(A)) is the inverse of op(A)
409 * abs(Z) is the componentwise absolute value of the matrix or
411 * NZ is the maximum number of nonzeros in any row of A, plus 1
412 * EPS is machine epsilon
414 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
415 * is incremented by SAFE1 if the i-th component of
416 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
418 * Use DLACN2 to estimate the infinity-norm of the matrix
419 * inv(op(A)) * diag(W),
420 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
423 IF( WORK( I ).GT.SAFE2 ) THEN
424 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
426 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
432 CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
437 * Multiply by diag(W)*inv(op(A)**T).
439 CALL DTRSV( UPLO, TRANST, DIAG, N, A, LDA, WORK( N+1 ),
442 WORK( N+I ) = WORK( I )*WORK( N+I )
446 * Multiply by inv(op(A))*diag(W).
449 WORK( N+I ) = WORK( I )*WORK( N+I )
451 CALL DTRSV( UPLO, TRANS, DIAG, N, A, LDA, WORK( N+1 ),
461 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
464 $ FERR( J ) = FERR( J ) / LSTRES