Previous Next Contents Generated Index Doc Set Home



Solution to a Linear System in a General Tridiagonal Matrix (Expert Driver)

The subroutines described in this section solve a linear system
AX = B, ATX = B, or AHX = B for a general tridiagonal matrix A and general matrices B and X. These subroutines also compute forward error bounds and backward error estimates for the solution, and estimate the condition number of the matrix A. Note that the simple driver xGTSV is also available.

Calling Sequence

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






void dgtsvx 
(char fact, 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 
*drcond, double *dferr, double *dberr, int *info)
void sgtsvx 
(char fact, 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 *srcond, float *sferr, 
float *sberr, int *info)
void zgtsvx 
(char fact, 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 *drcond, double *dferr, double 
*dberr, int *info)
void cgtsvx 
(char fact, char trans, int n, int nrhs, complex *clow, 
complex *cdiag, complex *cup, complex *clowf, complex 
*cdiag, complex *cupf1, complex *cupf2, int *ipivot, 
complex *cb, int ldb, complex *cx, int ldx, float 
*srcond, float *sferr, float *sberr, int *info)

Arguments

FACT

Indicates whether or not the factored form of A has been supplied on entry.

'F' or 'f'

On entry, LOWF, DIAGF, UPF, UPF2, and IPIVOT contain the factored form of A. These arguments, as well as LOW, DIAG, and UP, will not be modified.

'N' or 'n'

The matrix A will be copied to LOWF, DIAGF, and UPF and factored.

TRANSA

Indicates the form of the linear system to solve. The legal values for TRANSA are listed below. Any values not listed below are illegal.

'N' or 'n'

No transpose, solve AX = B.

'T' or 't'

Transpose, solve ATX = B.

'C' or 'c'

Conjugate transpose, solve 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 matrix B. NRHS 0.

xLOW

The N-1 subdiagonal elements of A.

xDIAG

The N diagonal elements of A.

xUP

The N-1 superdiagonal elements of A.

xLOWF

On entry, if FACT = 'F' or 'f', then LOWF contains the N-1 multipliers that define the matrix L from the LU factorization of A, as computed by xGTTRF.
On exit, if FACT = 'N', then LOWF contains the N-1 multipliers that define the matrix L from the LU factorization of A, as computed by xGTTRF.

xDIAGF

On entry, if FACT = 'F' or 'f', then DIAGF contains the N diagonal elements of the upper triangular matrix U from the LU factorization of A as computed by xGTTRF.
On exit, if FACT = 'N', then DIAGF contains the N diagonal elements of the upper triangular matrix U from the LU factorization of A, as computed by xGTTRF.

xUPF1

On entry, if FACT = 'F' or 'f', then UPF1 contains the N-1 elements of the first superdiagonal of U.
On exit, if FACT = 'N', then UPF1 contains the N-1 elements of the first superdiagonal of U.

xUPF2

On entry, if FACT = 'F' or 'f', then UPF2 contains the N-2 elements of the second superdiagonal of U.
On exit, if FACT = 'N', then UPF2 contains the N-2 elements of the second superdiagonal of U.

IPIVOT

On entry, if FACT = 'F' or 'f', then IPIVOT contains the pivot indices from the LU factorization of A, as computed by xGTTRF.
On exit, if FACT = 'N', then IPIVOT contains the pivot indices from the LU factorization of A, 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 exit, the N×NRHS solution matrix X.

LDX

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

xRCOND

On exit, an estimate of the reciprocal condition number of the matrix A, where the reciprocal condition number is defined to be
1 / (||A|| × ||A-1||). The reciprocal of the condition number is estimated instead of the condition number itself to avoid overflow or division by zero. If RCOND is less than machine precision (in particular, if RCOND = 0) then A is singular to working precision. In this case, INFO > 0 is returned and the solution and error bounds are not computed.

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 for complex subroutines.

INFO

On exit:

INFO = 0

Subroutine completed normally.

INFO < 0

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

1 INFO N

U(i,i), where i = INFO, is exactly zero, U is therefore singular. The factorization has not been completed, unless i = N, and the solution and error bounds could not be computed.

INFO = N + 1

RCOND is less than machine precision. The factorization has been completed, but the matrix is singular to working precision, and the solution and error bounds could not be computed.

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  B(LDB,NRHS), BERR(NRHS), DIAG(N), DIAGF(N)
      DOUBLE PRECISION  DLOW(N-1), DLOWF(N-1), DUP(N-1), DUPF(N-1)
      DOUBLE PRECISION  DUP2F(N-1), FERR(NRHS), RCOND
      DOUBLE PRECISION  WORK(LDWORK), X(LDX,NRHS)
      INTEGER           ICOL, INFO, IPIVOT(N), IROW, IWORK(LDIWRK)
C
      EXTERNAL          DGTSVX
      INTRINSIC         ABS, MAX
C
C     Initialize the arrays DLOWER, DIAG, and DUPPER 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         2  -1                0
C     A = 1   2  -1       b =  2
C             1   2  -1        4
C                 1   2       11
C
      DATA DLOW / 1.0D0, 1.0D0, 1.0D0 /
      DATA DIAG / 2.0D0, 2.0D0, 2.0D0, 2.0D0 /
      DATA DUP / -1.0D0, -1.0D0, -1.0D0 /
      DATA B / 0.0D0, 2.0D0, 4.0D0, 1.1D1 /
C
C     Print the initial value of the arrays.
C
      PRINT 1000
      DO 100, IROW = 1, N
        PRINT 1010, (0.0D0, ICOL = 1, IROW - 2),
     $        (DLOW(ICOL + 1), ICOL = ABS(IROW - 2), IROW - 2),
     $        DIAG(IROW),
     $        (DUP(IROW), ICOL = 1, MIN(1, N - IROW)),
     $        (0.0D0, ICOL = IROW + 2, N)
  100 CONTINUE
      PRINT 1020
      PRINT 1030, B
C
C     Solve the system Ax=b.  Print the solution and error 
C     information.
C
      CALL DGTSVX ('NOT FACTORED ON ENTRY', 'NO TRANSPOSE A', N,
     $             NRHS, DLOW, DIAG, DUP, DLOWF, DIAGF, DUPF,
     $             DUP2F, IPIVOT, B, LDB, X, LDX, RCOND, FERR,
     $             BERR, WORK, IWORK, INFO)
      IF (INFO .LT. 0) THEN
        PRINT 1040, INFO
        STOP 1
      ELSE IF (INFO .GT. 0) THEN
        PRINT 1050
        STOP 2
      END IF
      PRINT 1060
      PRINT 1030, X
      PRINT 1070, BERR(1)
      PRINT 1080, FERR(1)
C
 1000 FORMAT (1X, 'A:')
 1010 FORMAT (5(3X, F5.2))
 1020 FORMAT (/1X, 'b:')
 1030 FORMAT (1X, F8.2)
 1040 FORMAT (1X, 'Illegal argument to DGTSVX, argument #', I2)
 1050 FORMAT (1X, 'A is singular to working precision.')
 1060 FORMAT (/1X, 'x:')
 1070 FORMAT (/1X, 'Backward error: ', E14.8)
 1080 FORMAT (1X, 'Forward error:  ', E14.8)
C
      END
 

Sample Output

 
 A:
    2.00   -1.00    0.00    0.00
    1.00    2.00   -1.00    0.00
    0.00    1.00    2.00   -1.00
    0.00    0.00    1.00    2.00



 b:
     0.00
     2.00
     4.00
    11.00



 x:
     1.00
     2.00
     3.00
     4.00



 Backward error: 0.00000000E+00
 Forward error:  0.12174170E-14






Previous Next Contents Generated Index Doc Set Home