1       SUBROUTINE DPTT05( N, NRHS, D, E, B, LDB, X, LDX, XACT, LDXACT,
  2      $                   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       INTEGER            LDB, LDX, LDXACT, N, NRHS
 10 *     ..
 11 *     .. Array Arguments ..
 12       DOUBLE PRECISION   B( LDB, * ), BERR( * ), D( * ), E( * ),
 13      $                   FERR( * ), RESLTS( * ), X( LDX, * ),
 14      $                   XACT( LDXACT, * )
 15 *     ..
 16 *
 17 *  Purpose
 18 *  =======
 19 *
 20 *  DPTT05 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 tridiagonal matrix of order n.
 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 / ( NZ*EPS + (*) ), where
 31 *              (*) = NZ*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
 32 *              and NZ = max. number of nonzeros in any row of A, plus 1
 33 *
 34 *  Arguments
 35 *  =========
 36 *
 37 *  N       (input) INTEGER
 38 *          The number of rows of the matrices X, B, and XACT, and the
 39 *          order of the matrix A.  N >= 0.
 40 *
 41 *  NRHS    (input) INTEGER
 42 *          The number of columns of the matrices X, B, and XACT.
 43 *          NRHS >= 0.
 44 *
 45 *  D       (input) DOUBLE PRECISION array, dimension (N)
 46 *          The n diagonal elements of the tridiagonal matrix A.
 47 *
 48 *  E       (input) DOUBLE PRECISION array, dimension (N-1)
 49 *          The (n-1) subdiagonal elements of the tridiagonal matrix A.
 50 *
 51 *  B       (input) DOUBLE PRECISION array, dimension (LDB,NRHS)
 52 *          The right hand side vectors for the system of linear
 53 *          equations.
 54 *
 55 *  LDB     (input) INTEGER
 56 *          The leading dimension of the array B.  LDB >= max(1,N).
 57 *
 58 *  X       (input) DOUBLE PRECISION array, dimension (LDX,NRHS)
 59 *          The computed solution vectors.  Each vector is stored as a
 60 *          column of the matrix X.
 61 *
 62 *  LDX     (input) INTEGER
 63 *          The leading dimension of the array X.  LDX >= max(1,N).
 64 *
 65 *  XACT    (input) DOUBLE PRECISION array, dimension (LDX,NRHS)
 66 *          The exact solution vectors.  Each vector is stored as a
 67 *          column of the matrix XACT.
 68 *
 69 *  LDXACT  (input) INTEGER
 70 *          The leading dimension of the array XACT.  LDXACT >= max(1,N).
 71 *
 72 *  FERR    (input) DOUBLE PRECISION array, dimension (NRHS)
 73 *          The estimated forward error bounds for each solution vector
 74 *          X.  If XTRUE is the true solution, FERR bounds the magnitude
 75 *          of the largest entry in (X - XTRUE) divided by the magnitude
 76 *          of the largest entry in X.
 77 *
 78 *  BERR    (input) DOUBLE PRECISION array, dimension (NRHS)
 79 *          The componentwise relative backward error of each solution
 80 *          vector (i.e., the smallest relative change in any entry of A
 81 *          or B that makes X an exact solution).
 82 *
 83 *  RESLTS  (output) DOUBLE PRECISION array, dimension (2)
 84 *          The maximum over the NRHS solution vectors of the ratios:
 85 *          RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR )
 86 *          RESLTS(2) = BERR / ( NZ*EPS + (*) )
 87 *
 88 *  =====================================================================
 89 *
 90 *     .. Parameters ..
 91       DOUBLE PRECISION   ZERO, ONE
 92       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
 93 *     ..
 94 *     .. Local Scalars ..
 95       INTEGER            I, IMAX, J, K, NZ
 96       DOUBLE PRECISION   AXBI, DIFF, EPS, ERRBND, OVFL, TMP, UNFL, XNORM
 97 *     ..
 98 *     .. External Functions ..
 99       INTEGER            IDAMAX
100       DOUBLE PRECISION   DLAMCH
101       EXTERNAL           IDAMAX, DLAMCH
102 *     ..
103 *     .. Intrinsic Functions ..
104       INTRINSIC          ABSMAXMIN
105 *     ..
106 *     .. Executable Statements ..
107 *
108 *     Quick exit if N = 0 or NRHS = 0.
109 *
110       IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
111          RESLTS( 1 ) = ZERO
112          RESLTS( 2 ) = ZERO
113          RETURN
114       END IF
115 *
116       EPS = DLAMCH( 'Epsilon' )
117       UNFL = DLAMCH( 'Safe minimum' )
118       OVFL = ONE / UNFL
119       NZ = 4
120 *
121 *     Test 1:  Compute the maximum of
122 *        norm(X - XACT) / ( norm(X) * FERR )
123 *     over all the vectors X and XACT using the infinity-norm.
124 *
125       ERRBND = ZERO
126       DO 30 J = 1, NRHS
127          IMAX = IDAMAX( N, X( 1, J ), 1 )
128          XNORM = MAXABS( X( IMAX, J ) ), UNFL )
129          DIFF = ZERO
130          DO 10 I = 1, N
131             DIFF = MAX( DIFF, ABS( X( I, J )-XACT( I, J ) ) )
132    10    CONTINUE
133 *
134          IF( XNORM.GT.ONE ) THEN
135             GO TO 20
136          ELSE IF( DIFF.LE.OVFL*XNORM ) THEN
137             GO TO 20
138          ELSE
139             ERRBND = ONE / EPS
140             GO TO 30
141          END IF
142 *
143    20    CONTINUE
144          IF( DIFF / XNORM.LE.FERR( J ) ) THEN
145             ERRBND = MAX( ERRBND, ( DIFF / XNORM ) / FERR( J ) )
146          ELSE
147             ERRBND = ONE / EPS
148          END IF
149    30 CONTINUE
150       RESLTS( 1 ) = ERRBND
151 *
152 *     Test 2:  Compute the maximum of BERR / ( NZ*EPS + (*) ), where
153 *     (*) = NZ*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
154 *
155       DO 50 K = 1, NRHS
156          IF( N.EQ.1 ) THEN
157             AXBI = ABS( B( 1, K ) ) + ABS( D( 1 )*X( 1, K ) )
158          ELSE
159             AXBI = ABS( B( 1, K ) ) + ABS( D( 1 )*X( 1, K ) ) +
160      $             ABS( E( 1 )*X( 2, K ) )
161             DO 40 I = 2, N - 1
162                TMP = ABS( B( I, K ) ) + ABS( E( I-1 )*X( I-1, K ) ) +
163      $               ABS( D( I )*X( I, K ) ) + ABS( E( I )*X( I+1, K ) )
164                AXBI = MIN( AXBI, TMP )
165    40       CONTINUE
166             TMP = ABS( B( N, K ) ) + ABS( E( N-1 )*X( N-1, K ) ) +
167      $            ABS( D( N )*X( N, K ) )
168             AXBI = MIN( AXBI, TMP )
169          END IF
170          TMP = BERR( K ) / ( NZ*EPS+NZ*UNFL / MAX( AXBI, NZ*UNFL ) )
171          IF( K.EQ.1 ) THEN
172             RESLTS( 2 ) = TMP
173          ELSE
174             RESLTS( 2 ) = MAX( RESLTS( 2 ), TMP )
175          END IF
176    50 CONTINUE
177 *
178       RETURN
179 *
180 *     End of DPTT05
181 *
182       END