1       SUBROUTINE SPOT05( UPLO, N, NRHS, A, LDA, B, LDB, X, LDX, XACT,
  2      $                   LDXACT, FERR, BERR, RESLTS )
  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, LDB, LDX, LDXACT, N, NRHS
 11 *     ..
 12 *     .. Array Arguments ..
 13       REAL               A( LDA, * ), B( LDB, * ), BERR( * ), FERR( * ),
 14      $                   RESLTS( * ), X( LDX, * ), XACT( LDXACT, * )
 15 *     ..
 16 *
 17 *  Purpose
 18 *  =======
 19 *
 20 *  SPOT05 tests the error bounds from iterative refinement for the
 21 *  computed solution to a system of equations A*X = B, where A is a
 22 *  symmetric n by n matrix.
 23 *
 24 *  RESLTS(1) = test of the error bound
 25 *            = norm(X - XACT) / ( norm(X) * FERR )
 26 *
 27 *  A large value is returned if this ratio is not less than one.
 28 *
 29 *  RESLTS(2) = residual from the iterative refinement routine
 30 *            = the maximum of BERR / ( (n+1)*EPS + (*) ), where
 31 *              (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
 32 *
 33 *  Arguments
 34 *  =========
 35 *
 36 *  UPLO    (input) CHARACTER*1
 37 *          Specifies whether the upper or lower triangular part of the
 38 *          symmetric matrix A is stored.
 39 *          = 'U':  Upper triangular
 40 *          = 'L':  Lower triangular
 41 *
 42 *  N       (input) INTEGER
 43 *          The number of rows of the matrices X, B, and XACT, and the
 44 *          order of the matrix A.  N >= 0.
 45 *
 46 *  NRHS    (input) INTEGER
 47 *          The number of columns of the matrices X, B, and XACT.
 48 *          NRHS >= 0.
 49 *
 50 *  A       (input) REAL array, dimension (LDA,N)
 51 *          The symmetric matrix A.  If UPLO = 'U', the leading n by n
 52 *          upper triangular part of A contains the upper triangular part
 53 *          of the matrix A, and the strictly lower triangular part of A
 54 *          is not referenced.  If UPLO = 'L', the leading n by n lower
 55 *          triangular part of A contains the lower triangular part of
 56 *          the matrix A, and the strictly upper triangular part of A is
 57 *          not referenced.
 58 *
 59 *  LDA     (input) INTEGER
 60 *          The leading dimension of the array A.  LDA >= max(1,N).
 61 *
 62 *  B       (input) REAL array, dimension (LDB,NRHS)
 63 *          The right hand side vectors for the system of linear
 64 *          equations.
 65 *
 66 *  LDB     (input) INTEGER
 67 *          The leading dimension of the array B.  LDB >= max(1,N).
 68 *
 69 *  X       (input) REAL array, dimension (LDX,NRHS)
 70 *          The computed solution vectors.  Each vector is stored as a
 71 *          column of the matrix X.
 72 *
 73 *  LDX     (input) INTEGER
 74 *          The leading dimension of the array X.  LDX >= max(1,N).
 75 *
 76 *  XACT    (input) REAL array, dimension (LDX,NRHS)
 77 *          The exact solution vectors.  Each vector is stored as a
 78 *          column of the matrix XACT.
 79 *
 80 *  LDXACT  (input) INTEGER
 81 *          The leading dimension of the array XACT.  LDXACT >= max(1,N).
 82 *
 83 *  FERR    (input) REAL array, dimension (NRHS)
 84 *          The estimated forward error bounds for each solution vector
 85 *          X.  If XTRUE is the true solution, FERR bounds the magnitude
 86 *          of the largest entry in (X - XTRUE) divided by the magnitude
 87 *          of the largest entry in X.
 88 *
 89 *  BERR    (input) REAL array, dimension (NRHS)
 90 *          The componentwise relative backward error of each solution
 91 *          vector (i.e., the smallest relative change in any entry of A
 92 *          or B that makes X an exact solution).
 93 *
 94 *  RESLTS  (output) REAL array, dimension (2)
 95 *          The maximum over the NRHS solution vectors of the ratios:
 96 *          RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR )
 97 *          RESLTS(2) = BERR / ( (n+1)*EPS + (*) )
 98 *
 99 *  =====================================================================
100 *
101 *     .. Parameters ..
102       REAL               ZERO, ONE
103       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
104 *     ..
105 *     .. Local Scalars ..
106       LOGICAL            UPPER
107       INTEGER            I, IMAX, J, K
108       REAL               AXBI, DIFF, EPS, ERRBND, OVFL, TMP, UNFL, XNORM
109 *     ..
110 *     .. External Functions ..
111       LOGICAL            LSAME
112       INTEGER            ISAMAX
113       REAL               SLAMCH
114       EXTERNAL           LSAME, ISAMAX, SLAMCH
115 *     ..
116 *     .. Intrinsic Functions ..
117       INTRINSIC          ABSMAXMIN
118 *     ..
119 *     .. Executable Statements ..
120 *
121 *     Quick exit if N = 0 or NRHS = 0.
122 *
123       IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
124          RESLTS( 1 ) = ZERO
125          RESLTS( 2 ) = ZERO
126          RETURN
127       END IF
128 *
129       EPS = SLAMCH( 'Epsilon' )
130       UNFL = SLAMCH( 'Safe minimum' )
131       OVFL = ONE / UNFL
132       UPPER = LSAME( UPLO, 'U' )
133 *
134 *     Test 1:  Compute the maximum of
135 *        norm(X - XACT) / ( norm(X) * FERR )
136 *     over all the vectors X and XACT using the infinity-norm.
137 *
138       ERRBND = ZERO
139       DO 30 J = 1, NRHS
140          IMAX = ISAMAX( N, X( 1, J ), 1 )
141          XNORM = MAXABS( X( IMAX, J ) ), UNFL )
142          DIFF = ZERO
143          DO 10 I = 1, N
144             DIFF = MAX( DIFF, ABS( X( I, J )-XACT( I, J ) ) )
145    10    CONTINUE
146 *
147          IF( XNORM.GT.ONE ) THEN
148             GO TO 20
149          ELSE IF( DIFF.LE.OVFL*XNORM ) THEN
150             GO TO 20
151          ELSE
152             ERRBND = ONE / EPS
153             GO TO 30
154          END IF
155 *
156    20    CONTINUE
157          IF( DIFF / XNORM.LE.FERR( J ) ) THEN
158             ERRBND = MAX( ERRBND, ( DIFF / XNORM ) / FERR( J ) )
159          ELSE
160             ERRBND = ONE / EPS
161          END IF
162    30 CONTINUE
163       RESLTS( 1 ) = ERRBND
164 *
165 *     Test 2:  Compute the maximum of BERR / ( (n+1)*EPS + (*) ), where
166 *     (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
167 *
168       DO 90 K = 1, NRHS
169          DO 80 I = 1, N
170             TMP = ABS( B( I, K ) )
171             IF( UPPER ) THEN
172                DO 40 J = 1, I
173                   TMP = TMP + ABS( A( J, I ) )*ABS( X( J, K ) )
174    40          CONTINUE
175                DO 50 J = I + 1, N
176                   TMP = TMP + ABS( A( I, J ) )*ABS( X( J, K ) )
177    50          CONTINUE
178             ELSE
179                DO 60 J = 1, I - 1
180                   TMP = TMP + ABS( A( I, J ) )*ABS( X( J, K ) )
181    60          CONTINUE
182                DO 70 J = I, N
183                   TMP = TMP + ABS( A( J, I ) )*ABS( X( J, K ) )
184    70          CONTINUE
185             END IF
186             IF( I.EQ.1 ) THEN
187                AXBI = TMP
188             ELSE
189                AXBI = MIN( AXBI, TMP )
190             END IF
191    80    CONTINUE
192          TMP = BERR( K ) / ( ( N+1 )*EPS+( N+1 )*UNFL /
193      $         MAX( AXBI, ( N+1 )*UNFL ) )
194          IF( K.EQ.1 ) THEN
195             RESLTS( 2 ) = TMP
196          ELSE
197             RESLTS( 2 ) = MAX( RESLTS( 2 ), TMP )
198          END IF
199    90 CONTINUE
200 *
201       RETURN
202 *
203 *     End of SPOT05
204 *
205       END