Previous Next Contents Generated Index Doc Set Home



Solution to a Linear System in a Triangular Matrix

The subroutines described in this section solve a linear system
AX = B, ATX = B, or AHX = B for a triangular matrix A and general matrices B and X.

Calling Sequence

CALL DTRTRS 
(UPLO, TRANSA, DIAG, N, NRHS, DA, LDA, DB, LDB, INFO)
CALL STRTRS 
(UPLO, TRANSA, DIAG, N, NRHS, SA, LDA, SB, LDB, INFO)
CALL ZTRTRS 
(UPLO, TRANSA, DIAG, N, NRHS, ZA, LDA, ZB, LDB, INFO)
CALL CTRTRS 
(UPLO, TRANSA, DIAG, N, NRHS, CA, LDA, CB, LDB, INFO)






void dtrtrs 
(char uplo, char trans, char diag, int n, int nrhs, 
double *da, int lda, double *db, int ldb, int *info)
void strtrs 
(char uplo, char trans, char diag, int n, int nrhs, 
float *sa, int lda, float *sb, int ldb, int *info)
void ztrtrs 
(char uplo, char trans, char diag, int n, int nrhs, 
doublecomplex *za, int lda, doublecomplex *zb, int ldb, 
int *info)
void ctrtrs 
(char uplo, char trans, char diag, int n, int nrhs, 
complex *ca, int lda, complex *cb, int ldb, int *info)

Arguments

UPLO

Indicates whether xA contains the upper or lower triangle of the matrix. The legal values for UPLO are listed below. Any values not listed below are illegal.

U' or 'u'

xA contains the upper triangle.

'L' or 'l'

xA contains the lower triangle.

TRANSA

Indicates the form of the system of equations. 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 and AH are the same for real matrices.

DIAG

Indicates whether or not A is unit triangular. The legal values for DIAG are listed below. Any values not listed below are illegal.

'N' or 'n'

A is not unit triangular.

'U' or 'u'

A is unit triangular.

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

Upper or lower triangular matrix A.

If DIAG = 'U' or 'u', the diagonal elements of A are assumed to be 1 and are not used.

LDA

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

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

The ith diagonal element, where i = INFO, of A is zero. The matrix is therefore singular and the solution could not be computed.

Sample Program




      PROGRAM TEST
      IMPLICIT NONE
C
      DOUBLE PRECISION  ZERO
      INTEGER           LDA, LDB, N, NRHS
      PARAMETER        (N = 4)
      PARAMETER        (LDA = N)
      PARAMETER        (LDB = N)
      PARAMETER        (NRHS = 1)
      PARAMETER        (ZERO = 0.0D0)
C
      DOUBLE PRECISION  A(LDA,N), B(LDB,NRHS)
      INTEGER           ICOL, INFO, IROW
C
      EXTERNAL          DTRTRS
      INTRINSIC         ABS
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                     4
C     A = 1   1             b = 3
C         1   1   1             2
C         1   1   1   1         1
C
      DATA A / 1.0D0, 1.0D0, 1.0D0, 1.0D0,
     $         8.8D8, 1.0D0, 1.0D0, 1.0D0,
     $         8.8D8, 8.8D8, 1.0D0, 1.0D0,
     $         8.8D8, 8.8D8, 8.8D8, 1.0D0 /
      DATA B / 4.0D0, 3.0D0, 2.0D0, 1.0D0 /
C
C     Print the initial value of the arrays.
C
      PRINT 1000
      DO 100, IROW = 1, N
        PRINT 1010, (A(IROW,ICOL), ICOL = 1, IROW),
     $              (ZERO, ICOL = IROW + 1, N)
  100 CONTINUE
      PRINT 1020
      PRINT 1010, ((A(IROW,ICOL), ICOL = 1, N), IROW = 1, LDA)
      PRINT 1030
      PRINT 1060, B
C
C     Solve Ax=b and print the result.
C
      CALL DTRTRS ('LOWER TRIANGULAR A', 'TRANSPOSE A',
     $             'NO UNIT DIAGONAL A', N, NRHS, A, LDA, B, LDB,
     $             INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1040, INFO
        STOP 1
      END IF
      PRINT 1050
      PRINT 1060, B
C
 1000 FORMAT (1X, 'A in full form:')
 1010 FORMAT (4(3X, F8.4))
 1020 FORMAT (/1X, 'A in triangular form: ',
     $        ' (* in unused elements)')
 1030 FORMAT (/1X, 'b:')
 1040 FORMAT (/1X, 'Error solving Ax=b, INFO = ', I5)
 1050 FORMAT (/1X, 'x:')
 1060 FORMAT (1X, F8.4)
C
      END
 

Sample Output

 
 A in full form:
     1.0000     0.0000     0.0000     0.0000
     1.0000     1.0000     0.0000     0.0000
     1.0000     1.0000     1.0000     0.0000
     1.0000     1.0000     1.0000     1.0000



 A in triangular form:  (* in unused elements)
     1.0000   ********   ********   ********
     1.0000     1.0000   ********   ********
     1.0000     1.0000     1.0000   ********
     1.0000     1.0000     1.0000     1.0000



 b:
   4.0000
   3.0000
   2.0000
   1.0000



 x:
   1.0000
   1.0000
   1.0000
   1.0000










Previous Next Contents Generated Index Doc Set Home