LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ sgtrfs()

subroutine sgtrfs ( character trans,
integer n,
integer nrhs,
real, dimension( * ) dl,
real, dimension( * ) d,
real, dimension( * ) du,
real, dimension( * ) dlf,
real, dimension( * ) df,
real, dimension( * ) duf,
real, dimension( * ) du2,
integer, dimension( * ) ipiv,
real, dimension( ldb, * ) b,
integer ldb,
real, dimension( ldx, * ) x,
integer ldx,
real, dimension( * ) ferr,
real, dimension( * ) berr,
real, dimension( * ) work,
integer, dimension( * ) iwork,
integer info )

SGTRFS

Download SGTRFS + dependencies [TGZ] [ZIP] [TXT]

Purpose:
!>
!> SGTRFS improves the computed solution to a system of linear
!> equations when the coefficient matrix is tridiagonal, and provides
!> error bounds and backward error estimates for the solution.
!> 
Parameters
[in]TRANS
!>          TRANS is CHARACTER*1
!>          Specifies the form of the system of equations:
!>          = 'N':  A * X = B     (No transpose)
!>          = 'T':  A**T * X = B  (Transpose)
!>          = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
!> 
[in]N
!>          N is INTEGER
!>          The order of the matrix A.  N >= 0.
!> 
[in]NRHS
!>          NRHS is INTEGER
!>          The number of right hand sides, i.e., the number of columns
!>          of the matrix B.  NRHS >= 0.
!> 
[in]DL
!>          DL is REAL array, dimension (N-1)
!>          The (n-1) subdiagonal elements of A.
!> 
[in]D
!>          D is REAL array, dimension (N)
!>          The diagonal elements of A.
!> 
[in]DU
!>          DU is REAL array, dimension (N-1)
!>          The (n-1) superdiagonal elements of A.
!> 
[in]DLF
!>          DLF is REAL array, dimension (N-1)
!>          The (n-1) multipliers that define the matrix L from the
!>          LU factorization of A as computed by SGTTRF.
!> 
[in]DF
!>          DF is REAL array, dimension (N)
!>          The n diagonal elements of the upper triangular matrix U from
!>          the LU factorization of A.
!> 
[in]DUF
!>          DUF is REAL array, dimension (N-1)
!>          The (n-1) elements of the first superdiagonal of U.
!> 
[in]DU2
!>          DU2 is REAL array, dimension (N-2)
!>          The (n-2) elements of the second superdiagonal of U.
!> 
[in]IPIV
!>          IPIV is INTEGER array, dimension (N)
!>          The pivot indices; for 1 <= i <= n, row i of the matrix was
!>          interchanged with row IPIV(i).  IPIV(i) will always be either
!>          i or i+1; IPIV(i) = i indicates a row interchange was not
!>          required.
!> 
[in]B
!>          B is REAL array, dimension (LDB,NRHS)
!>          The right hand side matrix B.
!> 
[in]LDB
!>          LDB is INTEGER
!>          The leading dimension of the array B.  LDB >= max(1,N).
!> 
[in,out]X
!>          X is REAL array, dimension (LDX,NRHS)
!>          On entry, the solution matrix X, as computed by SGTTRS.
!>          On exit, the improved solution matrix X.
!> 
[in]LDX
!>          LDX is INTEGER
!>          The leading dimension of the array X.  LDX >= max(1,N).
!> 
[out]FERR
!>          FERR is REAL array, dimension (NRHS)
!>          The estimated forward error bound for each solution vector
!>          X(j) (the j-th column of the solution matrix X).
!>          If XTRUE is the true solution corresponding to X(j), FERR(j)
!>          is an estimated upper bound for the magnitude of the largest
!>          element in (X(j) - XTRUE) divided by the magnitude of the
!>          largest element in X(j).  The estimate is as reliable as
!>          the estimate for RCOND, and is almost always a slight
!>          overestimate of the true error.
!> 
[out]BERR
!>          BERR is REAL array, dimension (NRHS)
!>          The componentwise relative backward error of each solution
!>          vector X(j) (i.e., the smallest relative change in
!>          any element of A or B that makes X(j) an exact solution).
!> 
[out]WORK
!>          WORK is REAL array, dimension (3*N)
!> 
[out]IWORK
!>          IWORK is INTEGER array, dimension (N)
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit
!>          < 0:  if INFO = -i, the i-th argument had an illegal value
!> 
Internal Parameters:
!>  ITMAX is the maximum number of steps of iterative refinement.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 204 of file sgtrfs.f.

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*
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 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
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
logical function lsame(ca, cb)
LSAME
Definition lsame.f:48
Here is the call graph for this function:
Here is the caller graph for this function: