1       SUBROUTINE CPTT02( UPLO, N, NRHS, D, E, X, LDX, B, LDB, RESID )
  2 *
  3 *  -- LAPACK test routine (version 3.1) --
  4 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  5 *     November 2006
  6 *
  7 *     .. Scalar Arguments ..
  8       CHARACTER          UPLO
  9       INTEGER            LDB, LDX, N, NRHS
 10       REAL               RESID
 11 *     ..
 12 *     .. Array Arguments ..
 13       REAL               D( * )
 14       COMPLEX            B( LDB, * ), E( * ), X( LDX, * )
 15 *     ..
 16 *
 17 *  Purpose
 18 *  =======
 19 *
 20 *  CPTT02 computes the residual for the solution to a symmetric
 21 *  tridiagonal system of equations:
 22 *     RESID = norm(B - A*X) / (norm(A) * norm(X) * EPS),
 23 *  where EPS is the machine epsilon.
 24 *
 25 *  Arguments
 26 *  =========
 27 *
 28 *  UPLO    (input) CHARACTER*1
 29 *          Specifies whether the superdiagonal or the subdiagonal of the
 30 *          tridiagonal matrix A is stored.
 31 *          = 'U':  E is the superdiagonal of A
 32 *          = 'L':  E is the subdiagonal of A
 33 *
 34 *  N       (input) INTEGTER
 35 *          The order of the matrix A.
 36 *
 37 *  NRHS    (input) INTEGER
 38 *          The number of right hand sides, i.e., the number of columns
 39 *          of the matrices B and X.  NRHS >= 0.
 40 *
 41 *  D       (input) REAL array, dimension (N)
 42 *          The n diagonal elements of the tridiagonal matrix A.
 43 *
 44 *  E       (input) COMPLEX array, dimension (N-1)
 45 *          The (n-1) subdiagonal elements of the tridiagonal matrix A.
 46 *
 47 *  X       (input) COMPLEX array, dimension (LDX,NRHS)
 48 *          The n by nrhs matrix of solution vectors X.
 49 *
 50 *  LDX     (input) INTEGER
 51 *          The leading dimension of the array X.  LDX >= max(1,N).
 52 *
 53 *  B       (input/output) COMPLEX array, dimension (LDB,NRHS)
 54 *          On entry, the n by nrhs matrix of right hand side vectors B.
 55 *          On exit, B is overwritten with the difference B - A*X.
 56 *
 57 *  LDB     (input) INTEGER
 58 *          The leading dimension of the array B.  LDB >= max(1,N).
 59 *
 60 *  RESID   (output) REAL
 61 *          norm(B - A*X) / (norm(A) * norm(X) * EPS)
 62 *
 63 *  =====================================================================
 64 *
 65 *     .. Parameters ..
 66       REAL               ONE, ZERO
 67       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
 68 *     ..
 69 *     .. Local Scalars ..
 70       INTEGER            J
 71       REAL               ANORM, BNORM, EPS, XNORM
 72 *     ..
 73 *     .. External Functions ..
 74       REAL               CLANHT, SCASUM, SLAMCH
 75       EXTERNAL           CLANHT, SCASUM, SLAMCH
 76 *     ..
 77 *     .. Intrinsic Functions ..
 78       INTRINSIC          MAX
 79 *     ..
 80 *     .. External Subroutines ..
 81       EXTERNAL           CLAPTM
 82 *     ..
 83 *     .. Executable Statements ..
 84 *
 85 *     Quick return if possible
 86 *
 87       IF( N.LE.0 ) THEN
 88          RESID = ZERO
 89          RETURN
 90       END IF
 91 *
 92 *     Compute the 1-norm of the tridiagonal matrix A.
 93 *
 94       ANORM = CLANHT( '1', N, D, E )
 95 *
 96 *     Exit with RESID = 1/EPS if ANORM = 0.
 97 *
 98       EPS = SLAMCH( 'Epsilon' )
 99       IF( ANORM.LE.ZERO ) THEN
100          RESID = ONE / EPS
101          RETURN
102       END IF
103 *
104 *     Compute B - A*X.
105 *
106       CALL CLAPTM( UPLO, N, NRHS, -ONE, D, E, X, LDX, ONE, B, LDB )
107 *
108 *     Compute the maximum over the number of right hand sides of
109 *        norm(B - A*X) / ( norm(A) * norm(X) * EPS ).
110 *
111       RESID = ZERO
112       DO 10 J = 1, NRHS
113          BNORM = SCASUM( N, B( 1, J ), 1 )
114          XNORM = SCASUM( N, X( 1, J ), 1 )
115          IF( XNORM.LE.ZERO ) THEN
116             RESID = ONE / EPS
117          ELSE
118             RESID = MAX( RESID, ( ( BNORM / ANORM ) / XNORM ) / EPS )
119          END IF
120    10 CONTINUE
121 *
122       RETURN
123 *
124 *     End of CPTT02
125 *
126       END