3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DTPRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtprfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtprfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtprfs.f">
21 * SUBROUTINE DTPRFS( UPLO, TRANS, DIAG, N, NRHS, AP, B, LDB, X, LDX,
22 * FERR, BERR, WORK, IWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER DIAG, TRANS, UPLO
26 * INTEGER INFO, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
30 * DOUBLE PRECISION AP( * ), B( LDB, * ), BERR( * ), FERR( * ),
31 * $ WORK( * ), X( LDX, * )
40 *> DTPRFS provides error bounds and backward error estimates for the
41 *> solution to a system of linear equations with a triangular packed
42 *> coefficient matrix.
44 *> The solution matrix X must be computed by DTPTRS or some other
45 *> means before entering this routine. DTPRFS 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 *> AP is DOUBLE PRECISION array, dimension (N*(N+1)/2)
91 *> The upper or lower triangular matrix A, packed columnwise in
92 *> a linear array. The j-th column of A is stored in the array
94 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
95 *> if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
96 *> If DIAG = 'U', the diagonal elements of A are not referenced
97 *> and are assumed to be 1.
102 *> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
103 *> The right hand side matrix B.
109 *> The leading dimension of the array B. LDB >= max(1,N).
114 *> X is DOUBLE PRECISION array, dimension (LDX,NRHS)
115 *> The solution matrix X.
121 *> The leading dimension of the array X. LDX >= max(1,N).
126 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
127 *> The estimated forward error bound for each solution vector
128 *> X(j) (the j-th column of the solution matrix X).
129 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
130 *> is an estimated upper bound for the magnitude of the largest
131 *> element in (X(j) - XTRUE) divided by the magnitude of the
132 *> largest element in X(j). The estimate is as reliable as
133 *> the estimate for RCOND, and is almost always a slight
134 *> overestimate of the true error.
139 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
140 *> The componentwise relative backward error of each solution
141 *> vector X(j) (i.e., the smallest relative change in
142 *> any element of A or B that makes X(j) an exact solution).
147 *> WORK is DOUBLE PRECISION array, dimension (3*N)
152 *> IWORK is INTEGER array, dimension (N)
158 *> = 0: successful exit
159 *> < 0: if INFO = -i, the i-th argument had an illegal value
165 *> \author Univ. of Tennessee
166 *> \author Univ. of California Berkeley
167 *> \author Univ. of Colorado Denver
170 *> \date November 2011
172 *> \ingroup doubleOTHERcomputational
174 * =====================================================================
175 SUBROUTINE DTPRFS( UPLO, TRANS, DIAG, N, NRHS, AP, B, LDB, X, LDX,
176 $ FERR, BERR, WORK, IWORK, INFO )
178 * -- LAPACK computational routine (version 3.4.0) --
179 * -- LAPACK is a software package provided by Univ. of Tennessee, --
180 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
183 * .. Scalar Arguments ..
184 CHARACTER DIAG, TRANS, UPLO
185 INTEGER INFO, LDB, LDX, N, NRHS
187 * .. Array Arguments ..
189 DOUBLE PRECISION AP( * ), B( LDB, * ), BERR( * ), FERR( * ),
190 $ WORK( * ), X( LDX, * )
193 * =====================================================================
196 DOUBLE PRECISION ZERO
197 PARAMETER ( ZERO = 0.0D+0 )
199 PARAMETER ( ONE = 1.0D+0 )
201 * .. Local Scalars ..
202 LOGICAL NOTRAN, NOUNIT, UPPER
204 INTEGER I, J, K, KASE, KC, NZ
205 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
210 * .. External Subroutines ..
211 EXTERNAL DAXPY, DCOPY, DLACN2, DTPMV, DTPSV, XERBLA
213 * .. Intrinsic Functions ..
216 * .. External Functions ..
218 DOUBLE PRECISION DLAMCH
219 EXTERNAL LSAME, DLAMCH
221 * .. Executable Statements ..
223 * Test the input parameters.
226 UPPER = LSAME( UPLO, 'U' )
227 NOTRAN = LSAME( TRANS, 'N' )
228 NOUNIT = LSAME( DIAG, 'N' )
230 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
232 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
233 $ LSAME( TRANS, 'C' ) ) THEN
235 ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
237 ELSE IF( N.LT.0 ) THEN
239 ELSE IF( NRHS.LT.0 ) THEN
241 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
243 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
247 CALL XERBLA( 'DTPRFS', -INFO )
251 * Quick return if possible
253 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
267 * NZ = maximum number of nonzero elements in each row of A, plus 1
270 EPS = DLAMCH( 'Epsilon' )
271 SAFMIN = DLAMCH( 'Safe minimum' )
275 * Do for each right hand side
279 * Compute residual R = B - op(A) * X,
280 * where op(A) = A or A**T, depending on TRANS.
282 CALL DCOPY( N, X( 1, J ), 1, WORK( N+1 ), 1 )
283 CALL DTPMV( UPLO, TRANS, DIAG, N, AP, WORK( N+1 ), 1 )
284 CALL DAXPY( N, -ONE, B( 1, J ), 1, WORK( N+1 ), 1 )
286 * Compute componentwise relative backward error from formula
288 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
290 * where abs(Z) is the componentwise absolute value of the matrix
291 * or vector Z. If the i-th component of the denominator is less
292 * than SAFE2, then SAFE1 is added to the i-th components of the
293 * numerator and denominator before dividing.
296 WORK( I ) = ABS( B( I, J ) )
301 * Compute abs(A)*abs(X) + abs(B).
307 XK = ABS( X( K, J ) )
309 WORK( I ) = WORK( I ) + ABS( AP( KC+I-1 ) )*XK
315 XK = ABS( X( K, J ) )
317 WORK( I ) = WORK( I ) + ABS( AP( KC+I-1 ) )*XK
319 WORK( K ) = WORK( K ) + XK
327 XK = ABS( X( K, J ) )
329 WORK( I ) = WORK( I ) + ABS( AP( KC+I-K ) )*XK
335 XK = ABS( X( K, J ) )
337 WORK( I ) = WORK( I ) + ABS( AP( KC+I-K ) )*XK
339 WORK( K ) = WORK( K ) + XK
346 * Compute abs(A**T)*abs(X) + abs(B).
354 S = S + ABS( AP( KC+I-1 ) )*ABS( X( I, J ) )
356 WORK( K ) = WORK( K ) + S
363 S = S + ABS( AP( KC+I-1 ) )*ABS( X( I, J ) )
365 WORK( K ) = WORK( K ) + S
375 S = S + ABS( AP( KC+I-K ) )*ABS( X( I, J ) )
377 WORK( K ) = WORK( K ) + S
384 S = S + ABS( AP( KC+I-K ) )*ABS( X( I, J ) )
386 WORK( K ) = WORK( K ) + S
394 IF( WORK( I ).GT.SAFE2 ) THEN
395 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
397 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
398 $ ( WORK( I )+SAFE1 ) )
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 DLACN2 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( WORK( I ).GT.SAFE2 ) THEN
427 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
429 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
435 CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
440 * Multiply by diag(W)*inv(op(A)**T).
442 CALL DTPSV( UPLO, TRANST, DIAG, N, AP, WORK( N+1 ), 1 )
444 WORK( N+I ) = WORK( I )*WORK( N+I )
448 * Multiply by inv(op(A))*diag(W).
451 WORK( N+I ) = WORK( I )*WORK( N+I )
453 CALL DTPSV( UPLO, TRANS, DIAG, N, AP, WORK( N+1 ), 1 )
462 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
465 $ FERR( J ) = FERR( J ) / LSTRES