Previous Next Contents Generated Index Doc Set Home



LU Factorization of a Tridiagonal Matrix

The subroutines described in this section compute an LU factorization of a tridiagonal matrix A. It is typical to follow a call to xGTTRF with a call to xGTSVX or xGTTRS to solve a linear system AX = B, or to xGTCON to estimate the condition number of A.

Calling Sequence

CALL DGTTRF 
(N, DLOW, DDIAG, DUP1, DUP2, IPIVOT, INFO)
CALL SGTTRF 
(N, SLOW, SDIAG, SUP1, SUP2, IPIVOT, INFO)
CALL ZGTTRF 
(N, ZLOW, ZDIAG, ZUP1, ZUP2, IPIVOT, INFO)
CALL CGTTRF 
(N, CLOW, CDIAG, CUP1, CUP2, IPIVOT, INFO)






void dgttrf 
(int n, double *dlow, double *ddiag, double *dup1, 
double *dup2, int *ipivot, int *info)
void sgttrf 
(int n, float *slow, float *sdiag, float *sup1, float 
*sup2, int *ipivot, int *info)
void zgttrf 
(int n, doublecomplex *zlow, doublecomplex *zdiag, 
doublecomplex *zup1, doublecomplex *zup2, int *ipivot, 
int *info)
void cgttrf 
(int n, complex *clow, complex *cdiag, complex *cup1, 
complex *cup2, int *ipivot, int *info)

Arguments

N

Order of the matrix A. N 0.

xLOW

On entry, the N-1 subdiagonal elements of A.
On exit, the N-1 multipliers that define the matrix L from the LU factorization of A.

xDIAG

On entry, the N diagonal elements of A.
On exit, the N diagonal elements of the upper triangular matrix U from the LU factorization of A.

xUP1

On entry, the N-1 superdiagonal elements of A.
On exit, the N-1 elements of the first superdiagonal of U.

xUP2

On exit, the N-2 elements of the second superdiagonal of U.

IPIVOT

On exit, the pivot indices. During factorization, row i was exchanged with row IPIVOT(i) for 1 i 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 been completed, but division by zero will occur if this factorization is used to solve a linear system.

Sample Program




      PROGRAM TEST
      IMPLICIT NONE
C
      INTEGER           LDB, LDIWRK, LDWORK, N, NRHS
      PARAMETER        (N = 5)
      PARAMETER        (LDB = N)
      PARAMETER        (LDIWRK = N)
      PARAMETER        (LDWORK = 2 * N)
      PARAMETER        (NRHS = 1)
C
      DOUBLE PRECISION  ANORM, B(LDB,NRHS), DIAG(N), DLOWER(N-1)
      DOUBLE PRECISION  DUP1(N-1), DUP2(N-2), RCOND, WORK(LDWORK)
      INTEGER           ICOL, INFO, IPIVOT(N), IROW, IWORK(LDIWRK)
C
      EXTERNAL          DGTCON, DGTTRF, DGTTRS
      INTRINSIC         ABS, MAX
C
C     Initialize the arrays DLOWER, 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         -3   1                      6
C          1  -2   1                 12
C     A =      1  -2   1         b = 18
C                  1  -2   1         12
C                      1  -1          6
C
      DATA DLOWER / 1.0D0, 1.0D0, 1.0D0, 1.0D0 /
      DATA DIAG / -3.0D0, -2.0D0, -2.0D0, -2.0D0, -1.0D0 /
      DATA DUP1 / 1.0D0, 1.0D0, 1.0D0, 1.0D0 /
      DATA B / 6.0D0, 1.2D1, 1.8D1, 1.2D1, 6.0D0 /
C
C     Print the initial value of A.
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),
     $        (DUP1(IROW), ICOL = 1, MIN(1, N - IROW)),
     $        (0.0D0, ICOL = IROW + 2, N)
  100 CONTINUE
      PRINT 1020
      PRINT 1030, B
C
C     LU factor A.
C
      CALL DGTTRF (N, DLOWER, DIAG, DUP1, DUP2, IPIVOT, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1040, INFO
        STOP 1
      END IF
      ANORM = 4.0D0
C
C     Estimate and print the condition number of A.
C
      CALL DGTCON ('ONE-NORM', N, DLOWER, DIAG, DUP1, DUP2,
     $             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 the system and print the solution.
C
      CALL DGTTRS ('NO TRANSPOSE A', N, NRHS, DLOWER, DIAG, DUP1,
     $             DUP2, IPIVOT, B, LDB, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1070, INFO
        STOP 3
      END IF
      PRINT 1080
      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, 'Error factoring A, INFO = ', I5)
 1050 FORMAT (1X, 'Illegal argument to DGTCON, argument #', I2)
 1060 FORMAT (/1X, 'Estimated condition number of A: ', F6.2)
 1070 FORMAT (1X, 'Error solving Ax=b, INFO = ', I5)
 1080 FORMAT (/1X, 'x:')
C
      END
 

Sample Output

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



 b:
     6.00
    12.00
    18.00
    12.00
     6.00



 Estimated condition number of A:  50.00



 x:
   -27.00
   -75.00
  -111.00
  -129.00
  -135.00






Previous Next Contents Generated Index Doc Set Home