Previous Next Contents Generated Index Doc Set Home



Refined Solution to a Linear System in a UDU- or LDL-Factored Symmetric Matrix

The subroutines described in this section refine the solution to a linear system AX = B for a symmetric matrix A, which has been UDU-factored or LDL-factored by xSYTRF, and general matrices B and X. These subroutines also compute forward error bounds and backward error estimates for the refined solution.

Calling Sequence

CALL DSYRFS 
(UPLO, N, NRHS, DA, LDA, DAF, LDAF, IPIVOT, DB, LDB, 
DX, LDX, DFERR, DBERR, DWORK, DWORK2, INFO)
CALL SSYRFS 
(UPLO, N, NRHS, SA, LDA, SAF, LDAF, IPIVOT, SB, LDB, 
SX, LDX, SFERR, SBERR, SWORK, SWORK2, INFO)
CALL ZSYRFS 
(UPLO, N, NRHS, ZA, LDA, ZAF, LDAF, IPIVOT, ZB, LDB, 
ZX, LDX, DFERR, DBERR, ZWORK, DWORK2, INFO)
CALL CSYRFS 
(UPLO, N, NRHS, CA, LDA, CAF, LDAF, IPIVOT, CB, LDB, 
CX, LDX, SFERR, SBERR, CWORK, SWORK2, INFO)






void dsyrfs 
(char uplo, 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 ssyrfs 
(char uplo, 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 zsyrfs 
(char uplo, 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 csyrfs 
(char uplo, 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

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.

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

Upper or lower triangle of the matrix A.

LDA

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

xAF

UDU or LDL factorization of the matrix A as computed by xSYTRF.

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 xSYTRF.

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.

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, LDWORK, LDX, N, NRHS
      PARAMETER        (N = 4)
      PARAMETER        (LDA = N)
      PARAMETER        (LDAF = N)
      PARAMETER        (LDB = N)
      PARAMETER        (LDWORK = 1)
      PARAMETER        (LDX = LDB)
      PARAMETER        (NRHS = 1)
C
      DOUBLE PRECISION  A(LDA,N), AF(LDAF,N), B(LDB,NRHS)
      DOUBLE PRECISION  BERR(NRHS), EPSLON, FERR(NRHS)
      DOUBLE PRECISION  WORK(LDWORK), X(LDX,NRHS)
      INTEGER           ICOL, INFO, IPIVOT(N), IROW, IWORK(N)
C
      EXTERNAL          DCOPY, DSYRFS, DSYTRF, DSYTRS
      INTRINSIC         ABS, MAX
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         0   0                30
C     A = 0   2   2        b = 50
C             2   2   0        70
C                 0   0       110
C
      DATA A / 0.0D0, 8.0D8, 8.0D8, 8.0D8, 0.0D0, 2.0D0, 8.0D8,
     $         8.0D8, 0.0D0, 2.0D0, 2.0D0, 8.0D8, 0.0D0, 0.0D0,
     $         0.0D0, 0.0D0 /
      DATA B / 3.0D0, 5.0D0, 7.0D0, 1.1D1 /
C
C     Slightly perturb each of the elements on the diagonal, the
C     first subdiagonal, and the first superdiagonal of A.  After
C     this code, A will resemble the matrix shown below.
C
C          2e   -e
C     A =  -e   2+e   2-e
C               2-e   2+e   -e
C                     -e    2e
C
      EPSLON = ABS ((((2.0D0 / 3.0D0) + 2.0D0) - 2.0D0) -
     $   (2.0D0 / 3.0D0))
      A(1,1) = EPSLON + EPSLON
      A(N,N) = EPSLON + EPSLON
      DO 100, IROW = 2, N - 1
        A(IROW,IROW) = A(IROW,IROW) + EPSLON
  100 CONTINUE
      DO 110, IROW = 1, N - 1
        A(IROW,IROW + 1) = A(IROW,IROW + 1) - EPSLON
  110 CONTINUE
C
C     Slightly perturb each element of B.  After this code, B will
C     resemble the matrix shown below.
C
C          3-small
C     B =  5-small
C          7-small
C         11-small
C
      DO 130, ICOL = 1, NRHS
        DO 120, IROW = 1, N
          B(IROW,ICOL) = B(IROW,ICOL) * (1.0D0 - EPSLON)
  120   CONTINUE
  130 CONTINUE
C
C     Print the initial values of the arrays.
C
      PRINT 1000
      DO 140, IROW = 1, N
        PRINT 1010, (A(ICOL,IROW), ICOL = 1, IROW),
     $              (A(IROW,ICOL), ICOL = IROW + 1, N)
  140 CONTINUE
      PRINT 1020
      DO 150, IROW = 1, N
        PRINT 1010, (A(IROW,ICOL), ICOL = 1, N)
  150 CONTINUE
      PRINT 1030
      PRINT 1040, B
C
C     Make copies to use with DSYRFS.
C
      CALL DCOPY (LDA * N, A, 1, AF, 1)
      CALL DCOPY (LDB * NRHS, B, 1, X, 1)
C
C     LU factor A.
C
      CALL DSYTRF ('UPPER TRIANGLE OF A STORED', N, AF, LDAF,
     $             IPIVOT, WORK, LDWORK, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1050, INFO
        STOP 1
      END IF
C
C     Solve Ax=b and print the solution.
C
      CALL DSYTRS ('UPPER TRIANGLE OF A STORED', N, NRHS, AF, LDA,
     $             IPIVOT, X, LDX, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1060, INFO
        STOP 2
      END IF
      PRINT 1070
      PRINT 1080, X
      PRINT 1090
      PRINT 1040, A(1,1) * X(1,1) + A(1,2) * X(2,1)
      PRINT 1040, A(1,2) * X(1,1) + A(2,2) * X(2,1) + A(2,3) *
     $   X(3,1)
      PRINT 1040, A(2,3) * X(2,1) + A(3,3) * X(3,1) + A(3,4) *
     $   X(4,1)
      PRINT 1040,                   A(3,4) * X(3,1) + A(4,4) *
     $   X(4,1)
C
C     Refine the solution to Ax=b and print the refined solution.
C
      CALL DSYRFS ('UPPER TRIANGLE OF A STORED', N, NRHS, A, LDA,
     $             AF, LDAF, IPIVOT, B, LDB, X, LDX, FERR, BERR,
     $             WORK, IWORK, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1100, INFO
        STOP 3
      END IF
      PRINT 1110
      PRINT 1080, X
      PRINT 1120
      PRINT 1040, A(1,1) * X(1,1) + A(1,2) * X(2,1)
      PRINT 1040, A(1,2) * X(1,1) + A(2,2) * X(2,1) + A(2,3) *
     $   X(3,1)
      PRINT 1040, A(2,3) * X(2,1) + A(3,3) * X(3,1) + A(3,4) *
     $   X(4,1)
      PRINT 1040,                   A(3,4) * X(3,1) + A(4,4) *
     $   X(4,1)
      PRINT 1130, FERR(1)
      PRINT 1140, BERR(1)
C
 1000 FORMAT (1X, 'A in full form:')
 1010 FORMAT (4(2X, F18.16))
 1020 FORMAT (/1X, 'A in symmetric form:  (* in unused elements)')
 1030 FORMAT (/1X, 'b:')
 1040 FORMAT (1X, F22.17)
 1050 FORMAT (1X, 'Error factoring A, INFO = ', I5)
 1060 FORMAT (1X, 'Error solving Ax=b, INFO = ', I5)
 1070 FORMAT (/1X, 'Initial solution to Ax=b:')
 1080 FORMAT (1X, E25.17)
 1090 FORMAT (/1X, 'Ax with the initial x:')
 1100 FORMAT (1X, 'Illegal argument to DSYRFS, INFO = ', I3)
 1110 FORMAT (/1X, 'Refined solution to Ax=b:')
 1120 FORMAT (/1X, 'Ax with refined x:')
 1130 FORMAT (/1X, 'Forward error:  ', E14.8)
 1140 FORMAT (1X, 'Backward error: ', E14.8)
C
      END
 

Sample Output

 
 A in full form:
  0.0000000000000002  -.0000000000000001  0.0000000000000000  0.0000000000000000
  -.0000000000000001  2.0000000000000000  2.0000000000000000  0.0000000000000000
  0.0000000000000000  2.0000000000000000  2.0000000000000000  -.0000000000000001
  0.0000000000000000  0.0000000000000000  -.0000000000000001  0.0000000000000002



 A in symmetric form:  (* in unused elements)
  0.0000000000000002  -.0000000000000001  0.0000000000000000  0.0000000000000000
  ******************  2.0000000000000000  2.0000000000000000  0.0000000000000000
  ******************  ******************  2.0000000000000000  -.0000000000000001
  ******************  ******************  ******************  0.0000000000000002



 b:
    2.99999999999999956
    4.99999999999999911
    6.99999999999999911
   10.99999999999999822



 Initial solution to Ax=b:
   0.67553994410557432E+17
   0.10808639105689189E+18
  -0.10808639105689189E+18
  -0.45035996273704960E+16



 Ax with the initial x:
    3.00000000000000000
    0.00000000000000000
    0.50000000000000000
   10.99999999999999822



 Refined solution to Ax=b:
   0.67553994410557432E+17
   0.10808639105689189E+18
  -0.10808639105689189E+18
  -0.45035996273704960E+16



 Ax with refined x:
    3.00000000000000000
    0.00000000000000000
    0.50000000000000000
   10.99999999999999822



 Forward error:  0.73614937E-01
 Backward error: 0.11564823E-17






Previous Next Contents Generated Index Doc Set Home