Previous Next Contents Generated Index Doc Set Home



Inverse of an LU-Factored General Matrix

The subroutines described in this section compute the inverse of a general matrix A, which has been LU-factored by xGETRF.

Calling Sequence

CALL DGETRI 
(N, DA, LDA, IPIVOT, DWORK, LDWORK, INFO)
CALL SGETRI 
(N, SA, LDA, IPIVOT, SWORK, LDWORK, INFO)
CALL ZGETRI 
(N, ZA, LDA, IPIVOT, ZWORK, LDWORK, INFO)
CALL CGETRI 
(N, CA, LDA, IPIVOT, CWORK, LDWORK, INFO)






void dgetri 
(int n, double *da, int lda, int *ipivot, int *info)
void sgetri 
(int n, float *sa, int lda, int *ipivot, int *info)
void zgetri 
(int n, doublecomplex *za, int lda, int *ipivot, int 
*info)
void cgetri 
(int n, complex *ca, int lda, int *ipivot, int *info)

Arguments

N

Order of the matrix A. N 0.

xA

On entry, the LU factorization of A as computed by xGETRF.
On exit, A-1.

LDA

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

IPIVOT

Pivot indices as computed by xGETRF.

xWORK

Scratch array with a dimension of LDWORK.

LDWORK

Leading dimension of the array WORK as specified in a dimension or type statement. LDWORK 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. The matrix is therefore singular and its inverse could not be computed.

Sample Program




      PROGRAM TEST
      IMPLICIT NONE
C
      INTEGER           LDA, LDB, LDWORK, M, N
      PARAMETER        (M = 3)
      PARAMETER        (N = 3)
      PARAMETER        (LDA = M)
      PARAMETER        (LDB = LDA)
      PARAMETER        (LDWORK = N)
C
      DOUBLE PRECISION  A(LDA,N), WORK(LDWORK)
      INTEGER           ICOL, INFO, IROW, IPIVOT(N)
C
      EXTERNAL          DGETRF, DGETRI
C
C     Initialize the array A to store the matrix A shown below.
C
C         1   4   6
C     A = 2   9  14
C         3  14  23
C
      DATA A / 1.0D0, 2.0D0, 3.0D0,
     $         4.0D0, 9.0D0, 1.4D1,
     $         6.0D0, 1.4D1, 2.3D1 /
C
C     Print the initial value of A.
C
      PRINT 1000
      PRINT 1010, ((A(IROW,ICOL), ICOL = 1, N), IROW = 1, M)
C
C     LU factor A, then use the factorization to compute the
C     inverse.
C
      CALL DGETRF (M, N, A, LDA, IPIVOT, INFO)
      IF (INFO .EQ. 0) THEN
        CALL DGETRI (N, A, LDA, IPIVOT, WORK, LDWORK, INFO)
        IF (INFO .EQ. 0) THEN
          PRINT 1020
          PRINT 1010, ((A(IROW,ICOL), ICOL = 1, N), IROW = 1, M)
        ELSE
          PRINT 1030, INFO
        END IF
      ELSE
        PRINT 1040, INFO
      END IF
C
 1000 FORMAT (1X, 'A:')
 1010 FORMAT (3(3X, F4.1))
 1020 FORMAT (/1X, 'A**(-1):')
 1030 FORMAT (1X, 'Inverse failed with INFO = ', I6)
 1040 FORMAT (1X, 'Factorization failed with INFO = ', I6)
C
      END
 

Sample Output

 
 A:
    1.0    4.0    6.0
    2.0    9.0   14.0
    3.0   14.0   23.0



 A**(-1):
   11.0   -8.0    2.0
   -4.0    5.0   -2.0
    1.0   -2.0    1.0






Previous Next Contents Generated Index Doc Set Home