1       SUBROUTINE DPOT03( UPLO, N, A, LDA, AINV, LDAINV, WORK, LDWORK,
  2      $                   RWORK, RCOND, RESID )
  3 *
  4 *  -- LAPACK test routine (version 3.1) --
  5 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  6 *     November 2006
  7 *
  8 *     .. Scalar Arguments ..
  9       CHARACTER          UPLO
 10       INTEGER            LDA, LDAINV, LDWORK, N
 11       DOUBLE PRECISION   RCOND, RESID
 12 *     ..
 13 *     .. Array Arguments ..
 14       DOUBLE PRECISION   A( LDA, * ), AINV( LDAINV, * ), RWORK( * ),
 15      $                   WORK( LDWORK, * )
 16 *     ..
 17 *
 18 *  Purpose
 19 *  =======
 20 *
 21 *  DPOT03 computes the residual for a symmetric matrix times its
 22 *  inverse:
 23 *     norm( I - A*AINV ) / ( N * norm(A) * norm(AINV) * EPS ),
 24 *  where EPS is the machine epsilon.
 25 *
 26 *  Arguments
 27 *  ==========
 28 *
 29 *  UPLO    (input) CHARACTER*1
 30 *          Specifies whether the upper or lower triangular part of the
 31 *          symmetric matrix A is stored:
 32 *          = 'U':  Upper triangular
 33 *          = 'L':  Lower triangular
 34 *
 35 *  N       (input) INTEGER
 36 *          The number of rows and columns of the matrix A.  N >= 0.
 37 *
 38 *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)
 39 *          The original symmetric matrix A.
 40 *
 41 *  LDA     (input) INTEGER
 42 *          The leading dimension of the array A.  LDA >= max(1,N)
 43 *
 44 *  AINV    (input/output) DOUBLE PRECISION array, dimension (LDAINV,N)
 45 *          On entry, the inverse of the matrix A, stored as a symmetric
 46 *          matrix in the same format as A.
 47 *          In this version, AINV is expanded into a full matrix and
 48 *          multiplied by A, so the opposing triangle of AINV will be
 49 *          changed; i.e., if the upper triangular part of AINV is
 50 *          stored, the lower triangular part will be used as work space.
 51 *
 52 *  LDAINV  (input) INTEGER
 53 *          The leading dimension of the array AINV.  LDAINV >= max(1,N).
 54 *
 55 *  WORK    (workspace) DOUBLE PRECISION array, dimension (LDWORK,N)
 56 *
 57 *  LDWORK  (input) INTEGER
 58 *          The leading dimension of the array WORK.  LDWORK >= max(1,N).
 59 *
 60 *  RWORK   (workspace) DOUBLE PRECISION array, dimension (N)
 61 *
 62 *  RCOND   (output) DOUBLE PRECISION
 63 *          The reciprocal of the condition number of A, computed as
 64 *          ( 1/norm(A) ) / norm(AINV).
 65 *
 66 *  RESID   (output) DOUBLE PRECISION
 67 *          norm(I - A*AINV) / ( N * norm(A) * norm(AINV) * EPS )
 68 *
 69 *  =====================================================================
 70 *
 71 *     .. Parameters ..
 72       DOUBLE PRECISION   ZERO, ONE
 73       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
 74 *     ..
 75 *     .. Local Scalars ..
 76       INTEGER            I, J
 77       DOUBLE PRECISION   AINVNM, ANORM, EPS
 78 *     ..
 79 *     .. External Functions ..
 80       LOGICAL            LSAME
 81       DOUBLE PRECISION   DLAMCH, DLANGE, DLANSY
 82       EXTERNAL           LSAME, DLAMCH, DLANGE, DLANSY
 83 *     ..
 84 *     .. External Subroutines ..
 85       EXTERNAL           DSYMM
 86 *     ..
 87 *     .. Intrinsic Functions ..
 88       INTRINSIC          DBLE
 89 *     ..
 90 *     .. Executable Statements ..
 91 *
 92 *     Quick exit if N = 0.
 93 *
 94       IF( N.LE.0 ) THEN
 95          RCOND = ONE
 96          RESID = ZERO
 97          RETURN
 98       END IF
 99 *
100 *     Exit with RESID = 1/EPS if ANORM = 0 or AINVNM = 0.
101 *
102       EPS = DLAMCH( 'Epsilon' )
103       ANORM = DLANSY( '1', UPLO, N, A, LDA, RWORK )
104       AINVNM = DLANSY( '1', UPLO, N, AINV, LDAINV, RWORK )
105       IF( ANORM.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN
106          RCOND = ZERO
107          RESID = ONE / EPS
108          RETURN
109       END IF
110       RCOND = ( ONE / ANORM ) / AINVNM
111 *
112 *     Expand AINV into a full matrix and call DSYMM to multiply
113 *     AINV on the left by A.
114 *
115       IF( LSAME( UPLO, 'U' ) ) THEN
116          DO 20 J = 1, N
117             DO 10 I = 1, J - 1
118                AINV( J, I ) = AINV( I, J )
119    10       CONTINUE
120    20    CONTINUE
121       ELSE
122          DO 40 J = 1, N
123             DO 30 I = J + 1, N
124                AINV( J, I ) = AINV( I, J )
125    30       CONTINUE
126    40    CONTINUE
127       END IF
128       CALL DSYMM( 'Left', UPLO, N, N, -ONE, A, LDA, AINV, LDAINV, ZERO,
129      $            WORK, LDWORK )
130 *
131 *     Add the identity matrix to WORK .
132 *
133       DO 50 I = 1, N
134          WORK( I, I ) = WORK( I, I ) + ONE
135    50 CONTINUE
136 *
137 *     Compute norm(I - A*AINV) / (N * norm(A) * norm(AINV) * EPS)
138 *
139       RESID = DLANGE( '1', N, N, WORK, LDWORK, RWORK )
140 *
141       RESID = ( ( RESID*RCOND ) / EPS ) / DBLE( N )
142 *
143       RETURN
144 *
145 *     End of DPOT03
146 *
147       END