3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CTPRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctprfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctprfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctprfs.f">
21 * SUBROUTINE CTPRFS( UPLO, TRANS, DIAG, N, NRHS, AP, B, LDB, X, LDX,
22 * FERR, BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER DIAG, TRANS, UPLO
26 * INTEGER INFO, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
29 * REAL BERR( * ), FERR( * ), RWORK( * )
30 * COMPLEX AP( * ), B( LDB, * ), WORK( * ), X( LDX, * )
39 *> CTPRFS provides error bounds and backward error estimates for the
40 *> solution to a system of linear equations with a triangular packed
41 *> coefficient matrix.
43 *> The solution matrix X must be computed by CTPTRS or some other
44 *> means before entering this routine. CTPRFS does not do iterative
45 *> refinement because doing so cannot improve the backward error.
53 *> UPLO is CHARACTER*1
54 *> = 'U': A is upper triangular;
55 *> = 'L': A is lower triangular.
60 *> TRANS is CHARACTER*1
61 *> Specifies the form of the system of equations:
62 *> = 'N': A * X = B (No transpose)
63 *> = 'T': A**T * X = B (Transpose)
64 *> = 'C': A**H * X = B (Conjugate transpose)
69 *> DIAG is CHARACTER*1
70 *> = 'N': A is non-unit triangular;
71 *> = 'U': A is unit triangular.
77 *> The order of the matrix A. N >= 0.
83 *> The number of right hand sides, i.e., the number of columns
84 *> of the matrices B and X. NRHS >= 0.
89 *> AP is COMPLEX array, dimension (N*(N+1)/2)
90 *> The upper or lower triangular matrix A, packed columnwise in
91 *> a linear array. The j-th column of A is stored in the array
93 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
94 *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
95 *> If DIAG = 'U', the diagonal elements of A are not referenced
96 *> and are assumed to be 1.
101 *> B is COMPLEX array, dimension (LDB,NRHS)
102 *> The right hand side matrix B.
108 *> The leading dimension of the array B. LDB >= max(1,N).
113 *> X is COMPLEX array, dimension (LDX,NRHS)
114 *> The solution matrix X.
120 *> The leading dimension of the array X. LDX >= max(1,N).
125 *> FERR is REAL array, dimension (NRHS)
126 *> The estimated forward error bound for each solution vector
127 *> X(j) (the j-th column of the solution matrix X).
128 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
129 *> is an estimated upper bound for the magnitude of the largest
130 *> element in (X(j) - XTRUE) divided by the magnitude of the
131 *> largest element in X(j). The estimate is as reliable as
132 *> the estimate for RCOND, and is almost always a slight
133 *> overestimate of the true error.
138 *> BERR is REAL array, dimension (NRHS)
139 *> The componentwise relative backward error of each solution
140 *> vector X(j) (i.e., the smallest relative change in
141 *> any element of A or B that makes X(j) an exact solution).
146 *> WORK is COMPLEX array, dimension (2*N)
151 *> RWORK is REAL array, dimension (N)
157 *> = 0: successful exit
158 *> < 0: if INFO = -i, the i-th argument had an illegal value
164 *> \author Univ. of Tennessee
165 *> \author Univ. of California Berkeley
166 *> \author Univ. of Colorado Denver
169 *> \date November 2011
171 *> \ingroup complexOTHERcomputational
173 * =====================================================================
174 SUBROUTINE CTPRFS( UPLO, TRANS, DIAG, N, NRHS, AP, B, LDB, X, LDX,
175 $ FERR, BERR, WORK, RWORK, INFO )
177 * -- LAPACK computational routine (version 3.4.0) --
178 * -- LAPACK is a software package provided by Univ. of Tennessee, --
179 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
182 * .. Scalar Arguments ..
183 CHARACTER DIAG, TRANS, UPLO
184 INTEGER INFO, LDB, LDX, N, NRHS
186 * .. Array Arguments ..
187 REAL BERR( * ), FERR( * ), RWORK( * )
188 COMPLEX AP( * ), B( LDB, * ), WORK( * ), X( LDX, * )
191 * =====================================================================
195 PARAMETER ( ZERO = 0.0E+0 )
197 PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )
199 * .. Local Scalars ..
200 LOGICAL NOTRAN, NOUNIT, UPPER
201 CHARACTER TRANSN, TRANST
202 INTEGER I, J, K, KASE, KC, NZ
203 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
209 * .. External Subroutines ..
210 EXTERNAL CAXPY, CCOPY, CLACN2, CTPMV, CTPSV, XERBLA
212 * .. Intrinsic Functions ..
213 INTRINSIC ABS, AIMAG, MAX, REAL
215 * .. External Functions ..
218 EXTERNAL LSAME, SLAMCH
220 * .. Statement Functions ..
223 * .. Statement Function definitions ..
224 CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
226 * .. Executable Statements ..
228 * Test the input parameters.
231 UPPER = LSAME( UPLO, 'U' )
232 NOTRAN = LSAME( TRANS, 'N' )
233 NOUNIT = LSAME( DIAG, 'N' )
235 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
237 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
238 $ LSAME( TRANS, 'C' ) ) THEN
240 ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
242 ELSE IF( N.LT.0 ) THEN
244 ELSE IF( NRHS.LT.0 ) THEN
246 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
248 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
252 CALL XERBLA( 'CTPRFS', -INFO )
256 * Quick return if possible
258 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
274 * NZ = maximum number of nonzero elements in each row of A, plus 1
277 EPS = SLAMCH( 'Epsilon' )
278 SAFMIN = SLAMCH( 'Safe minimum' )
282 * Do for each right hand side
286 * Compute residual R = B - op(A) * X,
287 * where op(A) = A, A**T, or A**H, depending on TRANS.
289 CALL CCOPY( N, X( 1, J ), 1, WORK, 1 )
290 CALL CTPMV( UPLO, TRANS, DIAG, N, AP, WORK, 1 )
291 CALL CAXPY( N, -ONE, B( 1, J ), 1, WORK, 1 )
293 * Compute componentwise relative backward error from formula
295 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
297 * where abs(Z) is the componentwise absolute value of the matrix
298 * or vector Z. If the i-th component of the denominator is less
299 * than SAFE2, then SAFE1 is added to the i-th components of the
300 * numerator and denominator before dividing.
303 RWORK( I ) = CABS1( B( I, J ) )
308 * Compute abs(A)*abs(X) + abs(B).
314 XK = CABS1( X( K, J ) )
316 RWORK( I ) = RWORK( I ) +
317 $ CABS1( AP( KC+I-1 ) )*XK
323 XK = CABS1( X( K, J ) )
325 RWORK( I ) = RWORK( I ) +
326 $ CABS1( AP( KC+I-1 ) )*XK
328 RWORK( K ) = RWORK( K ) + XK
336 XK = CABS1( X( K, J ) )
338 RWORK( I ) = RWORK( I ) +
339 $ CABS1( AP( KC+I-K ) )*XK
345 XK = CABS1( X( K, J ) )
347 RWORK( I ) = RWORK( I ) +
348 $ CABS1( AP( KC+I-K ) )*XK
350 RWORK( K ) = RWORK( K ) + XK
357 * Compute abs(A**H)*abs(X) + abs(B).
365 S = S + CABS1( AP( KC+I-1 ) )*CABS1( X( I, J ) )
367 RWORK( K ) = RWORK( K ) + S
372 S = CABS1( X( K, J ) )
374 S = S + CABS1( AP( KC+I-1 ) )*CABS1( X( I, J ) )
376 RWORK( K ) = RWORK( K ) + S
386 S = S + CABS1( AP( KC+I-K ) )*CABS1( X( I, J ) )
388 RWORK( K ) = RWORK( K ) + S
393 S = CABS1( X( K, J ) )
395 S = S + CABS1( AP( KC+I-K ) )*CABS1( X( I, J ) )
397 RWORK( K ) = RWORK( K ) + S
405 IF( RWORK( I ).GT.SAFE2 ) THEN
406 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
408 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
409 $ ( RWORK( I )+SAFE1 ) )
414 * Bound error from formula
416 * norm(X - XTRUE) / norm(X) .le. FERR =
417 * norm( abs(inv(op(A)))*
418 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
421 * norm(Z) is the magnitude of the largest component of Z
422 * inv(op(A)) is the inverse of op(A)
423 * abs(Z) is the componentwise absolute value of the matrix or
425 * NZ is the maximum number of nonzeros in any row of A, plus 1
426 * EPS is machine epsilon
428 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
429 * is incremented by SAFE1 if the i-th component of
430 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
432 * Use CLACN2 to estimate the infinity-norm of the matrix
433 * inv(op(A)) * diag(W),
434 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
437 IF( RWORK( I ).GT.SAFE2 ) THEN
438 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
440 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
447 CALL CLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
451 * Multiply by diag(W)*inv(op(A)**H).
453 CALL CTPSV( UPLO, TRANST, DIAG, N, AP, WORK, 1 )
455 WORK( I ) = RWORK( I )*WORK( I )
459 * Multiply by inv(op(A))*diag(W).
462 WORK( I ) = RWORK( I )*WORK( I )
464 CALL CTPSV( UPLO, TRANSN, DIAG, N, AP, WORK, 1 )
473 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
476 $ FERR( J ) = FERR( J ) / LSTRES