3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZGTRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgtrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgtrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgtrfs.f">
21 * SUBROUTINE ZGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2,
22 * IPIV, B, LDB, X, LDX, FERR, BERR, WORK, RWORK,
25 * .. Scalar Arguments ..
27 * INTEGER INFO, LDB, LDX, N, NRHS
29 * .. Array Arguments ..
31 * DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
32 * COMPLEX*16 B( LDB, * ), D( * ), DF( * ), DL( * ),
33 * $ DLF( * ), DU( * ), DU2( * ), DUF( * ),
34 * $ WORK( * ), X( LDX, * )
43 *> ZGTRFS improves the computed solution to a system of linear
44 *> equations when the coefficient matrix is tridiagonal, and provides
45 *> error bounds and backward error estimates for the solution.
53 *> TRANS is CHARACTER*1
54 *> Specifies the form of the system of equations:
55 *> = 'N': A * X = B (No transpose)
56 *> = 'T': A**T * X = B (Transpose)
57 *> = 'C': A**H * X = B (Conjugate transpose)
63 *> The order of the matrix A. N >= 0.
69 *> The number of right hand sides, i.e., the number of columns
70 *> of the matrix B. NRHS >= 0.
75 *> DL is COMPLEX*16 array, dimension (N-1)
76 *> The (n-1) subdiagonal elements of A.
81 *> D is COMPLEX*16 array, dimension (N)
82 *> The diagonal elements of A.
87 *> DU is COMPLEX*16 array, dimension (N-1)
88 *> The (n-1) superdiagonal elements of A.
93 *> DLF is COMPLEX*16 array, dimension (N-1)
94 *> The (n-1) multipliers that define the matrix L from the
95 *> LU factorization of A as computed by ZGTTRF.
100 *> DF is COMPLEX*16 array, dimension (N)
101 *> The n diagonal elements of the upper triangular matrix U from
102 *> the LU factorization of A.
107 *> DUF is COMPLEX*16 array, dimension (N-1)
108 *> The (n-1) elements of the first superdiagonal of U.
113 *> DU2 is COMPLEX*16 array, dimension (N-2)
114 *> The (n-2) elements of the second superdiagonal of U.
119 *> IPIV is INTEGER array, dimension (N)
120 *> The pivot indices; for 1 <= i <= n, row i of the matrix was
121 *> interchanged with row IPIV(i). IPIV(i) will always be either
122 *> i or i+1; IPIV(i) = i indicates a row interchange was not
128 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
129 *> The right hand side matrix B.
135 *> The leading dimension of the array B. LDB >= max(1,N).
140 *> X is COMPLEX*16 array, dimension (LDX,NRHS)
141 *> On entry, the solution matrix X, as computed by ZGTTRS.
142 *> On exit, the improved solution matrix X.
148 *> The leading dimension of the array X. LDX >= max(1,N).
153 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
154 *> The estimated forward error bound for each solution vector
155 *> X(j) (the j-th column of the solution matrix X).
156 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
157 *> is an estimated upper bound for the magnitude of the largest
158 *> element in (X(j) - XTRUE) divided by the magnitude of the
159 *> largest element in X(j). The estimate is as reliable as
160 *> the estimate for RCOND, and is almost always a slight
161 *> overestimate of the true error.
166 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
167 *> The componentwise relative backward error of each solution
168 *> vector X(j) (i.e., the smallest relative change in
169 *> any element of A or B that makes X(j) an exact solution).
174 *> WORK is COMPLEX*16 array, dimension (2*N)
179 *> RWORK is DOUBLE PRECISION array, dimension (N)
185 *> = 0: successful exit
186 *> < 0: if INFO = -i, the i-th argument had an illegal value
189 *> \par Internal Parameters:
190 * =========================
193 *> ITMAX is the maximum number of steps of iterative refinement.
199 *> \author Univ. of Tennessee
200 *> \author Univ. of California Berkeley
201 *> \author Univ. of Colorado Denver
204 *> \date September 2012
206 *> \ingroup complex16GTcomputational
208 * =====================================================================
209 SUBROUTINE ZGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2,
210 $ IPIV, B, LDB, X, LDX, FERR, BERR, WORK, RWORK,
213 * -- LAPACK computational routine (version 3.4.2) --
214 * -- LAPACK is a software package provided by Univ. of Tennessee, --
215 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
218 * .. Scalar Arguments ..
220 INTEGER INFO, LDB, LDX, N, NRHS
222 * .. Array Arguments ..
224 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
225 COMPLEX*16 B( LDB, * ), D( * ), DF( * ), DL( * ),
226 $ DLF( * ), DU( * ), DU2( * ), DUF( * ),
227 $ WORK( * ), X( LDX, * )
230 * =====================================================================
234 PARAMETER ( ITMAX = 5 )
235 DOUBLE PRECISION ZERO, ONE
236 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
238 PARAMETER ( TWO = 2.0D+0 )
239 DOUBLE PRECISION THREE
240 PARAMETER ( THREE = 3.0D+0 )
242 * .. Local Scalars ..
244 CHARACTER TRANSN, TRANST
245 INTEGER COUNT, I, J, KASE, NZ
246 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN
252 * .. External Subroutines ..
253 EXTERNAL XERBLA, ZAXPY, ZCOPY, ZGTTRS, ZLACN2, ZLAGTM
255 * .. Intrinsic Functions ..
256 INTRINSIC ABS, DBLE, DCMPLX, DIMAG, MAX
258 * .. External Functions ..
260 DOUBLE PRECISION DLAMCH
261 EXTERNAL LSAME, DLAMCH
263 * .. Statement Functions ..
264 DOUBLE PRECISION CABS1
266 * .. Statement Function definitions ..
267 CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
269 * .. Executable Statements ..
271 * Test the input parameters.
274 NOTRAN = LSAME( TRANS, 'N' )
275 IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
276 $ LSAME( TRANS, 'C' ) ) THEN
278 ELSE IF( N.LT.0 ) THEN
280 ELSE IF( NRHS.LT.0 ) THEN
282 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
284 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
288 CALL XERBLA( 'ZGTRFS', -INFO )
292 * Quick return if possible
294 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
310 * NZ = maximum number of nonzero elements in each row of A, plus 1
313 EPS = DLAMCH( 'Epsilon' )
314 SAFMIN = DLAMCH( 'Safe minimum' )
318 * Do for each right hand side
326 * Loop until stopping criterion is satisfied.
328 * Compute residual R = B - op(A) * X,
329 * where op(A) = A, A**T, or A**H, depending on TRANS.
331 CALL ZCOPY( N, B( 1, J ), 1, WORK, 1 )
332 CALL ZLAGTM( TRANS, N, 1, -ONE, DL, D, DU, X( 1, J ), LDX, ONE,
335 * Compute abs(op(A))*abs(x) + abs(b) for use in the backward
340 RWORK( 1 ) = CABS1( B( 1, J ) ) +
341 $ CABS1( D( 1 ) )*CABS1( X( 1, J ) )
343 RWORK( 1 ) = CABS1( B( 1, J ) ) +
344 $ CABS1( D( 1 ) )*CABS1( X( 1, J ) ) +
345 $ CABS1( DU( 1 ) )*CABS1( X( 2, J ) )
347 RWORK( I ) = CABS1( B( I, J ) ) +
348 $ CABS1( DL( I-1 ) )*CABS1( X( I-1, J ) ) +
349 $ CABS1( D( I ) )*CABS1( X( I, J ) ) +
350 $ CABS1( DU( I ) )*CABS1( X( I+1, J ) )
352 RWORK( N ) = CABS1( B( N, J ) ) +
353 $ CABS1( DL( N-1 ) )*CABS1( X( N-1, J ) ) +
354 $ CABS1( D( N ) )*CABS1( X( N, J ) )
358 RWORK( 1 ) = CABS1( B( 1, J ) ) +
359 $ CABS1( D( 1 ) )*CABS1( X( 1, J ) )
361 RWORK( 1 ) = CABS1( B( 1, J ) ) +
362 $ CABS1( D( 1 ) )*CABS1( X( 1, J ) ) +
363 $ CABS1( DL( 1 ) )*CABS1( X( 2, J ) )
365 RWORK( I ) = CABS1( B( I, J ) ) +
366 $ CABS1( DU( I-1 ) )*CABS1( X( I-1, J ) ) +
367 $ CABS1( D( I ) )*CABS1( X( I, J ) ) +
368 $ CABS1( DL( I ) )*CABS1( X( I+1, J ) )
370 RWORK( N ) = CABS1( B( N, J ) ) +
371 $ CABS1( DU( N-1 ) )*CABS1( X( N-1, J ) ) +
372 $ CABS1( D( N ) )*CABS1( X( N, J ) )
376 * Compute componentwise relative backward error from formula
378 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
380 * where abs(Z) is the componentwise absolute value of the matrix
381 * or vector Z. If the i-th component of the denominator is less
382 * than SAFE2, then SAFE1 is added to the i-th components of the
383 * numerator and denominator before dividing.
387 IF( RWORK( I ).GT.SAFE2 ) THEN
388 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
390 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
391 $ ( RWORK( I )+SAFE1 ) )
396 * Test stopping criterion. Continue iterating if
397 * 1) The residual BERR(J) is larger than machine epsilon, and
398 * 2) BERR(J) decreased by at least a factor of 2 during the
399 * last iteration, and
400 * 3) At most ITMAX iterations tried.
402 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
403 $ COUNT.LE.ITMAX ) THEN
405 * Update solution and try again.
407 CALL ZGTTRS( TRANS, N, 1, DLF, DF, DUF, DU2, IPIV, WORK, N,
409 CALL ZAXPY( N, DCMPLX( ONE ), WORK, 1, X( 1, J ), 1 )
415 * Bound error from formula
417 * norm(X - XTRUE) / norm(X) .le. FERR =
418 * norm( abs(inv(op(A)))*
419 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
422 * norm(Z) is the magnitude of the largest component of Z
423 * inv(op(A)) is the inverse of op(A)
424 * abs(Z) is the componentwise absolute value of the matrix or
426 * NZ is the maximum number of nonzeros in any row of A, plus 1
427 * EPS is machine epsilon
429 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
430 * is incremented by SAFE1 if the i-th component of
431 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
433 * Use ZLACN2 to estimate the infinity-norm of the matrix
434 * inv(op(A)) * diag(W),
435 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
438 IF( RWORK( I ).GT.SAFE2 ) THEN
439 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
441 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
448 CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
452 * Multiply by diag(W)*inv(op(A)**H).
454 CALL ZGTTRS( TRANST, N, 1, DLF, DF, DUF, DU2, IPIV, WORK,
457 WORK( I ) = RWORK( I )*WORK( I )
461 * Multiply by inv(op(A))*diag(W).
464 WORK( I ) = RWORK( I )*WORK( I )
466 CALL ZGTTRS( TRANSN, N, 1, DLF, DF, DUF, DU2, IPIV, WORK,
476 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
479 $ FERR( J ) = FERR( J ) / LSTRES