Previous Next Contents Generated Index Doc Set Home



LU Factorization of a General Matrix

The subroutines described in this section compute an LU factorization of a general matrix A. It is typical to follow a call to xGETRF with a call to xGESVX or xGETRS to solve a linear system AX = B, to xGECON to estimate the condition number of A, or to xGETRI to compute A-1.

Calling Sequence

CALL DGETRF 
(M, N, DA, LDA, IPIVOT, INFO)
CALL SGETRF 
(M, N, SA, LDA, IPIVOT, INFO)
CALL ZGETRF 
(M, N, ZA, LDA, IPIVOT, INFO)
CALL CGETRF 
(M, N, CA, LDA, IPIVOT, INFO)






void dgetrf 
(int m, int n, double *da, int lda, int *ipivot, int 
*info)
void sgetrf 
(int m, int n, float *sa, int lda, int *ipivot, int 
*info)
void zgetrf 
(int m, int n, doublecomplex *za, int lda, int *ipivot, 
int *info)
void cgetrf 
(int m, int n, complex *ca, int lda, int *ipivot, int 
*info)

Arguments

M

Number of rows of the matrix A. M 0.

N

Number of columns of the matrix A. N 0.

xA

On entry, the matrix A.
On exit, an LU factorization of A.

LDA

Leading dimension of the array A as specified in a dimension or type statement. LDA max(1, M).

IPIVOT

On exit, the pivot indices. During factorization, row i was exchanged with row IPIVOT(i) for 1 i min(M, 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           LDA, LDB, M, N, NRHS, SIZEB
      PARAMETER        (M = 3)
      PARAMETER        (N = 3)
      PARAMETER        (NRHS = 1)
      PARAMETER        (LDA = M)
      PARAMETER        (LDB = LDA)
      PARAMETER        (SIZEB = LDB * NRHS)
C
      DOUBLE PRECISION  A(LDA,N), B(LDB,NRHS)
      INTEGER           ICOL, INFO, IROW, IPIVOT(N)
C
      EXTERNAL          DGETRF, DGETRS
C
C     Initialize the array A to store the coefficient matrix A
C     shown below.  Initialize the array B to store the right
C     hand side vector b shown below.
C
C         1  2  2        15
C     A = 2  1  2    b = 15
C         2  2  1        15
C
      DATA A / 1.0D0, 3*2.0D0, 1.0D0, 3*2.0D0, 1.0D0 /
      DATA B / SIZEB*1.5D1 /
C
C     Print the initial value of the arrays.
C
      PRINT 1000
      PRINT 1010, ((A(IROW,ICOL), ICOL = 1, N), IROW = 1, M)
      PRINT 1020
      PRINT 1030, B
C
C     Factor A, solve the system, and print the solution.
C
      CALL DGETRF (M, N, A, LDA, IPIVOT, INFO)
      IF (INFO .EQ. 0) THEN
        CALL DGETRS ('NO TRANSPOSE A', N, NRHS, A, LDA, IPIVOT,
     $     B, LDB, INFO)
        IF (INFO .EQ. 0) THEN
          PRINT 1040
          PRINT 1030, B
        ELSE
          PRINT 1050, INFO
        END IF
      ELSE
        PRINT 1060, INFO
      END IF
C
 1000 FORMAT (1X, 'A:')
 1010 FORMAT (3(3X, F4.1))
 1020 FORMAT (/1X, 'b:')
 1030 FORMAT (1X, 2X, F4.1)
 1040 FORMAT (/1X, 'x:')
 1050 FORMAT (1X, 'Solve failed with INFO = ', I6)
 1060 FORMAT (1X, 'Factorization failed with INFO = ', I6)
C
      END
 

Sample Output

 
 A:
    1.0    2.0    2.0
    2.0    1.0    2.0
    2.0    2.0    1.0



 b:
   15.0
   15.0
   15.0



 x:
    3.0
    3.0
    3.0






Previous Next Contents Generated Index Doc Set Home