00001 /* strt01.f -- translated by f2c (version 20061008). 00002 You must link the resulting object file with libf2c: 00003 on Microsoft Windows system, link with libf2c.lib; 00004 on Linux or Unix systems, link with .../path/to/libf2c.a -lm 00005 or, if you install libf2c.a in a standard place, with -lf2c -lm 00006 -- in that order, at the end of the command line, as in 00007 cc *.o -lf2c -lm 00008 Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., 00009 00010 http://www.netlib.org/f2c/libf2c.zip 00011 */ 00012 00013 #include "f2c.h" 00014 #include "blaswrap.h" 00015 00016 /* Table of constant values */ 00017 00018 static integer c__1 = 1; 00019 00020 /* Subroutine */ int strt01_(char *uplo, char *diag, integer *n, real *a, 00021 integer *lda, real *ainv, integer *ldainv, real *rcond, real *work, 00022 real *resid) 00023 { 00024 /* System generated locals */ 00025 integer a_dim1, a_offset, ainv_dim1, ainv_offset, i__1, i__2; 00026 00027 /* Local variables */ 00028 integer j; 00029 real eps; 00030 extern logical lsame_(char *, char *); 00031 real anorm; 00032 extern /* Subroutine */ int strmv_(char *, char *, char *, integer *, 00033 real *, integer *, real *, integer *); 00034 extern doublereal slamch_(char *); 00035 real ainvnm; 00036 extern doublereal slantr_(char *, char *, char *, integer *, integer *, 00037 real *, integer *, real *); 00038 00039 00040 /* -- LAPACK test routine (version 3.1) -- */ 00041 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00042 /* November 2006 */ 00043 00044 /* .. Scalar Arguments .. */ 00045 /* .. */ 00046 /* .. Array Arguments .. */ 00047 /* .. */ 00048 00049 /* Purpose */ 00050 /* ======= */ 00051 00052 /* STRT01 computes the residual for a triangular matrix A times its */ 00053 /* inverse: */ 00054 /* RESID = norm( A*AINV - I ) / ( N * norm(A) * norm(AINV) * EPS ), */ 00055 /* where EPS is the machine epsilon. */ 00056 00057 /* Arguments */ 00058 /* ========== */ 00059 00060 /* UPLO (input) CHARACTER*1 */ 00061 /* Specifies whether the matrix A is upper or lower triangular. */ 00062 /* = 'U': Upper triangular */ 00063 /* = 'L': Lower triangular */ 00064 00065 /* DIAG (input) CHARACTER*1 */ 00066 /* Specifies whether or not the matrix A is unit triangular. */ 00067 /* = 'N': Non-unit triangular */ 00068 /* = 'U': Unit triangular */ 00069 00070 /* N (input) INTEGER */ 00071 /* The order of the matrix A. N >= 0. */ 00072 00073 /* A (input) REAL array, dimension (LDA,N) */ 00074 /* The triangular matrix A. If UPLO = 'U', the leading n by n */ 00075 /* upper triangular part of the array A contains the upper */ 00076 /* triangular matrix, and the strictly lower triangular part of */ 00077 /* A is not referenced. If UPLO = 'L', the leading n by n lower */ 00078 /* triangular part of the array A contains the lower triangular */ 00079 /* matrix, and the strictly upper triangular part of A is not */ 00080 /* referenced. If DIAG = 'U', the diagonal elements of A are */ 00081 /* also not referenced and are assumed to be 1. */ 00082 00083 /* LDA (input) INTEGER */ 00084 /* The leading dimension of the array A. LDA >= max(1,N). */ 00085 00086 /* AINV (input/output) REAL array, dimension (LDAINV,N) */ 00087 /* On entry, the (triangular) inverse of the matrix A, in the */ 00088 /* same storage format as A. */ 00089 /* On exit, the contents of AINV are destroyed. */ 00090 00091 /* LDAINV (input) INTEGER */ 00092 /* The leading dimension of the array AINV. LDAINV >= max(1,N). */ 00093 00094 /* RCOND (output) REAL */ 00095 /* The reciprocal condition number of A, computed as */ 00096 /* 1/(norm(A) * norm(AINV)). */ 00097 00098 /* WORK (workspace) REAL array, dimension (N) */ 00099 00100 /* RESID (output) REAL */ 00101 /* norm(A*AINV - I) / ( N * norm(A) * norm(AINV) * EPS ) */ 00102 00103 /* ===================================================================== */ 00104 00105 /* .. Parameters .. */ 00106 /* .. */ 00107 /* .. Local Scalars .. */ 00108 /* .. */ 00109 /* .. External Functions .. */ 00110 /* .. */ 00111 /* .. External Subroutines .. */ 00112 /* .. */ 00113 /* .. Intrinsic Functions .. */ 00114 /* .. */ 00115 /* .. Executable Statements .. */ 00116 00117 /* Quick exit if N = 0 */ 00118 00119 /* Parameter adjustments */ 00120 a_dim1 = *lda; 00121 a_offset = 1 + a_dim1; 00122 a -= a_offset; 00123 ainv_dim1 = *ldainv; 00124 ainv_offset = 1 + ainv_dim1; 00125 ainv -= ainv_offset; 00126 --work; 00127 00128 /* Function Body */ 00129 if (*n <= 0) { 00130 *rcond = 1.f; 00131 *resid = 0.f; 00132 return 0; 00133 } 00134 00135 /* Exit with RESID = 1/EPS if ANORM = 0 or AINVNM = 0. */ 00136 00137 eps = slamch_("Epsilon"); 00138 anorm = slantr_("1", uplo, diag, n, n, &a[a_offset], lda, &work[1]); 00139 ainvnm = slantr_("1", uplo, diag, n, n, &ainv[ainv_offset], ldainv, &work[ 00140 1]); 00141 if (anorm <= 0.f || ainvnm <= 0.f) { 00142 *rcond = 0.f; 00143 *resid = 1.f / eps; 00144 return 0; 00145 } 00146 *rcond = 1.f / anorm / ainvnm; 00147 00148 /* Set the diagonal of AINV to 1 if AINV has unit diagonal. */ 00149 00150 if (lsame_(diag, "U")) { 00151 i__1 = *n; 00152 for (j = 1; j <= i__1; ++j) { 00153 ainv[j + j * ainv_dim1] = 1.f; 00154 /* L10: */ 00155 } 00156 } 00157 00158 /* Compute A * AINV, overwriting AINV. */ 00159 00160 if (lsame_(uplo, "U")) { 00161 i__1 = *n; 00162 for (j = 1; j <= i__1; ++j) { 00163 strmv_("Upper", "No transpose", diag, &j, &a[a_offset], lda, & 00164 ainv[j * ainv_dim1 + 1], &c__1); 00165 /* L20: */ 00166 } 00167 } else { 00168 i__1 = *n; 00169 for (j = 1; j <= i__1; ++j) { 00170 i__2 = *n - j + 1; 00171 strmv_("Lower", "No transpose", diag, &i__2, &a[j + j * a_dim1], 00172 lda, &ainv[j + j * ainv_dim1], &c__1); 00173 /* L30: */ 00174 } 00175 } 00176 00177 /* Subtract 1 from each diagonal element to form A*AINV - I. */ 00178 00179 i__1 = *n; 00180 for (j = 1; j <= i__1; ++j) { 00181 ainv[j + j * ainv_dim1] += -1.f; 00182 /* L40: */ 00183 } 00184 00185 /* Compute norm(A*AINV - I) / (N * norm(A) * norm(AINV) * EPS) */ 00186 00187 *resid = slantr_("1", uplo, "Non-unit", n, n, &ainv[ainv_offset], ldainv, 00188 &work[1]); 00189 00190 *resid = *resid * *rcond / (real) (*n) / eps; 00191 00192 return 0; 00193 00194 /* End of STRT01 */ 00195 00196 } /* strt01_ */