LAPACK 3.3.1 Linear Algebra PACKage

# ctpt01.f

Go to the documentation of this file.
```00001       SUBROUTINE CTPT01( UPLO, DIAG, N, AP, AINVP, RCOND, RWORK, RESID )
00002 *
00003 *  -- LAPACK test routine (version 3.1) --
00004 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
00005 *     November 2006
00006 *
00007 *     .. Scalar Arguments ..
00008       CHARACTER          DIAG, UPLO
00009       INTEGER            N
00010       REAL               RCOND, RESID
00011 *     ..
00012 *     .. Array Arguments ..
00013       REAL               RWORK( * )
00014       COMPLEX            AINVP( * ), AP( * )
00015 *     ..
00016 *
00017 *  Purpose
00018 *  =======
00019 *
00020 *  CTPT01 computes the residual for a triangular matrix A times its
00021 *  inverse when A is stored in packed format:
00022 *     RESID = norm(A*AINV - I) / ( N * norm(A) * norm(AINV) * EPS ),
00023 *  where EPS is the machine epsilon.
00024 *
00025 *  Arguments
00026 *  ==========
00027 *
00028 *  UPLO    (input) CHARACTER*1
00029 *          Specifies whether the matrix A is upper or lower triangular.
00030 *          = 'U':  Upper triangular
00031 *          = 'L':  Lower triangular
00032 *
00033 *  DIAG    (input) CHARACTER*1
00034 *          Specifies whether or not the matrix A is unit triangular.
00035 *          = 'N':  Non-unit triangular
00036 *          = 'U':  Unit triangular
00037 *
00038 *  N       (input) INTEGER
00039 *          The order of the matrix A.  N >= 0.
00040 *
00041 *  AP      (input) COMPLEX array, dimension (N*(N+1)/2)
00042 *          The original upper or lower triangular matrix A, packed
00043 *          columnwise in a linear array.  The j-th column of A is stored
00044 *          in the array AP as follows:
00045 *          if UPLO = 'U', AP((j-1)*j/2 + i) = A(i,j) for 1<=i<=j;
00046 *          if UPLO = 'L',
00047 *             AP((j-1)*(n-j) + j*(j+1)/2 + i-j) = A(i,j) for j<=i<=n.
00048 *
00049 *  AINVP   (input) COMPLEX array, dimension (N*(N+1)/2)
00050 *          On entry, the (triangular) inverse of the matrix A, packed
00051 *          columnwise in a linear array as in AP.
00052 *          On exit, the contents of AINVP are destroyed.
00053 *
00054 *  RCOND   (output) REAL
00055 *          The reciprocal condition number of A, computed as
00056 *          1/(norm(A) * norm(AINV)).
00057 *
00058 *  RWORK   (workspace) REAL array, dimension (N)
00059 *
00060 *  RESID   (output) REAL
00061 *          norm(A*AINV - I) / ( N * norm(A) * norm(AINV) * EPS )
00062 *
00063 *  =====================================================================
00064 *
00065 *     .. Parameters ..
00066       REAL               ZERO, ONE
00067       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00068 *     ..
00069 *     .. Local Scalars ..
00070       LOGICAL            UNITD
00071       INTEGER            J, JC
00072       REAL               AINVNM, ANORM, EPS
00073 *     ..
00074 *     .. External Functions ..
00075       LOGICAL            LSAME
00076       REAL               CLANTP, SLAMCH
00077       EXTERNAL           LSAME, CLANTP, SLAMCH
00078 *     ..
00079 *     .. External Subroutines ..
00080       EXTERNAL           CTPMV
00081 *     ..
00082 *     .. Intrinsic Functions ..
00083       INTRINSIC          REAL
00084 *     ..
00085 *     .. Executable Statements ..
00086 *
00087 *     Quick exit if N = 0.
00088 *
00089       IF( N.LE.0 ) THEN
00090          RCOND = ONE
00091          RESID = ZERO
00092          RETURN
00093       END IF
00094 *
00095 *     Exit with RESID = 1/EPS if ANORM = 0 or AINVNM = 0.
00096 *
00097       EPS = SLAMCH( 'Epsilon' )
00098       ANORM = CLANTP( '1', UPLO, DIAG, N, AP, RWORK )
00099       AINVNM = CLANTP( '1', UPLO, DIAG, N, AINVP, RWORK )
00100       IF( ANORM.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN
00101          RCOND = ZERO
00102          RESID = ONE / EPS
00103          RETURN
00104       END IF
00105       RCOND = ( ONE / ANORM ) / AINVNM
00106 *
00107 *     Compute A * AINV, overwriting AINV.
00108 *
00109       UNITD = LSAME( DIAG, 'U' )
00110       IF( LSAME( UPLO, 'U' ) ) THEN
00111          JC = 1
00112          DO 10 J = 1, N
00113             IF( UNITD )
00114      \$         AINVP( JC+J-1 ) = ONE
00115 *
00116 *           Form the j-th column of A*AINV.
00117 *
00118             CALL CTPMV( 'Upper', 'No transpose', DIAG, J, AP,
00119      \$                  AINVP( JC ), 1 )
00120 *
00121 *           Subtract 1 from the diagonal to form A*AINV - I.
00122 *
00123             AINVP( JC+J-1 ) = AINVP( JC+J-1 ) - ONE
00124             JC = JC + J
00125    10    CONTINUE
00126       ELSE
00127          JC = 1
00128          DO 20 J = 1, N
00129             IF( UNITD )
00130      \$         AINVP( JC ) = ONE
00131 *
00132 *           Form the j-th column of A*AINV.
00133 *
00134             CALL CTPMV( 'Lower', 'No transpose', DIAG, N-J+1, AP( JC ),
00135      \$                  AINVP( JC ), 1 )
00136 *
00137 *           Subtract 1 from the diagonal to form A*AINV - I.
00138 *
00139             AINVP( JC ) = AINVP( JC ) - ONE
00140             JC = JC + N - J + 1
00141    20    CONTINUE
00142       END IF
00143 *
00144 *     Compute norm(A*AINV - I) / (N * norm(A) * norm(AINV) * EPS)
00145 *
00146       RESID = CLANTP( '1', UPLO, 'Non-unit', N, AINVP, RWORK )
00147 *
00148       RESID = ( ( RESID*RCOND ) / REAL( N ) ) / EPS
00149 *
00150       RETURN
00151 *
00152 *     End of CTPT01
00153 *
00154       END
```