LAPACK 3.3.0

cqrt16.f

Go to the documentation of this file.
00001       SUBROUTINE CQRT16( TRANS, M, N, NRHS, A, LDA, X, LDX, B, LDB,
00002      $                   RWORK, 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          TRANS
00010       INTEGER            LDA, LDB, LDX, M, N, NRHS
00011       REAL               RESID
00012 *     ..
00013 *     .. Array Arguments ..
00014       REAL               RWORK( * )
00015       COMPLEX            A( LDA, * ), B( LDB, * ), X( LDX, * )
00016 *     ..
00017 *
00018 *  Purpose
00019 *  =======
00020 *
00021 *  CQRT16 computes the residual for a solution of a system of linear
00022 *  equations  A*x = b  or  A'*x = b:
00023 *     RESID = norm(B - A*X) / ( max(m,n) * norm(A) * norm(X) * EPS ),
00024 *  where EPS is the machine epsilon.
00025 *
00026 *  Arguments
00027 *  =========
00028 *
00029 *  TRANS   (input) CHARACTER*1
00030 *          Specifies the form of the system of equations:
00031 *          = 'N':  A *x = b
00032 *          = 'T':  A^T*x = b, where A^T is the transpose of A
00033 *          = 'C':  A^H*x = b, where A^H is the conjugate transpose of A
00034 *
00035 *  M       (input) INTEGER
00036 *          The number of rows of the matrix A.  M >= 0.
00037 *
00038 *  N       (input) INTEGER
00039 *          The number of columns of the matrix A.  N >= 0.
00040 *
00041 *  NRHS    (input) INTEGER
00042 *          The number of columns of B, the matrix of right hand sides.
00043 *          NRHS >= 0.
00044 *
00045 *  A       (input) COMPLEX array, dimension (LDA,N)
00046 *          The original M x N matrix A.
00047 *
00048 *  LDA     (input) INTEGER
00049 *          The leading dimension of the array A.  LDA >= max(1,M).
00050 *
00051 *  X       (input) COMPLEX array, dimension (LDX,NRHS)
00052 *          The computed solution vectors for the system of linear
00053 *          equations.
00054 *
00055 *  LDX     (input) INTEGER
00056 *          The leading dimension of the array X.  If TRANS = 'N',
00057 *          LDX >= max(1,N); if TRANS = 'T' or 'C', LDX >= max(1,M).
00058 *
00059 *  B       (input/output) COMPLEX array, dimension (LDB,NRHS)
00060 *          On entry, the right hand side vectors for the system of
00061 *          linear equations.
00062 *          On exit, B is overwritten with the difference B - A*X.
00063 *
00064 *  LDB     (input) INTEGER
00065 *          The leading dimension of the array B.  IF TRANS = 'N',
00066 *          LDB >= max(1,M); if TRANS = 'T' or 'C', LDB >= max(1,N).
00067 *
00068 *  RWORK   (workspace) REAL array, dimension (M)
00069 *
00070 *  RESID   (output) REAL
00071 *          The maximum over the number of right hand sides of
00072 *          norm(B - A*X) / ( max(m,n) * norm(A) * norm(X) * EPS ).
00073 *
00074 *  =====================================================================
00075 *
00076 *     .. Parameters ..
00077       REAL               ZERO, ONE
00078       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00079       COMPLEX            CONE
00080       PARAMETER          ( CONE = ( 1.0E+0, 0.0E+0 ) )
00081 *     ..
00082 *     .. Local Scalars ..
00083       INTEGER            J, N1, N2
00084       REAL               ANORM, BNORM, EPS, XNORM
00085 *     ..
00086 *     .. External Functions ..
00087       LOGICAL            LSAME
00088       REAL               CLANGE, SCASUM, SLAMCH
00089       EXTERNAL           LSAME, CLANGE, SCASUM, SLAMCH
00090 *     ..
00091 *     .. External Subroutines ..
00092       EXTERNAL           CGEMM
00093 *     ..
00094 *     .. Intrinsic Functions ..
00095       INTRINSIC          MAX
00096 *     ..
00097 *     .. Executable Statements ..
00098 *
00099 *     Quick exit if M = 0 or N = 0 or NRHS = 0
00100 *
00101       IF( M.LE.0 .OR. N.LE.0 .OR. NRHS.EQ.0 ) THEN
00102          RESID = ZERO
00103          RETURN
00104       END IF
00105 *
00106       IF( LSAME( TRANS, 'T' ) .OR. LSAME( TRANS, 'C' ) ) THEN
00107          ANORM = CLANGE( 'I', M, N, A, LDA, RWORK )
00108          N1 = N
00109          N2 = M
00110       ELSE
00111          ANORM = CLANGE( '1', M, N, A, LDA, RWORK )
00112          N1 = M
00113          N2 = N
00114       END IF
00115 *
00116       EPS = SLAMCH( 'Epsilon' )
00117 *
00118 *     Compute  B - A*X  (or  B - A'*X ) and store in B.
00119 *
00120       CALL CGEMM( TRANS, 'No transpose', N1, NRHS, N2, -CONE, A, LDA, X,
00121      $            LDX, CONE, B, LDB )
00122 *
00123 *     Compute the maximum over the number of right hand sides of
00124 *        norm(B - A*X) / ( max(m,n) * norm(A) * norm(X) * EPS ) .
00125 *
00126       RESID = ZERO
00127       DO 10 J = 1, NRHS
00128          BNORM = SCASUM( N1, B( 1, J ), 1 )
00129          XNORM = SCASUM( N2, X( 1, J ), 1 )
00130          IF( ANORM.EQ.ZERO .AND. BNORM.EQ.ZERO ) THEN
00131             RESID = ZERO
00132          ELSE IF( ANORM.LE.ZERO .OR. XNORM.LE.ZERO ) THEN
00133             RESID = ONE / EPS
00134          ELSE
00135             RESID = MAX( RESID, ( ( BNORM / ANORM ) / XNORM ) /
00136      $              ( MAX( M, N )*EPS ) )
00137          END IF
00138    10 CONTINUE
00139 *
00140       RETURN
00141 *
00142 *     End of CQRT16
00143 *
00144       END
 All Files Functions