Previous Next Contents Generated Index Doc Set Home



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

The subroutines described in this section solve a linear system AX = B for a general tridiagonal matrix A and general matrices B and X. Note that the expert driver xGTSVX is also available.

Calling Sequence

CALL DGTSV 
(N, NRHS, DLOW, DDIAG, DUP, DB, LDB, INFO)
CALL SGTSV 
(N, NRHS, SLOW, SDIAG, SUP, SB, LDB, INFO)
CALL ZGTSV 
(N, NRHS, ZLOW, ZDIAG, ZUP, ZB, LDB, INFO)
CALL CGTSV 
(N, NRHS, CLOW, CDIAG, CUP, CB, LDB, INFO)






void dgtsv 
(int n, int nrhs, double *dlow, double *ddiag, double 
*dup, double *db, int ldb, int *info)
void sgtsv 
(int n, int nrhs, float *slow, float *sdiag, float 
*sup, float *sb, int ldb, int *info)
void zgtsv 
(int n, int nrhs, doublecomplex *zlow, doublecomplex 
*zdiag, doublecomplex *zup, doublecomplex *zb, int 
ldb, int *info)
void cgtsv 
(int n, int nrhs, complex *clow, complex *cdiag, 
complex *cup, complex *cb, int ldb, int *info)

Arguments

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

On entry, the N-1 subdiagonal elements of A.
On exit, LOW is overwritten by the N-2 elements of the second superdiagonal of the upper triangular matrix U from the LU factorization of A, stored in elements 1 through N-2.

xDIAG

On entry, the N diagonal elements of A.
On exit, DIAG is overwritten by the N diagonal elements of U.

xUP

On entry, the N-1 superdiagonal elements of A.
On exit, UP is overwritten by the N-1 elements of the first superdiagonal of U.

xB

On entry, the N×NRHS right-hand side matrix B.
On exit, the N×NRHS solution matrix X.

LDB

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

INFO

On exit:

INFO = 0

Subroutine completed normally.

INFO < 0

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

INFO > 0

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

Sample Program




      PROGRAM TEST
      IMPLICIT NONE
C
      INTEGER           LDB, LDIWRK, LDWORK, N, NRHS
      PARAMETER        (N = 4)
      PARAMETER        (LDB = N)
      PARAMETER        (LDIWRK = N)
      PARAMETER        (LDWORK = N)
      PARAMETER        (NRHS = 1)
C
      DOUBLE PRECISION  B(LDB,NRHS), DIAG(N), DLOWER(N-1)
      DOUBLE PRECISION  DUPPER(N-1)
      INTEGER           ICOL, INFO, IROW
C
      EXTERNAL          DGTSV
      INTRINSIC         ABS, MAX
C
C     Initialize the arrays DLOWER, DIAG, and DUPPER to store the
C     first subdiagonal, the diagonal, and the first superdiagonal
C     of the coefficient matrix A shown below.  Initialize the 
C     array B to store the right hand side 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 DLOWER / 1.0D0, 1.0D0, 1.0D0 /
      DATA DIAG / 2.0D0, 2.0D0, 2.0D0, 2.0D0 /
      DATA DUPPER / -1.0D0, -1.0D0, -1.0D0 /
      DATA B / 0.0D0, 2.0D0, 4.0D0, 1.1D1 /
C
      PRINT 1000
      DO 100, IROW = 1, N
        PRINT 1010, (0.0D0, ICOL = 1, IROW - 2),
     $        (DLOWER(ICOL + 1), ICOL = ABS(IROW - 2), IROW - 2),
     $        DIAG(IROW),
     $        (DUPPER(IROW), ICOL = 1, MIN(1, N - IROW)),
     $        (0.0D0, ICOL = IROW + 2, N)
  100 CONTINUE
      PRINT 1020
      PRINT 1030, B
C
      CALL DGTSV (N, NRHS, DLOWER, DIAG, DUPPER, B, LDB, 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, B
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 DGTSV, argument #', I2)
 1050 FORMAT (1X, 'A is singular to working precision.')
 1060 FORMAT (/1X, 'x:')
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






Previous Next Contents Generated Index Doc Set Home