Previous Next Contents Generated Index Doc Set Home



Solution to a Linear System in a General Matrix (Expert Driver)

The subroutines described in this section solve a linear system
AX = B, ATX = B, or AHX = B for general matrices A, B, and X. These subroutines also compute forward error bounds and backward error estimates for the solution, estimate the condition number of the matrix A and, optionally, equilibrate the system before computing a solution. Note that the simple driver xGESV is also available.

Calling Sequence

CALL DGESVX 
(FACT, TRANSA, N, NRHS, DA, LDA, DAF, LDAF, IPIVOT, 
EQUED, DROWSC, DCOLSC, DB, LDB, DX, LDX, DRCOND, DFERR, 
DBERR, DWORK, IWORK2, INFO)
CALL SGESVX 
(FACT, TRANSA, N, NRHS, SA, LDA, SAF, LDAF, IPIVOT, 
EQUED, SROWSC, SCOLSC, SB, LDB, SX, LDX, SRCOND, SFERR, 
SBERR, SWORK, IWORK2, INFO)
CALL ZGESVX 
(FACT, TRANSA, N, NRHS, ZA, LDA, ZAF, LDAF, IPIVOT, 
EQUED, ZROWSC, ZCOLSC, ZB, LDB, ZX, LDX, DRCOND, DFERR, 
DBERR, ZWORK, DWORK2, INFO)
CALL CGESVX 
(FACT, TRANSA, N, NRHS, CA, LDA, CAF, LDAF, IPIVOT, 
EQUED, CROWSC, CCOLSC, CB, LDB, CX, LDX, SRCOND, SFERR, 
SBERR, CWORK, SWORK2, INFO)






void dgesvx 
(char fact, char trans, int n, int nrhs, double *da, 
int lda, double *daf, int ldaf, int *ipivot, char 
*equed, double *drowsc, double *dcolsc, double *db, int 
ldb, double *dx, int ldx, double *drcond, double 
*dferr, double *dberr, int *info)
void sgesvx 
(char fact, char trans, int n, int nrhs, float *sa, int 
lda, float *saf, int ldaf, int *ipivot, char *equed, 
float *drowsc, float *scolsc, float *sb, int ldb, float 
*sx, int ldx, float *srcond, float *sferr, float 
*sberr, int *info)
void zgesvx 
(char fact, char trans, int n, int nrhs, doublecomplex 
*za, int lda, doublecomplex *zaf, int ldaf, int 
*ipivot, char *equed, double *drowsc, double *dcolsc, 
doublecomplex *zb, int ldb, doublecomplex *zx, int ldx, 
double *drcond, double *dferr, double *dberr, int 
*info)
void cgesvx 
(char fact, char trans, int n, int nrhs, complex *ca, 
int lda, complex *caf, int ldaf, int *ipivot, char 
*equed, float *srowsc, float *scolsc, complex *cb, int 
ldb, complex *cx, int ldx, float *srcond, float *sferr, 
float *sberr, int *info)

Arguments

FACT

Indicates whether or not the factored form of the matrix A is supplied on entry, and if not, whether the matrix A will be equilibrated before it is factored. FACT interacts with EQUED, A, and AF as shown in this table. FACT also affects the contents of IPIVOT; see its description below.



FACT
EQUED entry
EQUED exit
A entry
A exit
AF entry
AF exit

'F', 'f'

'B', 'b'

Unchanged

Row- and col-equilibrated A

Unchanged

LU-factored row- and col-equilibrated A

Unchanged

'F', 'f'

'C','c'

Unchanged

Col-equilibrated A

Unchanged

LU-factored col-equilibrated A

Unchanged

'F', 'f'

'N', 'n'

Unchanged

Matrix A

Unchanged

LU-factored A

Unchanged

'F', 'f'

'R', 'r'

Unchanged

Row-equilibrated A

Unchanged

LU-factored row-equilibrated A

Unchanged

'E', 'e'

Not used

'B'

Matrix A

Row- and col-equilibrated A

Not used

LU-factored row- and col-equilibrated A

'E', 'e'

Not used

'C'

Matrix A

Col-equilibrated A

Not used

LU-factored col-equilibrated A

'E', 'e'

Not used

'N'

Matrix A

Unchanged

Not used

LU-factored A

'E', 'e'

Not used

'R'

Matrix A

Row-equilibrated A

Not used

LU-factored row-equilibrated A

'N', 'n'

Not used

'N'

Matrix A

Unchanged

Not used

LU-factored A



The above table uses the following abbreviations:

LU-factored = the factored form of A as computed by xGETRF

Row-equilibrated A = diag(ROWSC) × A

Col-equilibrated A = A × diag(COLSC)

Row- and col-equilibrated A = diag(ROWSC) × A × diag(COLSC)

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 and AH are the same for real matrices.

N

Order of the matrix A. N 0.

NRHS

Number of right-hand sides, equal to the number of columns in the matrices B and X. NRHS 0.

xA

The contents of A vary depending on the values of FACT and EQUED. See the table for the argument FACT above.

LDA

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

xAF

The contents of AF vary depending on the values of FACT and EQUED. See the table for the argument FACT above.

LDAF

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

IPIVOT

Pivot indices; values vary depending on FACT and EQUED as shown below:



FACT
EQUED Entry
EQUED Exit
IPIVOT Entry
IPIVOT Exit

'F' or 'f'

'B', 'b', 'C', 'c', 'R', 'r'

Not used

Pivot indices from LU factorization of equilibrated A as computed by xGETRF

Unchanged

'F' or 'f'

'N' or 'n'

Not used

Pivot indices from LU factorization of A as computed by xGETRF

Unchanged

'E' or 'e'

Not used

'B', 'C', 'R'

Not used

Pivot indices from LU factorization of equilibrated A as computed by xGETRF

'E' or 'e'

Not used

'N'

Not used

Pivot indices from LU factorization of A as computed by xGETRF

'N' or 'n'

Not used

'B', 'C', 'R'

Not used

Pivot indices from LU factorization of equilibrated A as computed by xGETRF

'N' or 'n'

Not used

'N'

Not used

Pivot indices from LU factorization of A as computed by xGETRF



EQUED

EQUED interacts with FACT and IPIVOT as shown in the tables above.

Note that one must be careful about specifying lowercase letters for the entry value of EQUED when FACT = 'F' or 'f' because ordinarily LAPACK will always return a capital letter. If the caller specifies 'b', 'c', 'n', or 'r' on entry then the lowercase letter will still be in EQUED on exit. The caller may later draw incorrect conclusions if the code contains a series of IF statements to determine whether EQUED = 'B', 'C', 'N', or 'R'.

xROWSC

On entry, if FACT = 'F' or 'f' and EQUED = 'R', 'r', 'B', or 'b', then ROWSC contains the N row scale factors that were used to equilibrate A. Each element of ROWSC must be positive. If FACT or EQUED have other values, the entry values of ROWSC are not used.
On exit, if FACT = 'E' or 'e' and EQUED = 'R' or 'B', then ROWSC contains the N row scale factors that were used to equilibrate A. If FACT or EQUED have other values, ROWSC is unchanged.

xCOLSC

On entry, if FACT = 'F' or 'f' and EQUED = 'R', 'r', 'B', or 'b', then COLSC contains the N column scale factors that were used to equilibrate A. Each element of COLSC must be positive. If FACT or EQUED have other values, the entry values of COLSC are not used.

On exit, if FACT = 'E' or 'e' and EQUED = 'R' or 'B', then COLSC contains the N column scale factors that were used to equilibrate A. If FACT or EQUED have other values, COLSC is unchanged.

xB

On entry, the N×NRHS right-hand side matrix B.
On exit, the value of B is determined by the input value TRANSA and the output value of EQUED as shown below. For combinations of TRANSA and EQUED not shown below, B is not changed.

TRANSA

EQUED

Output value of B

'N', 'n'

'R' or 'B'

diag(R) × B

'T', 't', 'C', 'c'

'C' or 'B'

diag(C) × B

LDB

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

xX

On exit, the N×NRHS solution matrix for the original problem. Note that the solution to the original problem may differ from the solution to the equilibrated system for the cases shown below:

TRANSA

EQUED

Solution to equilibrated system

'N', 'n'

'C' or 'B'

diag(C)-1 × X

'T', 't', 'C', 'c'

'R' or 'B'

diag(R)-1 × X

LDX

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

xRCOND

On exit, an estimate of the reciprocal condition number of the matrix A after equilibration, if any, where the reciprocal condition number is defined to be 1 / (||A|| × ||A-1||). The reciprocal of the condition number is estimated instead of the condition number itself to avoid overflow or division by zero. If RCOND is less than machine precision (in particular, if RCOND = 0) then A is singular to working precision. In this case, INFO > 0 is returned and the solution and error bounds are not computed.

xFERR

On exit, the estimated forward error bound for each solution vector X(*, j) for 1 j NRHS. If X' is the true solution corresponding to
X(*, j) then FERR(j) is an upper bound on the magnitude of the largest element in X(*, j) - X' divided by the magnitude of the largest element in X(*, j).

xBERR

On exit, BERR(j) is the smallest relative change in any element of A or B(*, j) that makes X(*, j) an exact solution to AX(*, j) = B(*, j) for 1 j NRHS.

xWORK

Scratch array with a dimension of 3 × N for real subroutines or 2 × N for complex subroutines.

xWORK2

Scratch array with a dimension of N for real subroutines or 2 × N for complex subroutines.

INFO

On exit:

INFO = 0

Subroutine completed normally.

INFO < 0

The ith argument, where i = |INFO|, had an illegal value.

1 INFO N

U(i,i), where i = INFO, is exactly zero and U is therefore singular. The LU factorization of A has been completed, but the solution and error bounds could not be computed.

INFO = N+1

RCOND is less than machine precision. The LU factorization of A has been completed, but A is singular to working precision and so the solution and error bounds could not be computed.

Sample Program




      PROGRAM TEST
      IMPLICIT NONE
C
      INTEGER           LDA, LDAF, LDB, LDWORK, LDX, N, NRHS
      PARAMETER        (N = 3)
      PARAMETER        (NRHS = 1)
      PARAMETER        (LDA = N)
      PARAMETER        (LDAF = LDA)
      PARAMETER        (LDB = LDA)
      PARAMETER        (LDWORK = 4 * N)
      PARAMETER        (LDX = N)
C
      DOUBLE PRECISION  A(LDA,N), AF(LDAF,N), B(LDB,NRHS)
      DOUBLE PRECISION  BERR(NRHS), COLSCA(N), FERR(NRHS)
      DOUBLE PRECISION  RCOND, ROWSCA(N), WORK(LDWORK)
      DOUBLE PRECISION  X(LDX,NRHS)
      INTEGER           ICOL, INFO, IROW, IPIVOT(N), IWORK(N)
      CHARACTER*1       EQUED
C
      EXTERNAL          DGESVX
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 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 / 1.5D1, 1.5D1, 1.5D1 /
C
C     Print the initial values of the arrays.
C
      PRINT 1000
      PRINT 1010, ((A(IROW,ICOL), ICOL = 1, N), IROW = 1, N)
      PRINT 1020
      PRINT 1030, B
C
C     Solve the system.
C
      CALL DGESVX ('EQUILIBRATE A IF NECESSARY', 'NO TRANSPOSE A',
     $             N, NRHS, A, LDA, AF, LDAF, IPIVOT, EQUED,
     $             ROWSCA, COLSCA, B, LDB, X, LDX, RCOND, FERR,
     $             BERR, WORK, IWORK, INFO)
      IF (INFO .EQ. 0) THEN
C
C       Print the solution and error bounds.
C
        PRINT 1040
        PRINT 1030, X
        PRINT 1050, (1.0D0 / RCOND)
        IF (EQUED .EQ. 'N') PRINT 1060
        IF (EQUED .EQ. 'R') PRINT 1070
        IF (EQUED .EQ. 'C') PRINT 1080
        IF (EQUED .EQ. 'B') PRINT 1090
        PRINT 1100, (IROW, BERR(IROW), IROW = 1, NRHS)
        PRINT 1110, (IROW, FERR(IROW), IROW = 1, NRHS)
      ELSE
        PRINT 1120, 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, 'Estimated condition number: ', F6.3)
 1060 FORMAT (/1X, 'No equilibration was done on A.')
 1070 FORMAT (/1X, 'Row equilibration was done on A.')
 1080 FORMAT (/1X, 'Column equilibration was done on A.')
 1090 FORMAT (/1X, 'Row and column equilibration was done on A.')
 1100 FORMAT (/1X, 'Backward error for system #', I2, ': ', E12.5)
 1110 FORMAT (1X, 'Forward error for system #', I2, ': ', E12.5)
 1120 FORMAT (1X, 'Solve 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



 Estimated condition number:  7.000



 No equilibration was done on A.



 Backward error for system # 1:  0.00000E+00
 Forward error for system # 1:  0.62172E-14






Previous Next Contents Generated Index Doc Set Home