Previous Next Contents Generated Index Doc Set Home



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

The subroutines described in this section refine the solution to 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. These subroutines also compute forward error bounds and backward error estimates for the refined solution.

Calling Sequence

CALL DGERFS 
(TRANSA, N, NRHS, DA, LDA, DAF, LDAF, IPIVOT, DB, LDB, 
DX, LDX, DFERR, DBERR, DWORK, IWORK2, INFO)
CALL SGERFS 
(TRANSA, N, NRHS, SA, LDA, SAF, LDAF, IPIVOT, SB, LDB, 
SX, LDX, SFERR, SBERR, SWORK, IWORK2, INFO)
CALL ZGERFS 
(TRANSA, N, NRHS, ZA, LDA, ZAF, LDAF, IPIVOT, ZB, LDB, 
ZX, LDX, DFERR, DBERR, ZWORK, DWORK2, INFO)
CALL CGERFS 
(TRANSA, N, NRHS, CA, LDA, CAF, LDAF, IPIVOT, CB, LDB, 
CX, LDX, SFERR, SBERR, CWORK, SWORK2, INFO)






void dgerfs 
(char trans, int n, int nrhs, double *da, int lda, 
double *daf, int ldaf, int *ipivot, double *db, int 
ldb, double *dx, int ldx, double *dferr, double *dberr, 
int *info)
void sgerfs 
(char trans, int n, int nrhs, float *sa, int lda, float 
*saf, int ldaf, int *ipivot, float *sb, int ldb, float 
*sx, int ldx, float *sferr, float *sberr, int *info)
void zgerfs 
(char trans, int n, int nrhs, doublecomplex *za, int 
lda, doublecomplex *zaf, int ldaf, int *ipivot, 
doublecomplex *zb, int ldb, doublecomplex *zx, int ldx, 
double *dferr, double *dberr, int *info)
void cgerfs 
(char trans, int n, int nrhs, complex *ca, int lda, 
complex *caf, int ldaf, int *ipivot, complex *cb, int 
ldb, complex *cx, int ldx, float *sferr, float *sberr, 
int *info)

Arguments

TRANSA

Indicates the form of the linear system whose solution is to be refined. The legal values for TRANSA are listed below. Any values not listed below are illegal.

'N' or 'n'

No transpose, refine AX = B.

'T' or 't'

Transpose, refine ATX = B.

'C' or 'c'

Conjugate transpose, refine 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 of the matrices B and X. NRHS 0.

xA

Matrix A.

LDA

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

xAF

LU factorization of the matrix A as computed by xGETRF.

LDAF

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

IPIVOT

Pivot indices as computed by xGETRF.

xB

The N×NRHS right-hand side matrix B.

LDB

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

xX

On entry, the N×NRHS solution matrix X.
On exit, the refined N×NRHS solution matrix X.

LDX

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

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.

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, LDAF, LDB, LDIWRK, LDWORK, LDX
      INTEGER           N, NRHS
      PARAMETER        (N = 3)
      PARAMETER        (LDA = N)
      PARAMETER        (LDAF = N)
      PARAMETER        (LDB = N)
      PARAMETER        (LDIWRK = N)
      PARAMETER        (LDWORK = 3 * N)
      PARAMETER        (LDX = N)
      PARAMETER        (NRHS = 1)
C
      DOUBLE PRECISION  A(LDA,N), AF(LDAF,N), B(LDB,NRHS)
      DOUBLE PRECISION  B1(LDB,NRHS), BERR(NRHS), EPSLON
      DOUBLE PRECISION  FERR(NRHS), WORK(LDWORK), X(LDX,NRHS)
      INTEGER           ICOL, INFO, IPIVOT(N), IROW
      INTEGER           IWORK(LDIWRK)
C
      EXTERNAL          DCOPY, DGEMV, DGERFS, DGETRF, DGETRS
      INTRINSIC         ABS, DBLE
C
      EPSLON = ((((2.0D0 / 3.0D0) + 1.6D1) - 1.6D1) - 
     $         (2.0D0 / 3.0D0))
C
C     Initialize the array A to store the matrix A shown below.
C     Each of the diagonal elements is equal to the row number 
C     plus epsilon.
C
C         1+e  1    1
C     A = 2    2+e  2
C         3    3    3+e
C
      DO 110, ICOL = 1, N
        DO 100, IROW = 1, N
          A(IROW,ICOL) = DBLE(IROW)
  100   CONTINUE
        A(ICOL,ICOL) = A(ICOL,ICOL) + EPSLON
  110 CONTINUE
      CALL DCOPY (LDA*N, A, 1, AF, 1)
C
C     Print the initial value of A.
C
      PRINT 1000
      DO 120, IROW = 1, N
        PRINT 1010, (A(IROW,ICOL), ICOL = 1, N)
  120 CONTINUE
C
C     Initialize the array B to store the right hand side
C     vector b shown below.  Each element is equal to N plus
C     a small epsilon. Print the contents of the array after 
C     initialization.
C
C         N+e
C     b = N+e
C         N+e
C
      DO 130, IROW = 1, N
        B(IROW,1) = DBLE(N) + EPSLON
  130 CONTINUE
      CALL DCOPY (N, B, 1, X, 1)
      PRINT 1020
      PRINT 1030, B
C
C     LU factor A.
C
      CALL DGETRF (N, N, AF, LDAF, IPIVOT, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1040, INFO
        STOP 1
      END IF
C
C     Use the LU factorization to solve the system.
C
      CALL DGETRS ('NO TRANSPOSE A', N, NRHS, AF, LDAF, IPIVOT,
     $             X, LDX, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1050, INFO
        STOP 2
      END IF
C
C     Print the solution and Ax.
C
      PRINT 1060
      PRINT 1070, X
      CALL DGEMV ('N', N, N, 1.0D0, A, LDA, X, 1, 0.0D0, B1, 1)
      PRINT 1080
      PRINT 1030, B1
C
C     Refine the solution, then print the refined solution and Ax
C     with the refined x.
C
      CALL DGERFS ('NO TRANSPOSE A', N, NRHS, A, LDA, AF, LDAF,
     $             IPIVOT, B, LDB, X, LDX, FERR, BERR, WORK,
     $             IWORK, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1090, INFO
        STOP 2
      END IF
      PRINT 1100
      PRINT 1070, X
      CALL DGEMV ('N', N, N, 1.0D0, A, LDA, X, 1, 0.0D0, B1, 1)
      PRINT 1110
      PRINT 1030, B1
C
 1000 FORMAT (1X, 'A:')
 1010 FORMAT (3(3X, F22.17))
 1020 FORMAT (/1X, 'b:')
 1030 FORMAT (1X, F22.17)
 1040 FORMAT (1X, 'Error factoring A in DGETRF, INFO = ', I5)
 1050 FORMAT (1X, 'Error solving Ax=b in DGETRF, INFO = ', I5)
 1060 FORMAT (/1X, 'Initial solution for Ax=b:')
 1070 FORMAT (1X, E16.6)
 1080 FORMAT (/1X, 'Ax with initial x:')
 1090 FORMAT (1X, 'Error improving solution in DGERFS,
     $        INFO = ', I5)
 1100 FORMAT (/1X, 'Improved solution for Ax=b:')
 1110 FORMAT (/1X, 'Ax with improved x:')
C
      END
 

Sample Output

 
 A:
      1.00000000000000133      1.00000000000000000      1.00000000000000000
      2.00000000000000000      2.00000000000000133      2.00000000000000000
      3.00000000000000000      3.00000000000000000      3.00000000000000133



 b:
    3.00000000000000133
    3.00000000000000133
    3.00000000000000133



 Initial solution for Ax=b:
     0.112590E+16
     0.333333E+00
    -0.112590E+16



 Ax with initial x:
    2.75000000000000000
    2.50000000000000000
    2.50000000000000000



 Improved solution for Ax=b:
     0.115717E+16
     0.625500E+14
    -0.121972E+16



 Ax with improved x:
    3.25000000000000000
    3.50000000000000000
    3.00000000000000000






Previous Next Contents Generated Index Doc Set Home