3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SGTRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgtrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgtrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgtrfs.f">
21 * SUBROUTINE SGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2,
22 * IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
25 * .. Scalar Arguments ..
27 * INTEGER INFO, LDB, LDX, N, NRHS
29 * .. Array Arguments ..
30 * INTEGER IPIV( * ), IWORK( * )
31 * REAL B( LDB, * ), BERR( * ), D( * ), DF( * ),
32 * $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),
33 * $ FERR( * ), WORK( * ), X( LDX, * )
42 *> SGTRFS improves the computed solution to a system of linear
43 *> equations when the coefficient matrix is tridiagonal, and provides
44 *> error bounds and backward error estimates for the solution.
52 *> TRANS is CHARACTER*1
53 *> Specifies the form of the system of equations:
54 *> = 'N': A * X = B (No transpose)
55 *> = 'T': A**T * X = B (Transpose)
56 *> = 'C': A**H * X = B (Conjugate transpose = Transpose)
62 *> The order of the matrix A. N >= 0.
68 *> The number of right hand sides, i.e., the number of columns
69 *> of the matrix B. NRHS >= 0.
74 *> DL is REAL array, dimension (N-1)
75 *> The (n-1) subdiagonal elements of A.
80 *> D is REAL array, dimension (N)
81 *> The diagonal elements of A.
86 *> DU is REAL array, dimension (N-1)
87 *> The (n-1) superdiagonal elements of A.
92 *> DLF is REAL array, dimension (N-1)
93 *> The (n-1) multipliers that define the matrix L from the
94 *> LU factorization of A as computed by SGTTRF.
99 *> DF is REAL array, dimension (N)
100 *> The n diagonal elements of the upper triangular matrix U from
101 *> the LU factorization of A.
106 *> DUF is REAL array, dimension (N-1)
107 *> The (n-1) elements of the first superdiagonal of U.
112 *> DU2 is REAL array, dimension (N-2)
113 *> The (n-2) elements of the second superdiagonal of U.
118 *> IPIV is INTEGER array, dimension (N)
119 *> The pivot indices; for 1 <= i <= n, row i of the matrix was
120 *> interchanged with row IPIV(i). IPIV(i) will always be either
121 *> i or i+1; IPIV(i) = i indicates a row interchange was not
127 *> B is REAL array, dimension (LDB,NRHS)
128 *> The right hand side matrix B.
134 *> The leading dimension of the array B. LDB >= max(1,N).
139 *> X is REAL array, dimension (LDX,NRHS)
140 *> On entry, the solution matrix X, as computed by SGTTRS.
141 *> On exit, the improved solution matrix X.
147 *> The leading dimension of the array X. LDX >= max(1,N).
152 *> FERR is REAL array, dimension (NRHS)
153 *> The estimated forward error bound for each solution vector
154 *> X(j) (the j-th column of the solution matrix X).
155 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
156 *> is an estimated upper bound for the magnitude of the largest
157 *> element in (X(j) - XTRUE) divided by the magnitude of the
158 *> largest element in X(j). The estimate is as reliable as
159 *> the estimate for RCOND, and is almost always a slight
160 *> overestimate of the true error.
165 *> BERR is REAL array, dimension (NRHS)
166 *> The componentwise relative backward error of each solution
167 *> vector X(j) (i.e., the smallest relative change in
168 *> any element of A or B that makes X(j) an exact solution).
173 *> WORK is REAL array, dimension (3*N)
178 *> IWORK is INTEGER array, dimension (N)
184 *> = 0: successful exit
185 *> < 0: if INFO = -i, the i-th argument had an illegal value
188 *> \par Internal Parameters:
189 * =========================
192 *> ITMAX is the maximum number of steps of iterative refinement.
198 *> \author Univ. of Tennessee
199 *> \author Univ. of California Berkeley
200 *> \author Univ. of Colorado Denver
203 *> \date September 2012
205 *> \ingroup realGTcomputational
207 * =====================================================================
208 SUBROUTINE SGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2,
209 $ IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
212 * -- LAPACK computational routine (version 3.4.2) --
213 * -- LAPACK is a software package provided by Univ. of Tennessee, --
214 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
217 * .. Scalar Arguments ..
219 INTEGER INFO, LDB, LDX, N, NRHS
221 * .. Array Arguments ..
222 INTEGER IPIV( * ), IWORK( * )
223 REAL B( LDB, * ), BERR( * ), D( * ), DF( * ),
224 $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),
225 $ FERR( * ), WORK( * ), X( LDX, * )
228 * =====================================================================
232 PARAMETER ( ITMAX = 5 )
234 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
236 PARAMETER ( TWO = 2.0E+0 )
238 PARAMETER ( THREE = 3.0E+0 )
240 * .. Local Scalars ..
242 CHARACTER TRANSN, TRANST
243 INTEGER COUNT, I, J, KASE, NZ
244 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN
249 * .. External Subroutines ..
250 EXTERNAL SAXPY, SCOPY, SGTTRS, SLACN2, SLAGTM, XERBLA
252 * .. Intrinsic Functions ..
255 * .. External Functions ..
258 EXTERNAL LSAME, SLAMCH
260 * .. Executable Statements ..
262 * Test the input parameters.
265 NOTRAN = LSAME( TRANS, 'N' )
266 IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
267 $ LSAME( TRANS, 'C' ) ) THEN
269 ELSE IF( N.LT.0 ) THEN
271 ELSE IF( NRHS.LT.0 ) THEN
273 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
275 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
279 CALL XERBLA( 'SGTRFS', -INFO )
283 * Quick return if possible
285 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
301 * NZ = maximum number of nonzero elements in each row of A, plus 1
304 EPS = SLAMCH( 'Epsilon' )
305 SAFMIN = SLAMCH( 'Safe minimum' )
309 * Do for each right hand side
317 * Loop until stopping criterion is satisfied.
319 * Compute residual R = B - op(A) * X,
320 * where op(A) = A, A**T, or A**H, depending on TRANS.
322 CALL SCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
323 CALL SLAGTM( TRANS, N, 1, -ONE, DL, D, DU, X( 1, J ), LDX, ONE,
326 * Compute abs(op(A))*abs(x) + abs(b) for use in the backward
331 WORK( 1 ) = ABS( B( 1, J ) ) + ABS( D( 1 )*X( 1, J ) )
333 WORK( 1 ) = ABS( B( 1, J ) ) + ABS( D( 1 )*X( 1, J ) ) +
334 $ ABS( DU( 1 )*X( 2, J ) )
336 WORK( I ) = ABS( B( I, J ) ) +
337 $ ABS( DL( I-1 )*X( I-1, J ) ) +
338 $ ABS( D( I )*X( I, J ) ) +
339 $ ABS( DU( I )*X( I+1, J ) )
341 WORK( N ) = ABS( B( N, J ) ) +
342 $ ABS( DL( N-1 )*X( N-1, J ) ) +
343 $ ABS( D( N )*X( N, J ) )
347 WORK( 1 ) = ABS( B( 1, J ) ) + ABS( D( 1 )*X( 1, J ) )
349 WORK( 1 ) = ABS( B( 1, J ) ) + ABS( D( 1 )*X( 1, J ) ) +
350 $ ABS( DL( 1 )*X( 2, J ) )
352 WORK( I ) = ABS( B( I, J ) ) +
353 $ ABS( DU( I-1 )*X( I-1, J ) ) +
354 $ ABS( D( I )*X( I, J ) ) +
355 $ ABS( DL( I )*X( I+1, J ) )
357 WORK( N ) = ABS( B( N, J ) ) +
358 $ ABS( DU( N-1 )*X( N-1, J ) ) +
359 $ ABS( D( N )*X( N, J ) )
363 * Compute componentwise relative backward error from formula
365 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
367 * where abs(Z) is the componentwise absolute value of the matrix
368 * or vector Z. If the i-th component of the denominator is less
369 * than SAFE2, then SAFE1 is added to the i-th components of the
370 * numerator and denominator before dividing.
374 IF( WORK( I ).GT.SAFE2 ) THEN
375 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
377 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
378 $ ( WORK( I )+SAFE1 ) )
383 * Test stopping criterion. Continue iterating if
384 * 1) The residual BERR(J) is larger than machine epsilon, and
385 * 2) BERR(J) decreased by at least a factor of 2 during the
386 * last iteration, and
387 * 3) At most ITMAX iterations tried.
389 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
390 $ COUNT.LE.ITMAX ) THEN
392 * Update solution and try again.
394 CALL SGTTRS( TRANS, N, 1, DLF, DF, DUF, DU2, IPIV,
395 $ WORK( N+1 ), N, INFO )
396 CALL SAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
402 * Bound error from formula
404 * norm(X - XTRUE) / norm(X) .le. FERR =
405 * norm( abs(inv(op(A)))*
406 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
409 * norm(Z) is the magnitude of the largest component of Z
410 * inv(op(A)) is the inverse of op(A)
411 * abs(Z) is the componentwise absolute value of the matrix or
413 * NZ is the maximum number of nonzeros in any row of A, plus 1
414 * EPS is machine epsilon
416 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
417 * is incremented by SAFE1 if the i-th component of
418 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
420 * Use SLACN2 to estimate the infinity-norm of the matrix
421 * inv(op(A)) * diag(W),
422 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
425 IF( WORK( I ).GT.SAFE2 ) THEN
426 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
428 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
434 CALL SLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
439 * Multiply by diag(W)*inv(op(A)**T).
441 CALL SGTTRS( TRANST, N, 1, DLF, DF, DUF, DU2, IPIV,
442 $ WORK( N+1 ), N, INFO )
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 SGTTRS( TRANSN, N, 1, DLF, DF, DUF, DU2, IPIV,
454 $ WORK( N+1 ), N, INFO )
463 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
466 $ FERR( J ) = FERR( J ) / LSTRES