Previous Next Contents Generated Index Doc Set Home



Solution to a Linear System in an LU-Factored General Matrix

The subroutines described in this section solve a linear system
AX = B, ATX = B, or AHX = B for a general matrix A, which has been LU-factored by xGETRF, and general matrices B and X.

Calling Sequence

CALL DGETRS 
(TRANSA, N, NRHS, DA, LDA, IPIVOT, DB, LDB, INFO)
CALL SGETRS 
(TRANSA, N, NRHS, SA, LDA, IPIVOT, SB, LDB, INFO)
CALL ZGETRS 
(TRANSA, N, NRHS, ZA, LDA, IPIVOT, ZB, LDB, INFO)
CALL CGETRS 
(TRANSA, N, NRHS, CA, LDA, IPIVOT, CB, LDB, INFO)






void dgetrs 
(char trans, int n, int nrhs, double *da, int lda, int 
*ipivot, double *db, int ldb, int *info)
void sgetrs 
(char trans, int n, int nrhs, float *sa, int lda, int 
*ipivot, float *sb, int ldb, int *info)
void zgetrs 
(char trans, int n, int nrhs, doublecomplex *za, int 
lda, int *ipivot, doublecomplex *zb, int ldb, int 
*info)
void cgetrs 
(char trans, int n, int nrhs, complex *ca, int lda, int 
*ipivot, complex *cb, int ldb, int *info)

Arguments

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 = AH 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.

xA

LU factorization of matrix A as computed by xGETRF.

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.

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.

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  1  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     LU factor A then use the factorization to solve the system.
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