Previous Next Contents Generated Index Doc Set Home



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

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

Calling Sequence

CALL ZHERFS 
(UPLO, N, NRHS, ZA, LDA, ZAF, LDAF, IPIVOT, ZB, LDB, 
ZX, LDX, DFERR, DBERR, ZWORK, DWORK2, INFO)
CALL CHERFS 
(UPLO, N, NRHS, CA, LDA, CAF, LDAF, IPIVOT, CB, LDB, 
CX, LDX, SFERR, SBERR, CWORK, SWORK2, INFO)






void zherfs 
(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 cherfs 
(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 xHETRF.

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

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 2 × 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
      DOUBLE PRECISION  ZERO
      INTEGER           LDA, LDAF, LDB, LDB1, LDWORK, LDWRK2, LDX
      INTEGER           N, NRHS
      PARAMETER        (N = 3)
      PARAMETER        (LDA = N)
      PARAMETER        (LDAF = LDA)
      PARAMETER        (LDB = N)
      PARAMETER        (LDB1 = N)
      PARAMETER        (LDWORK = 2 * N)
      PARAMETER        (LDWRK2 = N)
      PARAMETER        (LDX = LDB)
      PARAMETER        (NRHS = 1)
      PARAMETER        (ZERO = 0.0D0)
C
      DOUBLE PRECISION  BERR(N), FERR(N), WORK2(LDWRK2)
      COMPLEX*16        A(LDA,N), AF(LDA,N), B(LDB,NRHS)
      COMPLEX*16        B1(LDB,NRHS), INFNTY, WORK(LDWORK)
      COMPLEX*16        X(LDX,NRHS)
      INTEGER           ICOL, INFO, IPIVOT(N), IROW
C
      EXTERNAL          ZCOPY, ZHEMM, ZHERFS, ZHETRF, ZHETRS
      INTRINSIC         ABS, DCMPLX, DCONJG, DBLE, SQRT, MAX
C
C     Initialize the array A to store the coefficient array A
C     shown below.
C
C          (1e+16, 0)       (1e+16, 1)     (3e+16, 3e-16)
C     A =  (1e+16, -1)      (1e+16, 0)     (3e+26, 3e-16)
C         (3e+16, 3e-16)  (3e+26, -3e-16)    (7e-16, 0)
C
C     Initialize the array B to store the right-hand side vector b
C     shown below.
C
C         (2e-26, 2e+16)
C     b = (2e+26, 2e-16)
C             (2, 2)
C
      DATA A / (1.0D16,0.0D0),  (-8D300,-8D300),  (-8D300,-8D300),
     $         (1.0D16,1.0D0), (1.0D16,0.0D0),  (-8D300,-8D300),
     $         (3.0D16,3.0D-16), (3.0D26,3.0D-16),
     $         (7.0D-16,0.0D0) /
      DATA B / (2.0D-26,2.0D16), (2.0D26,2.0D-16), (2.0D0,2.0D0) /
C
C     Print the initial value of the arrays.
C
      INFNTY = DCMPLX(SQRT(-1.0D0), SQRT(-1.0D0))
      DO 110, IROW = 1, N
        DO 100, ICOL = 1, IROW - 1
          A(IROW,ICOL) = INFNTY
  100   CONTINUE
  110 CONTINUE
      PRINT 1000
      DO 120, IROW = 1, N
        PRINT 1010, (DCONJG(A(ICOL,IROW)), ICOL = 1, IROW - 1),
     $              DCMPLX(DBLE(A(IROW,IROW)), ZERO),
     $              (A(IROW,ICOL), ICOL = IROW + 1, N)
  120 CONTINUE
      PRINT 1020
      DO 130, IROW = 1, N
        PRINT 1010, (A(IROW,ICOL), ICOL = 1, N)
  130 CONTINUE
      DO 150, ICOL = 1, NRHS
        PRINT 1030, ICOL
        DO 140, IROW = 1, N
          PRINT 1080, B(IROW,ICOL)
  140   CONTINUE
  150 CONTINUE
C
C     Factor the matrix.
C
      CALL ZCOPY (LDA * N, A, 1, AF, 1)
      CALL ZHETRF ('UPPER TRIANGLE OF A STORED', N, AF, LDAF,
     $             IPIVOT, WORK, LDWORK, INFO)
      IF (INFO .LT. 0) THEN
        PRINT 1040, ABS(INFO)
        STOP 1
      ELSE IF (INFO .GT. 0) THEN
        PRINT 1050
        STOP 2
      END IF
C
C     Compute and print the solution.
C
      CALL ZCOPY (LDB * NRHS, B, 1, X, 1)
      CALL ZHETRS ('UPPER TRIANGULAR FACTOR OF A', N, NRHS, AF,
     $             LDAF, IPIVOT, X, LDX, INFO)
      IF (INFO .LT. 0) THEN
        PRINT 1060, ABS(INFO)
        STOP 3
      END IF
      DO 210, ICOL = 1, NRHS
        PRINT 1070, ICOL
        DO 200, IROW = 1, N
          PRINT 1080, X(IROW,ICOL)
  200   CONTINUE
  210 CONTINUE
      CALL ZHEMM ('LEFT SIDE: AX', 'UPPER TRIANGLE OF A STORED',
     $            N, NRHS, DCMPLX(1.0D0,ZERO), A, LDA, X, LDX,
     $            DCMPLX(ZERO,ZERO), B1, LDB1)
      DO 230, ICOL = 1, NRHS
        PRINT 1090, ICOL
        DO 220, IROW = 1, N
          PRINT 1080, B1(IROW,ICOL)
  220   CONTINUE
  230 CONTINUE
C
C     Refine the solution and print the refined solution with the
C     error bounds.
C
      CALL ZHERFS ('UPPER TRIANGLE OF A STORED', N, NRHS, A, LDA,
     $             AF, LDAF, IPIVOT, B, LDB, X, LDX, FERR, BERR,
     $             WORK, WORK2, INFO)
      DO 310, ICOL = 1, NRHS
        PRINT 1100, ICOL
        DO 300, IROW = 1, N
          PRINT 1080, X(IROW,ICOL)
  300   CONTINUE
  310 CONTINUE
      CALL ZHEMM ('LEFT SIDE: AX', 'UPPER TRIANGLE OF A STORED',
     $            N, NRHS, DCMPLX(1.0D0,ZERO), A, LDA, X, LDX,
     $            DCMPLX(ZERO,ZERO), B1, LDB1)
      DO 330, ICOL = 1, NRHS
        PRINT 1110, ICOL
        DO 320, IROW = 1, N
          PRINT 1080, B1(IROW,ICOL)
  320   CONTINUE
  330 CONTINUE
      DO 340, IROW = 1, NRHS
        PRINT 1120, IROW, BERR(IROW)
        PRINT 1130, IROW, FERR(IROW)
  340 CONTINUE
C
 1000 FORMAT (1X, 'A in full form:')
 1010 FORMAT (1X, 10(: 1X, '(', E8.2, ', ', E8.2, ')'))
 1020 FORMAT (/1X, 'A in Hermitian form: ',
     $        ' ("NaN" in unused entries)')
 1030 FORMAT (/1X, 'b for system #', I1)
 1040 FORMAT (1X, 'Illegal argument to ZHETRF, argument #', I2)
 1050 FORMAT (1X, 'A is singular to working precision.')
 1060 FORMAT (1X, 'Illegal argument to ZHETRS, argument #', I2)
 1070 FORMAT (/1X, 'Initial x for system #', I1)
 1080 FORMAT (3X, '(', E20.14, ', ', E20.14, ')')
 1090 FORMAT (/1X, 'Ax with initial x for system #', I1)
 1100 FORMAT (/1X, 'Refined x for system #', I1)
 1110 FORMAT (/1X, 'Ax with refined x for system #', I1)
 1120 FORMAT (/1X, 'Backward error for system #', I1, ': ', E12.6)
 1130 FORMAT (1X, 'Forward error for system #', I1, ':  ', E12.6)
C
      END
 

Sample Output

 
 A in full form:
  (0.10E+17, 0.00E+00) (0.10E+17, 0.10E+01) (0.30E+17, 0.30E-15)
  (0.10E+17, -.10E+01) (0.10E+17, 0.00E+00) (0.30E+27, 0.30E-15)
  (0.30E+17, -.30E-15) (0.30E+27, -.30E-15) (0.70E-15, 0.00E+00)



 A in Hermitian form:  ("NaN" in unused entries)
  (0.10E+17, 0.00E+00) (0.10E+17, 0.10E+01) (0.30E+17, 0.30E-15)
  (NaN     , NaN     ) (0.10E+17, 0.00E+00) (0.30E+27, 0.30E-15)
  (NaN     , NaN     ) (NaN     , NaN     ) (0.70E-15, 0.00E+00)



 b for system #1
   (0.20000000000000E-25, 0.20000000000000E+17)
   (0.20000000000000E+27, 0.20000000000000E-15)
   (0.20000000000000E+01, 0.20000000000000E+01)



 Initial x for system #1
   (-.20000000004000E+01, 0.20000000004000E+01)
   (0.20000000004000E-09, -.20000000004000E-09)
   (0.66666666673333E+00, -.66666666673333E-10)



 Ax with initial x for system #1
   (0.40000000000000E+01, 0.20000000000000E+17)
   (0.20000000000000E+27, 0.40000000000000E+01)
   (-.80000000000000E+01, 0.80000000000000E+01)



 Refined x for system #1
   (-.20000000004000E+01, 0.20000000004000E+01)
   (0.20000000004000E-09, -.20000000004000E-09)
   (0.66666666673333E+00, -.66666666673333E-10)



 Ax with refined x for system #1
   (0.40000000000000E+01, 0.20000000000000E+17)
   (0.20000000000000E+27, 0.40000000000000E+01)
   (-.80000000000000E+01, 0.80000000000000E+01)



 Backward error for system #1: 0.666667E-16
 Forward error for system #1:  0.143228E-14






Previous Next Contents Generated Index Doc Set Home