LAPACK 3.3.1 Linear Algebra PACKage

# strt02.f

Go to the documentation of this file.
```00001       SUBROUTINE STRT02( UPLO, TRANS, DIAG, N, NRHS, A, LDA, X, LDX, B,
00002      \$                   LDB, WORK, RESID )
00003 *
00004 *  -- LAPACK test routine (version 3.1) --
00005 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
00006 *     November 2006
00007 *
00008 *     .. Scalar Arguments ..
00009       CHARACTER          DIAG, TRANS, UPLO
00010       INTEGER            LDA, LDB, LDX, N, NRHS
00011       REAL               RESID
00012 *     ..
00013 *     .. Array Arguments ..
00014       REAL               A( LDA, * ), B( LDB, * ), WORK( * ),
00015      \$                   X( LDX, * )
00016 *     ..
00017 *
00018 *  Purpose
00019 *  =======
00020 *
00021 *  STRT02 computes the residual for the computed solution to a
00022 *  triangular system of linear equations  A*x = b  or  A'*x = b.
00023 *  Here A is a triangular matrix, A' is the transpose of A, and x and b
00024 *  are N by NRHS matrices.  The test ratio is the maximum over the
00025 *  number of right hand sides of
00026 *     norm(b - op(A)*x) / ( norm(op(A)) * norm(x) * EPS ),
00027 *  where op(A) denotes A or A' and EPS is the machine epsilon.
00028 *
00029 *  Arguments
00030 *  =========
00031 *
00032 *  UPLO    (input) CHARACTER*1
00033 *          Specifies whether the matrix A is upper or lower triangular.
00034 *          = 'U':  Upper triangular
00035 *          = 'L':  Lower triangular
00036 *
00037 *  TRANS   (input) CHARACTER*1
00038 *          Specifies the operation applied to A.
00039 *          = 'N':  A *x = b  (No transpose)
00040 *          = 'T':  A'*x = b  (Transpose)
00041 *          = 'C':  A'*x = b  (Conjugate transpose = Transpose)
00042 *
00043 *  DIAG    (input) CHARACTER*1
00044 *          Specifies whether or not the matrix A is unit triangular.
00045 *          = 'N':  Non-unit triangular
00046 *          = 'U':  Unit triangular
00047 *
00048 *  N       (input) INTEGER
00049 *          The order of the matrix A.  N >= 0.
00050 *
00051 *  NRHS    (input) INTEGER
00052 *          The number of right hand sides, i.e., the number of columns
00053 *          of the matrices X and B.  NRHS >= 0.
00054 *
00055 *  A       (input) REAL array, dimension (LDA,N)
00056 *          The triangular matrix A.  If UPLO = 'U', the leading n by n
00057 *          upper triangular part of the array A contains the upper
00058 *          triangular matrix, and the strictly lower triangular part of
00059 *          A is not referenced.  If UPLO = 'L', the leading n by n lower
00060 *          triangular part of the array A contains the lower triangular
00061 *          matrix, and the strictly upper triangular part of A is not
00062 *          referenced.  If DIAG = 'U', the diagonal elements of A are
00063 *          also not referenced and are assumed to be 1.
00064 *
00065 *  LDA     (input) INTEGER
00066 *          The leading dimension of the array A.  LDA >= max(1,N).
00067 *
00068 *  X       (input) REAL array, dimension (LDX,NRHS)
00069 *          The computed solution vectors for the system of linear
00070 *          equations.
00071 *
00072 *  LDX     (input) INTEGER
00073 *          The leading dimension of the array X.  LDX >= max(1,N).
00074 *
00075 *  B       (input) REAL array, dimension (LDB,NRHS)
00076 *          The right hand side vectors for the system of linear
00077 *          equations.
00078 *
00079 *  LDB     (input) INTEGER
00080 *          The leading dimension of the array B.  LDB >= max(1,N).
00081 *
00082 *  WORK    (workspace) REAL array, dimension (N)
00083 *
00084 *  RESID   (output) REAL
00085 *          The maximum over the number of right hand sides of
00086 *          norm(op(A)*x - b) / ( norm(op(A)) * norm(x) * EPS ).
00087 *
00088 *  =====================================================================
00089 *
00090 *     .. Parameters ..
00091       REAL               ZERO, ONE
00092       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00093 *     ..
00094 *     .. Local Scalars ..
00095       INTEGER            J
00096       REAL               ANORM, BNORM, EPS, XNORM
00097 *     ..
00098 *     .. External Functions ..
00099       LOGICAL            LSAME
00100       REAL               SASUM, SLAMCH, SLANTR
00101       EXTERNAL           LSAME, SASUM, SLAMCH, SLANTR
00102 *     ..
00103 *     .. External Subroutines ..
00104       EXTERNAL           SAXPY, SCOPY, STRMV
00105 *     ..
00106 *     .. Intrinsic Functions ..
00107       INTRINSIC          MAX
00108 *     ..
00109 *     .. Executable Statements ..
00110 *
00111 *     Quick exit if N = 0 or NRHS = 0
00112 *
00113       IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
00114          RESID = ZERO
00115          RETURN
00116       END IF
00117 *
00118 *     Compute the 1-norm of A or A'.
00119 *
00120       IF( LSAME( TRANS, 'N' ) ) THEN
00121          ANORM = SLANTR( '1', UPLO, DIAG, N, N, A, LDA, WORK )
00122       ELSE
00123          ANORM = SLANTR( 'I', UPLO, DIAG, N, N, A, LDA, WORK )
00124       END IF
00125 *
00126 *     Exit with RESID = 1/EPS if ANORM = 0.
00127 *
00128       EPS = SLAMCH( 'Epsilon' )
00129       IF( ANORM.LE.ZERO ) THEN
00130          RESID = ONE / EPS
00131          RETURN
00132       END IF
00133 *
00134 *     Compute the maximum over the number of right hand sides of
00135 *        norm(op(A)*x - b) / ( norm(op(A)) * norm(x) * EPS )
00136 *
00137       RESID = ZERO
00138       DO 10 J = 1, NRHS
00139          CALL SCOPY( N, X( 1, J ), 1, WORK, 1 )
00140          CALL STRMV( UPLO, TRANS, DIAG, N, A, LDA, WORK, 1 )
00141          CALL SAXPY( N, -ONE, B( 1, J ), 1, WORK, 1 )
00142          BNORM = SASUM( N, WORK, 1 )
00143          XNORM = SASUM( N, X( 1, J ), 1 )
00144          IF( XNORM.LE.ZERO ) THEN
00145             RESID = ONE / EPS
00146          ELSE
00147             RESID = MAX( RESID, ( ( BNORM / ANORM ) / XNORM ) / EPS )
00148          END IF
00149    10 CONTINUE
00150 *
00151       RETURN
00152 *
00153 *     End of STRT02
00154 *
00155       END
```