Previous Next Contents Generated Index Doc Set Home



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

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

Calling Sequence

CALL ZHESVX 
(FACT, UPLO, N, NRHS, ZA, LDA, ZAF, LDAF, IPIVOT, ZB, 
LDB, ZX, LDX, DRCOND, DFERR, DBERR, ZWORK, LDWORK, 
DWORK2, INFO)
CALL CHESVX 
(FACT, UPLO, N, NRHS, CA, LDA, CAF, LDAF, IPIVOT, CB, 
LDB, CX, LDX, SRCOND, SFERR, SBERR, CWORK, LDWORK, 
SWORK2, INFO)






void zhesvx 
(char fact, 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 *drcond, double *dferr, double 
*dberr, int *info)
void chesvx 
(char fact, 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 *srcond, 
float *sferr, float *sberr, int *info)

Arguments

FACT

Indicates whether or not the factored form of the matrix A is supplied on entry.

'F' or 'f'

On entry, AF and IPIVOT contain the factored form of A. A, AF, and IPIVOT will not be modified.

'N' or 'n'

On entry, the matrix A will be copied to AF and factored.

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 in 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

On entry, if FACT = 'F' or 'f' then AF contains the UDU or LDL factorization of A as computed by xHETRF. Otherwise the entry value of AF is not used.

On exit, if FACT = 'N' or 'n' then AF contains the UDU or LDL factorization of A as computed by xHETRF. Otherwise AF is unchanged.

LDAF

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

IPIVOT

On entry, if FACT = 'F' or 'f', IPIVOT contains pivot indices as computed by xHETRF. Otherwise the entry value is not used.
On exit, if FACT = 'N' or 'n', IPIVOT contains pivot indices as computed by xHETRF. Otherwise IPIVOT is unchanged.

xB

On entry, 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 exit, the N×NRHS solution matrix for the original problem.

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

LDWORK

Leading dimension of the array WORK as specified in a dimension or type statement. LDWORK 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.

1 INFO N

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

INFO = N+1

D is nonsingular, but RCOND is less than machine precision. The UDU or LDL factorization of A has been completed, but the solution and error bounds could not be computed.

Sample Program




      PROGRAM TEST
      IMPLICIT NONE
C
      DOUBLE PRECISION  ZERO
      INTEGER           LDA, LDAF, LDB, LDWORK, LDWRK2, LDX
      INTEGER           N, NRHS
      PARAMETER        (N = 3)
      PARAMETER        (LDA = N)
      PARAMETER        (LDAF = N)
      PARAMETER        (LDB = N)
      PARAMETER        (LDWORK = 2 * N)
      PARAMETER        (LDWRK2 = N)
      PARAMETER        (LDX = N)
      PARAMETER        (NRHS = 1)
      PARAMETER        (ZERO = 0.0D0)
C
      DOUBLE PRECISION  BERR(NRHS), FERR(NRHS), RCOND
      DOUBLE PRECISION  WORK2(LDWRK2)
      COMPLEX*16        A(LDA,N), AF(LDAF,N), B(LDB,NRHS)
      COMPLEX*16        WORK(LDWORK)
      COMPLEX*16        X(LDX,NRHS)
      INTEGER           ICOL, INFO, IPIVOT(N), IROW
C
      EXTERNAL          ZHESVX
      INTRINSIC         ABS, CMPLX, CONJG
C
C     Initialize the array A to store the coefficient array A
C     shown below.  Initialize the array B to store the right
C     hand side vector b shown below.
C
      DATA A / (1.0D0,8D8),    (8D8,8D8),      (8D8,8D8),
     $         (1.0D0,-1.0D0), (3.0D0,8D8),    (8D8,8D8),
     $         (1.0D0,-1.0D0), (3.0D0,-1.0D0), (5.0D0,8D8) /
      DATA B / (4.0D0,1.0D0), (4.0D0,6.0D0), (4.0D0,7.0D0) /
C
C     Print the initial value of the arrays.
C
      PRINT 1000
      DO 100, IROW = 1, N
        PRINT 1010, (CONJG(A(ICOL,IROW)), ICOL = 1, IROW - 1),
     $              CMPLX(A(IROW,IROW), ZERO),
     $              (A(IROW,ICOL), ICOL = IROW, N)
  100 CONTINUE
      PRINT 1020
      DO 110, IROW = 1, N
        PRINT 1010, (A(IROW,ICOL), ICOL = 1, N)
  110 CONTINUE
      PRINT 1030
      DO 130, ICOL = 1, NRHS
        DO 120, IROW = 1, N
          PRINT 1010, B(IROW,ICOL)
  120   CONTINUE
  130 CONTINUE
C
C     Compute the solution.
C
      CALL ZHESVX ('NOT FACTORED A', 'UPPER TRIANGLE OF A STORED',
     $             N, NRHS, A, LDA, AF, LDAF, IPIVOT, B, LDB, X,
     $             LDX, RCOND, FERR, BERR, WORK, LDWORK, WORK2,
     $             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     Print the solution and error bounds.
C
      PRINT 1060
      DO 210, ICOL = 1, NRHS
        DO 200, IROW = 1, N
          PRINT 1010, X(IROW,ICOL)
  200   CONTINUE
  210 CONTINUE
      PRINT 1070, RCOND
      DO 220, IROW = 1, NRHS
        PRINT 1080, IROW, BERR(IROW)
        PRINT 1090, IROW, FERR(IROW)
  220 CONTINUE
C
 1000 FORMAT (1X, 'A in full form:')
 1010 FORMAT (1X, 10(: 2X, '(', F4.1, ',', F4.1, ')'))
 1020 FORMAT (/1X, 'A in Hermitian form:  (* in unused entries)')
 1030 FORMAT (/1X, 'b:')
 1040 FORMAT (1X, 'Illegal argument to ZHESVX, argument #', I2)
 1050 FORMAT (1X, 'A is singular to working precision.')
 1060 FORMAT (/1X, 'x:')
 1070 FORMAT (/1X,
     $        'Estimated reciprocal condition number of A: ',
     $        F5.3)
 1080 FORMAT (/1X, 'Backward error for system #', I2, ': ', E12.5)
 1090 FORMAT (1X, 'Forward error for system #', I2, ':  ', E12.5)
C
      END
 

Sample Output

 
 A in full form:
   ( 1.0, 0.0)  ( 1.0,****)  ( 1.0,-1.0)  ( 1.0,-1.0)
   ( 1.0, 1.0)  ( 3.0, 0.0)  ( 3.0,****)  ( 3.0,-1.0)
   ( 1.0, 1.0)  ( 3.0, 1.0)  ( 5.0, 0.0)  ( 5.0,****)



 A in Hermitian form:  (* in unused entries)
   ( 1.0,****)  ( 1.0,-1.0)  ( 1.0,-1.0)
   (****,****)  ( 3.0,****)  ( 3.0,-1.0)
   (****,****)  (****,****)  ( 5.0,****)



 b:
   ( 4.0, 1.0)
   ( 4.0, 6.0)
   ( 4.0, 7.0)



 x:
   ( 1.0, 0.0)
   ( 0.0, 2.0)
   ( 1.0, 0.0)



 Estimated reciprocal condition number of A: 0.011



 Backward error for system # 1:  0.74015E-16
 Forward error for system # 1:   0.40366E-13






Previous Next Contents Generated Index Doc Set Home