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