LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
sgtrfs.f
Go to the documentation of this file.
1*> \brief \b SGTRFS
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download SGTRFS + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgtrfs.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgtrfs.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgtrfs.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE SGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2,
20* IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
21* INFO )
22*
23* .. Scalar Arguments ..
24* CHARACTER TRANS
25* INTEGER INFO, LDB, LDX, N, NRHS
26* ..
27* .. Array Arguments ..
28* INTEGER IPIV( * ), IWORK( * )
29* REAL B( LDB, * ), BERR( * ), D( * ), DF( * ),
30* $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),
31* $ FERR( * ), WORK( * ), X( LDX, * )
32* ..
33*
34*
35*> \par Purpose:
36* =============
37*>
38*> \verbatim
39*>
40*> SGTRFS improves the computed solution to a system of linear
41*> equations when the coefficient matrix is tridiagonal, and provides
42*> error bounds and backward error estimates for the solution.
43*> \endverbatim
44*
45* Arguments:
46* ==========
47*
48*> \param[in] TRANS
49*> \verbatim
50*> TRANS is CHARACTER*1
51*> Specifies the form of the system of equations:
52*> = 'N': A * X = B (No transpose)
53*> = 'T': A**T * X = B (Transpose)
54*> = 'C': A**H * X = B (Conjugate transpose = Transpose)
55*> \endverbatim
56*>
57*> \param[in] N
58*> \verbatim
59*> N is INTEGER
60*> The order of the matrix A. N >= 0.
61*> \endverbatim
62*>
63*> \param[in] NRHS
64*> \verbatim
65*> NRHS is INTEGER
66*> The number of right hand sides, i.e., the number of columns
67*> of the matrix B. NRHS >= 0.
68*> \endverbatim
69*>
70*> \param[in] DL
71*> \verbatim
72*> DL is REAL array, dimension (N-1)
73*> The (n-1) subdiagonal elements of A.
74*> \endverbatim
75*>
76*> \param[in] D
77*> \verbatim
78*> D is REAL array, dimension (N)
79*> The diagonal elements of A.
80*> \endverbatim
81*>
82*> \param[in] DU
83*> \verbatim
84*> DU is REAL array, dimension (N-1)
85*> The (n-1) superdiagonal elements of A.
86*> \endverbatim
87*>
88*> \param[in] DLF
89*> \verbatim
90*> DLF is REAL array, dimension (N-1)
91*> The (n-1) multipliers that define the matrix L from the
92*> LU factorization of A as computed by SGTTRF.
93*> \endverbatim
94*>
95*> \param[in] DF
96*> \verbatim
97*> DF is REAL array, dimension (N)
98*> The n diagonal elements of the upper triangular matrix U from
99*> the LU factorization of A.
100*> \endverbatim
101*>
102*> \param[in] DUF
103*> \verbatim
104*> DUF is REAL array, dimension (N-1)
105*> The (n-1) elements of the first superdiagonal of U.
106*> \endverbatim
107*>
108*> \param[in] DU2
109*> \verbatim
110*> DU2 is REAL array, dimension (N-2)
111*> The (n-2) elements of the second superdiagonal of U.
112*> \endverbatim
113*>
114*> \param[in] IPIV
115*> \verbatim
116*> IPIV is INTEGER array, dimension (N)
117*> The pivot indices; for 1 <= i <= n, row i of the matrix was
118*> interchanged with row IPIV(i). IPIV(i) will always be either
119*> i or i+1; IPIV(i) = i indicates a row interchange was not
120*> required.
121*> \endverbatim
122*>
123*> \param[in] B
124*> \verbatim
125*> B is REAL array, dimension (LDB,NRHS)
126*> The right hand side matrix B.
127*> \endverbatim
128*>
129*> \param[in] LDB
130*> \verbatim
131*> LDB is INTEGER
132*> The leading dimension of the array B. LDB >= max(1,N).
133*> \endverbatim
134*>
135*> \param[in,out] X
136*> \verbatim
137*> X is REAL array, dimension (LDX,NRHS)
138*> On entry, the solution matrix X, as computed by SGTTRS.
139*> On exit, the improved solution matrix X.
140*> \endverbatim
141*>
142*> \param[in] LDX
143*> \verbatim
144*> LDX is INTEGER
145*> The leading dimension of the array X. LDX >= max(1,N).
146*> \endverbatim
147*>
148*> \param[out] FERR
149*> \verbatim
150*> FERR is REAL array, dimension (NRHS)
151*> The estimated forward error bound for each solution vector
152*> X(j) (the j-th column of the solution matrix X).
153*> If XTRUE is the true solution corresponding to X(j), FERR(j)
154*> is an estimated upper bound for the magnitude of the largest
155*> element in (X(j) - XTRUE) divided by the magnitude of the
156*> largest element in X(j). The estimate is as reliable as
157*> the estimate for RCOND, and is almost always a slight
158*> overestimate of the true error.
159*> \endverbatim
160*>
161*> \param[out] BERR
162*> \verbatim
163*> BERR is REAL array, dimension (NRHS)
164*> The componentwise relative backward error of each solution
165*> vector X(j) (i.e., the smallest relative change in
166*> any element of A or B that makes X(j) an exact solution).
167*> \endverbatim
168*>
169*> \param[out] WORK
170*> \verbatim
171*> WORK is REAL array, dimension (3*N)
172*> \endverbatim
173*>
174*> \param[out] IWORK
175*> \verbatim
176*> IWORK is INTEGER array, dimension (N)
177*> \endverbatim
178*>
179*> \param[out] INFO
180*> \verbatim
181*> INFO is INTEGER
182*> = 0: successful exit
183*> < 0: if INFO = -i, the i-th argument had an illegal value
184*> \endverbatim
185*
186*> \par Internal Parameters:
187* =========================
188*>
189*> \verbatim
190*> ITMAX is the maximum number of steps of iterative refinement.
191*> \endverbatim
192*
193* Authors:
194* ========
195*
196*> \author Univ. of Tennessee
197*> \author Univ. of California Berkeley
198*> \author Univ. of Colorado Denver
199*> \author NAG Ltd.
200*
201*> \ingroup gtrfs
202*
203* =====================================================================
204 SUBROUTINE sgtrfs( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF,
205 $ DU2,
206 $ IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
207 $ INFO )
208*
209* -- LAPACK computational routine --
210* -- LAPACK is a software package provided by Univ. of Tennessee, --
211* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
212*
213* .. Scalar Arguments ..
214 CHARACTER TRANS
215 INTEGER INFO, LDB, LDX, N, NRHS
216* ..
217* .. Array Arguments ..
218 INTEGER IPIV( * ), IWORK( * )
219 REAL B( LDB, * ), BERR( * ), D( * ), DF( * ),
220 $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),
221 $ ferr( * ), work( * ), x( ldx, * )
222* ..
223*
224* =====================================================================
225*
226* .. Parameters ..
227 INTEGER ITMAX
228 PARAMETER ( ITMAX = 5 )
229 real zero, one
230 parameter( zero = 0.0e+0, one = 1.0e+0 )
231 REAL TWO
232 parameter( two = 2.0e+0 )
233 REAL THREE
234 parameter( three = 3.0e+0 )
235* ..
236* .. Local Scalars ..
237 LOGICAL NOTRAN
238 CHARACTER TRANSN, TRANST
239 INTEGER COUNT, I, J, KASE, NZ
240 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN
241* ..
242* .. Local Arrays ..
243 INTEGER ISAVE( 3 )
244* ..
245* .. External Subroutines ..
246 EXTERNAL saxpy, scopy, sgttrs, slacn2, slagtm,
247 $ xerbla
248* ..
249* .. Intrinsic Functions ..
250 INTRINSIC abs, max
251* ..
252* .. External Functions ..
253 LOGICAL LSAME
254 REAL SLAMCH
255 EXTERNAL LSAME, SLAMCH
256* ..
257* .. Executable Statements ..
258*
259* Test the input parameters.
260*
261 info = 0
262 notran = lsame( trans, 'N' )
263 IF( .NOT.notran .AND. .NOT.lsame( trans, 'T' ) .AND. .NOT.
264 $ lsame( trans, 'C' ) ) THEN
265 info = -1
266 ELSE IF( n.LT.0 ) THEN
267 info = -2
268 ELSE IF( nrhs.LT.0 ) THEN
269 info = -3
270 ELSE IF( ldb.LT.max( 1, n ) ) THEN
271 info = -13
272 ELSE IF( ldx.LT.max( 1, n ) ) THEN
273 info = -15
274 END IF
275 IF( info.NE.0 ) THEN
276 CALL xerbla( 'SGTRFS', -info )
277 RETURN
278 END IF
279*
280* Quick return if possible
281*
282 IF( n.EQ.0 .OR. nrhs.EQ.0 ) THEN
283 DO 10 j = 1, nrhs
284 ferr( j ) = zero
285 berr( j ) = zero
286 10 CONTINUE
287 RETURN
288 END IF
289*
290 IF( notran ) THEN
291 transn = 'N'
292 transt = 'T'
293 ELSE
294 transn = 'T'
295 transt = 'N'
296 END IF
297*
298* NZ = maximum number of nonzero elements in each row of A, plus 1
299*
300 nz = 4
301 eps = slamch( 'Epsilon' )
302 safmin = slamch( 'Safe minimum' )
303 safe1 = real( nz )*safmin
304 safe2 = safe1 / eps
305*
306* Do for each right hand side
307*
308 DO 110 j = 1, nrhs
309*
310 count = 1
311 lstres = three
312 20 CONTINUE
313*
314* Loop until stopping criterion is satisfied.
315*
316* Compute residual R = B - op(A) * X,
317* where op(A) = A, A**T, or A**H, depending on TRANS.
318*
319 CALL scopy( n, b( 1, j ), 1, work( n+1 ), 1 )
320 CALL slagtm( trans, n, 1, -one, dl, d, du, x( 1, j ), ldx,
321 $ one,
322 $ work( n+1 ), n )
323*
324* Compute abs(op(A))*abs(x) + abs(b) for use in the backward
325* error bound.
326*
327 IF( notran ) THEN
328 IF( n.EQ.1 ) THEN
329 work( 1 ) = abs( b( 1, j ) ) + abs( d( 1 )*x( 1, j ) )
330 ELSE
331 work( 1 ) = abs( b( 1, j ) ) + abs( d( 1 )*x( 1, j ) ) +
332 $ abs( du( 1 )*x( 2, j ) )
333 DO 30 i = 2, n - 1
334 work( i ) = abs( b( i, j ) ) +
335 $ abs( dl( i-1 )*x( i-1, j ) ) +
336 $ abs( d( i )*x( i, j ) ) +
337 $ abs( du( i )*x( i+1, j ) )
338 30 CONTINUE
339 work( n ) = abs( b( n, j ) ) +
340 $ abs( dl( n-1 )*x( n-1, j ) ) +
341 $ abs( d( n )*x( n, j ) )
342 END IF
343 ELSE
344 IF( n.EQ.1 ) THEN
345 work( 1 ) = abs( b( 1, j ) ) + abs( d( 1 )*x( 1, j ) )
346 ELSE
347 work( 1 ) = abs( b( 1, j ) ) + abs( d( 1 )*x( 1, j ) ) +
348 $ abs( dl( 1 )*x( 2, j ) )
349 DO 40 i = 2, n - 1
350 work( i ) = abs( b( i, j ) ) +
351 $ abs( du( i-1 )*x( i-1, j ) ) +
352 $ abs( d( i )*x( i, j ) ) +
353 $ abs( dl( i )*x( i+1, j ) )
354 40 CONTINUE
355 work( n ) = abs( b( n, j ) ) +
356 $ abs( du( n-1 )*x( n-1, j ) ) +
357 $ abs( d( n )*x( n, j ) )
358 END IF
359 END IF
360*
361* Compute componentwise relative backward error from formula
362*
363* max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
364*
365* where abs(Z) is the componentwise absolute value of the matrix
366* or vector Z. If the i-th component of the denominator is less
367* than SAFE2, then SAFE1 is added to the i-th components of the
368* numerator and denominator before dividing.
369*
370 s = zero
371 DO 50 i = 1, n
372 IF( work( i ).GT.safe2 ) THEN
373 s = max( s, abs( work( n+i ) ) / work( i ) )
374 ELSE
375 s = max( s, ( abs( work( n+i ) )+safe1 ) /
376 $ ( work( i )+safe1 ) )
377 END IF
378 50 CONTINUE
379 berr( j ) = s
380*
381* Test stopping criterion. Continue iterating if
382* 1) The residual BERR(J) is larger than machine epsilon, and
383* 2) BERR(J) decreased by at least a factor of 2 during the
384* last iteration, and
385* 3) At most ITMAX iterations tried.
386*
387 IF( berr( j ).GT.eps .AND. two*berr( j ).LE.lstres .AND.
388 $ count.LE.itmax ) THEN
389*
390* Update solution and try again.
391*
392 CALL sgttrs( trans, n, 1, dlf, df, duf, du2, ipiv,
393 $ work( n+1 ), n, info )
394 CALL saxpy( n, one, work( n+1 ), 1, x( 1, j ), 1 )
395 lstres = berr( j )
396 count = count + 1
397 GO TO 20
398 END IF
399*
400* Bound error from formula
401*
402* norm(X - XTRUE) / norm(X) .le. FERR =
403* norm( abs(inv(op(A)))*
404* ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
405*
406* where
407* norm(Z) is the magnitude of the largest component of Z
408* inv(op(A)) is the inverse of op(A)
409* abs(Z) is the componentwise absolute value of the matrix or
410* vector Z
411* NZ is the maximum number of nonzeros in any row of A, plus 1
412* EPS is machine epsilon
413*
414* The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
415* is incremented by SAFE1 if the i-th component of
416* abs(op(A))*abs(X) + abs(B) is less than SAFE2.
417*
418* Use SLACN2 to estimate the infinity-norm of the matrix
419* inv(op(A)) * diag(W),
420* where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
421*
422 DO 60 i = 1, n
423 IF( work( i ).GT.safe2 ) THEN
424 work( i ) = abs( work( n+i ) ) + real( nz )*eps*work( i )
425 ELSE
426 work( i ) = abs( work( n+i ) ) + real( nz )*eps*work( i )
427 $ + safe1
428 END IF
429 60 CONTINUE
430*
431 kase = 0
432 70 CONTINUE
433 CALL slacn2( n, work( 2*n+1 ), work( n+1 ), iwork,
434 $ ferr( j ),
435 $ kase, isave )
436 IF( kase.NE.0 ) THEN
437 IF( kase.EQ.1 ) THEN
438*
439* Multiply by diag(W)*inv(op(A)**T).
440*
441 CALL sgttrs( transt, n, 1, dlf, df, duf, du2, ipiv,
442 $ work( n+1 ), n, info )
443 DO 80 i = 1, n
444 work( n+i ) = work( i )*work( n+i )
445 80 CONTINUE
446 ELSE
447*
448* Multiply by inv(op(A))*diag(W).
449*
450 DO 90 i = 1, n
451 work( n+i ) = work( i )*work( n+i )
452 90 CONTINUE
453 CALL sgttrs( transn, n, 1, dlf, df, duf, du2, ipiv,
454 $ work( n+1 ), n, info )
455 END IF
456 GO TO 70
457 END IF
458*
459* Normalize error.
460*
461 lstres = zero
462 DO 100 i = 1, n
463 lstres = max( lstres, abs( x( i, j ) ) )
464 100 CONTINUE
465 IF( lstres.NE.zero )
466 $ ferr( j ) = ferr( j ) / lstres
467*
468 110 CONTINUE
469*
470 RETURN
471*
472* End of SGTRFS
473*
474 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine saxpy(n, sa, sx, incx, sy, incy)
SAXPY
Definition saxpy.f:89
subroutine scopy(n, sx, incx, sy, incy)
SCOPY
Definition scopy.f:82
subroutine sgtrfs(trans, n, nrhs, dl, d, du, dlf, df, duf, du2, ipiv, b, ldb, x, ldx, ferr, berr, work, iwork, info)
SGTRFS
Definition sgtrfs.f:208
subroutine sgttrs(trans, n, nrhs, dl, d, du, du2, ipiv, b, ldb, info)
SGTTRS
Definition sgttrs.f:137
subroutine slacn2(n, v, x, isgn, est, kase, isave)
SLACN2 estimates the 1-norm of a square matrix, using reverse communication for evaluating matrix-vec...
Definition slacn2.f:134
subroutine slagtm(trans, n, nrhs, alpha, dl, d, du, x, ldx, beta, b, ldb)
SLAGTM performs a matrix-matrix product of the form C = αAB+βC, where A is a tridiagonal matrix,...
Definition slagtm.f:144