Previous Next Contents Generated Index Doc Set Home



Refined Solution to a Linear System in an LU-Factored General Tridiagonal Matrix

The subroutines described in this section refine the solution to a tridiagonal linear system AX = B, ATX = B, or AHX = B for a tridiagonal matrix A, which has been LU-factored by xGTTRF, and general matrices B and X. These subroutines also compute forward error bounds and backward error estimates on the solution.

Calling Sequence

CALL DGTRFS 
(TRANSA, N, NRHS, DLOW, DDIAG, DUP, DLOWF, DDIAGF, 
DUPF1, DUPF2, IPIVOT, DB, LDB, DX, LDX, DFERR, DBERR, 
DWORK, IWORK2, INFO)
CALL SGTRFS 
(TRANSA, N, NRHS, SLOW, SDIAG, SUP, SLOWF, SDIAGF, 
SUPF1, SUPF2, IPIVOT, SB, LDB, SX, LDX, SFERR, SBERR, 
SWORK, IWORK2, INFO)
CALL ZGTRFS 
(TRANSA, N, NRHS, ZLOW, ZDIAG, ZUP, ZLOWF, ZDIAGF, 
ZUPF1, ZUPF2, IPIVOT, ZB, LDB, ZX, LDX, DFERR, DBERR, 
ZWORK, DWORK2, INFO)
CALL CGTRFS 
(TRANSA, N, NRHS, CLOW, CDIAG, CUP, CLOWF, CDIAGF, 
CUPF1, CUPF2, IPIVOT, CB, LDB, CX, LDX, SFERR, SBERR, 
CWORK, SWORK2, INFO)






void dgtrfs 
(char trans, int n, int nrhs, double *dlow, double 
*ddiag, double *dup, double *dlowf, double *ddiagf, 
double *dupf1, double *dupf2, int *ipivot, double *db, 
int ldb, double *dx, int ldx, double *dferr, double 
*dberr, int *info)
void sgtrfs 
(char trans, int n, int nrhs, float *slow, float 
*sdiag, float *sup, float *slowf, float *sdiagf, float 
*supf1, float *supf2, int *ipivot, float *sb, int ldb, 
float *sx, int ldx, float *sferr, float *sberr, int 
*info)
void zgtrfs 
(char trans, int n, int nrhs, doublecomplex *zlow, 
doublecomplex *zdiag, doublecomplex *zup, 
doublecomplex *zlowf, doublecomplex *zdiagf, 
doublecomplex *zupf1, doublecomplex *zupf2, int 
*ipivot, doublecomplex *zb, int ldb, doublecomplex 
*zx, int ldx, double *dferr, double *dberr, int *info)
void cgtrfs 
(char trans, int n, int nrhs, complex *clow, complex 
*cdiag, complex *cup, complex *clowf, complex *cdiagf, 
complex *cupf1, complex *cupf2, int *ipivot, complex 
*cb, int ldb, complex *cx, int ldx, float *sferr, float 
*sberr, int *info)

Arguments

TRANSA

Indicates the form of the linear system whose solution is to be refined. The legal values for TRANSA are listed below. Any values not listed below are illegal.

'N' or 'n'

No transpose, refine AX = B.

'T' or 't'

Transpose, refine ATX = B.

'C' or 'c'

Conjugate transpose, refine AHX = B.

Note that AT and AH are the same for real matrices.

N

Order of the matrix A. N 0.

NRHS

Number of right-hand sides, equal to the number of columns of the matrices B and X. NRHS 0.

xLOW

The N-1 elements of the first subdiagonal of A.

xDIAG

The N diagonal elements of A.

xUP

The N-1 elements of the first superdiagonal A.

xLOWF

The N-1 multipliers that define the matrix L from the LU factorization of A, as computed by xGTTRF.

xDIAGF

The N diagonal elements of the upper triangular matrix U from the LU factorization of A, as computed by xGTTRF.

xUPF1

The N-1 elements of the first superdiagonal of U from the LU factorization of A, as computed by xGTTRF.

xUPF2

The N-2 elements of the second superdiagonal of U from the LU factorization of A, as computed by xGTTRF.

IPIVOT

Pivot indices as computed by xGTTRF.

xB

The N×NRHS right-hand side matrix B.

LDB

Leading dimension of the array B as specified in a dimension or type statement. LDB max(1, N).

xX

On entry, the N×NRHS solution matrix X.
On exit, the refined N×NRHS solution matrix X.

LDX

Leading dimension of the array X as specified in a dimension or type statement. LDX max(1, N).

xFERR

On exit, the estimated forward error bound for each solution vector X(*, j) for 1 j NRHS. If X' is the true solution corresponding to
X(*, j) then FERR(j) is an upper bound on the magnitude of the largest element in X(*, j) - X' divided by the magnitude of the largest element in X(*, j).

xBERR

On exit, BERR(j) is the smallest relative change in any element of A or B(*, j) that makes X(*, j) an exact solution to AX(*, j) = B(*, j) for 1 j NRHS.

xWORK

Scratch array with a dimension of 3 × N for real subroutines or 2 × N for complex subroutines.

xWORK2

Scratch array with a dimension of N.

INFO

On exit:

INFO = 0

Subroutine completed normally.

INFO < 0

The ith argument, where i = |INFO|, had an illegal value.

Sample Program




      PROGRAM TEST
      IMPLICIT NONE
C
      INTEGER           LDB, LDIWRK, LDWORK, LDX, N, NRHS
      PARAMETER        (N = 4)
      PARAMETER        (LDB = N)
      PARAMETER        (LDIWRK = N)
      PARAMETER        (LDWORK = 3 * N)
      PARAMETER        (LDX = N)
      PARAMETER        (NRHS = 1)
C
      DOUBLE PRECISION  ANORM, B(LDB,NRHS), BERR(NRHS), DIAG(N)
      DOUBLE PRECISION  DIAGF(N), DLOW(N-1), DLOWF(N-1), DUP1(N-1)
      DOUBLE PRECISION  DUP1F(N-1), DUP2F(N-2), EPSLON, FERR(NRHS)
      DOUBLE PRECISION  RCOND, WORK(LDWORK), X(LDX,NRHS)
      INTEGER           ICOL, INFO, IPIVOT(N), IROW, IWORK(LDIWRK)
C
      EXTERNAL          DCOPY, DGTCON, DGTRFS, DGTTRF, DGTTRS
      INTRINSIC         ABS, MAX
C
C     Initialize the arrays DLOW, DIAG, and DUP1 to store
C     the first subdiagonal, the diagonal, and the first
C     superdiagonal of the coefficient matrix A shown below. 
C     Initialize the array B to store the right hand side 
C     matrix b shown below.
C
C         0   3                   5
C     A = 0   0     7         b = 5
C             0.1   0   3         5
C                   0   0         5
C
      DATA DLOW / 0.0D0, 1.0D-1, 0.0D0 /
      DATA DIAG / 0.0D0,  0.0D0, 0.0D0, 0.0D0 /
      DATA DUP1 / 3.0D0,  7.0D0, 3.0D0 /
      DATA B / 5.0D0, 5.0D0, 5.0D0, 5.0D0 /
C
C     Add a small value to each of the elements on the diagonal
C     and the first sub- and super-diagonal of A.  After this
C     loop, A will resemble the matrix shown below.  Print A
C     after adding epsilon.
C
C         e    3+e
C     A = e     e     7+e
C             0.1+e    e    3+e
C                      e     e
C
      EPSLON = ((((2.0D0 / 3.0D0) + 8.0D0) - 8.0D0) - 
     $         (2.0D0 / 3.0D0))
      DO 100, IROW = 1, N - 1
        DLOW(IROW) = DLOW(IROW) + EPSLON
        DIAG(IROW) = DIAG(IROW) + EPSLON
        DUP1(IROW) = DUP1(IROW) - EPSLON
  100 CONTINUE
      DIAG(N) = DIAG(N) + EPSLON
      CALL DCOPY (N - 1, DLOW, 1, DLOWF, 1)
      CALL DCOPY (N, DIAG, 1, DIAGF, 1)
      CALL DCOPY (N - 1, DUP1, 1, DUP1F, 1)
C
      PRINT 1000
      DO 110, IROW = 1, N
        PRINT 1010, (0.0D0, ICOL = 1, IROW - 2),
     $        (DLOW(ICOL + 1), ICOL = ABS(IROW - 2), IROW - 2),
     $        DIAG(IROW),
     $        (DUP1(IROW), ICOL = 1, MIN(1, N - IROW)),
     $        (0.0D0, ICOL = IROW + 2, N)
  110 CONTINUE
C
C     Add a small value to each element of B.  After this loop, B
C     will resemble the matrix shown below.  Print B after adding
C     epsilon.
C
C         5+e
C     B = 5+e
C         5+e
C         5+e
C
      DO 130, ICOL = 1, NRHS
        DO 120, IROW = 1, N
          B(IROW,ICOL) = B(IROW,ICOL) + EPSLON
  120   CONTINUE
  130 CONTINUE
      CALL DCOPY (N, B, 1, X, 1)
      PRINT 1020
      PRINT 1030, B
C
C     LU factor A.
C
      CALL DGTTRF (N, DLOWF, DIAGF, DUP1F, DUP2F, IPIVOT, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1040, INFO
        STOP 1
      END IF
C
C     Estimate the condition number of A.
C
      ANORM = 9.25D0 + (3.0D0 * EPSLON)
      CALL DGTCON ('ONE-NORM', N, DLOWF, DIAGF, DUP1F, DUP2F,
     $             IPIVOT, ANORM, RCOND, WORK, IWORK, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1050, ABS (INFO)
        STOP 2
      END IF
      PRINT 1060, 1.0D0 / RCOND
C
C     Solve Ax=b and print the solution.
C
      CALL DGTTRS ('NO TRANSPOSE A', N, NRHS, DLOWF, DIAGF,
     $             DUP1F, DUP2F, IPIVOT, X, LDX, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1070, INFO
        STOP 3
      END IF
      PRINT 1080
      PRINT 1090, X
      PRINT 1100
      PRINT 1030,                    DIAG(1) * X(1,1) + DUP1(1) * 
     $   X(2,1)
      PRINT 1030, DLOW(1) * X(1,1) + DIAG(2) * X(2,1) + DUP1(2) *
     $   X(3,1)
      PRINT 1030, DLOW(2) * X(2,1) + DIAG(3) * X(3,1) + DUP1(3) * 
     $   X(4,1)
      PRINT 1030, DLOW(3) * X(3,1) + DIAG(4) * X(4,1)
C
C     Refine the solution to Ax=b and print the refined solution.
C
      CALL DGTRFS ('NO TRANSPOSE A', N, NRHS, DLOW, DIAG, DUP1,
     $             DLOWF, DIAGF, DUP1F, DUP2F, IPIVOT, B, LDB,
     $             X, LDX, FERR, BERR, WORK, IWORK, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1110, ABS(INFO)
        STOP 4
      END IF
      PRINT 1120
      PRINT 1090, X
      PRINT 1130
      PRINT 1030,                    DIAG(1) * X(1,1) + DUP1(1) * 
     $   X(2,1)
      PRINT 1030, DLOW(1) * X(1,1) + DIAG(2) * X(2,1) + DUP1(2) * 
     $   X(3,1)
      PRINT 1030, DLOW(2) * X(2,1) + DIAG(3) * X(3,1) + DUP1(3) * 
     $   X(4,1)
      PRINT 1030, DLOW(3) * X(3,1) + DIAG(4) * X(4,1)
      PRINT 1140, BERR(1)
      PRINT 1150, FERR(1)
C
 1000 FORMAT (1X, 'A:')
 1010 FORMAT (4(2X, F18.16))
 1020 FORMAT (/1X, 'b:')
 1030 FORMAT (1X, F21.17)
 1040 FORMAT (1X, 'Error factoring A, INFO = ', I5)
 1050 FORMAT (1X, 'Illegal argument to DGTCON, argument #', I2)
 1060 FORMAT (/1X, 'Estimated condition number of A: ', E12.6)
 1070 FORMAT (1X, 'Error solving Ax=b, INFO = ', I5)
 1080 FORMAT (/1X, 'Initial solution to Ax=b:')
 1090 FORMAT (1X, E25.17)
 1100 FORMAT (/1X, 'Ax with the initial x:')
 1110 FORMAT (1X, 'Illegal argument to DGTRFS, INFO = ', I2)
 1120 FORMAT (/1X, 'Refined solution to Ax=b:')
 1130 FORMAT (/1X, 'Ax with refined x:')
 1140 FORMAT (/1X, 'Forward error:  ', E12.4)
 1150 FORMAT (1X, 'Backward error: ', E12.4)
C
      END
 

Sample Output

 
 A:
  -.0000000000000006  3.0000000000000004  0.0000000000000000  0.0000000000000000
  -.0000000000000006  -.0000000000000006  7.0000000000000009  0.0000000000000000
  0.0000000000000000  0.0999999999999995  -.0000000000000006  3.0000000000000004
  0.0000000000000000  0.0000000000000000  -.0000000000000006  -.0000000000000006



 b:
   4.99999999999999911
   4.99999999999999911
   4.99999999999999911
   4.99999999999999911



 Estimated condition number of A: 0.227847E+33



 Initial solution to Ax=b:
  -0.12316065590651126E+33
  -0.22789299319224172E+17
  -0.97668425653817900E+16
   0.75964331064080138E+15



 Ax with the initial x:
  16.00000000000000000
  24.00000000000000000
   5.50000000000000000
   4.99999999999999822



 Refined solution to Ax=b:
  -0.12316065590651124E+33
  -0.22789299319224172E+17
  -0.97668425653817920E+16
   0.75964331064080125E+15



 Ax with refined x:
   0.00000000000000000
  -8.00000000000000000
   5.00000000000000000
   4.99999999999999911



 Forward error:    0.1170E-15
 Backward error:   0.2384E-14






Previous Next Contents Generated Index Doc Set Home