3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SGBRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgbrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgbrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgbrfs.f">
21 * SUBROUTINE SGBRFS( TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, LDAFB,
22 * IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
25 * .. Scalar Arguments ..
27 * INTEGER INFO, KL, KU, LDAB, LDAFB, LDB, LDX, N, NRHS
29 * .. Array Arguments ..
30 * INTEGER IPIV( * ), IWORK( * )
31 * REAL AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
32 * $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
41 *> SGBRFS improves the computed solution to a system of linear
42 *> equations when the coefficient matrix is banded, and provides
43 *> error bounds and backward error estimates for the solution.
51 *> TRANS is CHARACTER*1
52 *> Specifies the form of the system of equations:
53 *> = 'N': A * X = B (No transpose)
54 *> = 'T': A**T * X = B (Transpose)
55 *> = 'C': A**H * X = B (Conjugate transpose = Transpose)
61 *> The order of the matrix A. N >= 0.
67 *> The number of subdiagonals within the band of A. KL >= 0.
73 *> The number of superdiagonals within the band of A. KU >= 0.
79 *> The number of right hand sides, i.e., the number of columns
80 *> of the matrices B and X. NRHS >= 0.
85 *> AB is REAL array, dimension (LDAB,N)
86 *> The original band matrix A, stored in rows 1 to KL+KU+1.
87 *> The j-th column of A is stored in the j-th column of the
88 *> array AB as follows:
89 *> AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl).
95 *> The leading dimension of the array AB. LDAB >= KL+KU+1.
100 *> AFB is REAL array, dimension (LDAFB,N)
101 *> Details of the LU factorization of the band matrix A, as
102 *> computed by SGBTRF. U is stored as an upper triangular band
103 *> matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and
104 *> the multipliers used during the factorization are stored in
105 *> rows KL+KU+2 to 2*KL+KU+1.
111 *> The leading dimension of the array AFB. LDAFB >= 2*KL*KU+1.
116 *> IPIV is INTEGER array, dimension (N)
117 *> The pivot indices from SGBTRF; for 1<=i<=N, row i of the
118 *> matrix was interchanged with row IPIV(i).
123 *> B is REAL array, dimension (LDB,NRHS)
124 *> The right hand side matrix B.
130 *> The leading dimension of the array B. LDB >= max(1,N).
135 *> X is REAL array, dimension (LDX,NRHS)
136 *> On entry, the solution matrix X, as computed by SGBTRS.
137 *> On exit, the improved solution matrix X.
143 *> The leading dimension of the array X. LDX >= max(1,N).
148 *> FERR is REAL array, dimension (NRHS)
149 *> The estimated forward error bound for each solution vector
150 *> X(j) (the j-th column of the solution matrix X).
151 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
152 *> is an estimated upper bound for the magnitude of the largest
153 *> element in (X(j) - XTRUE) divided by the magnitude of the
154 *> largest element in X(j). The estimate is as reliable as
155 *> the estimate for RCOND, and is almost always a slight
156 *> overestimate of the true error.
161 *> BERR is REAL array, dimension (NRHS)
162 *> The componentwise relative backward error of each solution
163 *> vector X(j) (i.e., the smallest relative change in
164 *> any element of A or B that makes X(j) an exact solution).
169 *> WORK is REAL array, dimension (3*N)
174 *> IWORK is INTEGER array, dimension (N)
180 *> = 0: successful exit
181 *> < 0: if INFO = -i, the i-th argument had an illegal value
184 *> \par Internal Parameters:
185 * =========================
188 *> ITMAX is the maximum number of steps of iterative refinement.
194 *> \author Univ. of Tennessee
195 *> \author Univ. of California Berkeley
196 *> \author Univ. of Colorado Denver
199 *> \date November 2011
201 *> \ingroup realGBcomputational
203 * =====================================================================
204 SUBROUTINE SGBRFS( TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, LDAFB,
205 $ IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
208 * -- LAPACK computational routine (version 3.4.0) --
209 * -- LAPACK is a software package provided by Univ. of Tennessee, --
210 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
213 * .. Scalar Arguments ..
215 INTEGER INFO, KL, KU, LDAB, LDAFB, LDB, LDX, N, NRHS
217 * .. Array Arguments ..
218 INTEGER IPIV( * ), IWORK( * )
219 REAL AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
220 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
223 * =====================================================================
227 PARAMETER ( ITMAX = 5 )
229 PARAMETER ( ZERO = 0.0E+0 )
231 PARAMETER ( ONE = 1.0E+0 )
233 PARAMETER ( TWO = 2.0E+0 )
235 PARAMETER ( THREE = 3.0E+0 )
237 * .. Local Scalars ..
240 INTEGER COUNT, I, J, K, KASE, KK, NZ
241 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
246 * .. External Subroutines ..
247 EXTERNAL SAXPY, SCOPY, SGBMV, SGBTRS, SLACN2, XERBLA
249 * .. Intrinsic Functions ..
250 INTRINSIC ABS, MAX, MIN
252 * .. External Functions ..
255 EXTERNAL LSAME, SLAMCH
257 * .. Executable Statements ..
259 * Test the input parameters.
262 NOTRAN = LSAME( TRANS, 'N' )
263 IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
264 $ LSAME( TRANS, 'C' ) ) THEN
266 ELSE IF( N.LT.0 ) THEN
268 ELSE IF( KL.LT.0 ) THEN
270 ELSE IF( KU.LT.0 ) THEN
272 ELSE IF( NRHS.LT.0 ) THEN
274 ELSE IF( LDAB.LT.KL+KU+1 ) THEN
276 ELSE IF( LDAFB.LT.2*KL+KU+1 ) THEN
278 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
280 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
284 CALL XERBLA( 'SGBRFS', -INFO )
288 * Quick return if possible
290 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
304 * NZ = maximum number of nonzero elements in each row of A, plus 1
306 NZ = MIN( KL+KU+2, N+1 )
307 EPS = SLAMCH( 'Epsilon' )
308 SAFMIN = SLAMCH( 'Safe minimum' )
312 * Do for each right hand side
320 * Loop until stopping criterion is satisfied.
322 * Compute residual R = B - op(A) * X,
323 * where op(A) = A, A**T, or A**H, depending on TRANS.
325 CALL SCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
326 CALL SGBMV( TRANS, N, N, KL, KU, -ONE, AB, LDAB, X( 1, J ), 1,
327 $ ONE, WORK( N+1 ), 1 )
329 * Compute componentwise relative backward error from formula
331 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
333 * where abs(Z) is the componentwise absolute value of the matrix
334 * or vector Z. If the i-th component of the denominator is less
335 * than SAFE2, then SAFE1 is added to the i-th components of the
336 * numerator and denominator before dividing.
339 WORK( I ) = ABS( B( I, J ) )
342 * Compute abs(op(A))*abs(X) + abs(B).
347 XK = ABS( X( K, J ) )
348 DO 40 I = MAX( 1, K-KU ), MIN( N, K+KL )
349 WORK( I ) = WORK( I ) + ABS( AB( KK+I, K ) )*XK
356 DO 60 I = MAX( 1, K-KU ), MIN( N, K+KL )
357 S = S + ABS( AB( KK+I, K ) )*ABS( X( I, J ) )
359 WORK( K ) = WORK( K ) + S
364 IF( WORK( I ).GT.SAFE2 ) THEN
365 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
367 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
368 $ ( WORK( I )+SAFE1 ) )
373 * Test stopping criterion. Continue iterating if
374 * 1) The residual BERR(J) is larger than machine epsilon, and
375 * 2) BERR(J) decreased by at least a factor of 2 during the
376 * last iteration, and
377 * 3) At most ITMAX iterations tried.
379 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
380 $ COUNT.LE.ITMAX ) THEN
382 * Update solution and try again.
384 CALL SGBTRS( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV,
385 $ WORK( N+1 ), N, INFO )
386 CALL SAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
392 * Bound error from formula
394 * norm(X - XTRUE) / norm(X) .le. FERR =
395 * norm( abs(inv(op(A)))*
396 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
399 * norm(Z) is the magnitude of the largest component of Z
400 * inv(op(A)) is the inverse of op(A)
401 * abs(Z) is the componentwise absolute value of the matrix or
403 * NZ is the maximum number of nonzeros in any row of A, plus 1
404 * EPS is machine epsilon
406 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
407 * is incremented by SAFE1 if the i-th component of
408 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
410 * Use SLACN2 to estimate the infinity-norm of the matrix
411 * inv(op(A)) * diag(W),
412 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
415 IF( WORK( I ).GT.SAFE2 ) THEN
416 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
418 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
424 CALL SLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
429 * Multiply by diag(W)*inv(op(A)**T).
431 CALL SGBTRS( TRANST, N, KL, KU, 1, AFB, LDAFB, IPIV,
432 $ WORK( N+1 ), N, INFO )
434 WORK( N+I ) = WORK( N+I )*WORK( I )
438 * Multiply by inv(op(A))*diag(W).
441 WORK( N+I ) = WORK( N+I )*WORK( I )
443 CALL SGBTRS( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV,
444 $ WORK( N+1 ), N, INFO )
453 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
456 $ FERR( J ) = FERR( J ) / LSTRES