00001 /* dtrt02.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 static doublereal c_b10 = -1.; 00020 00021 /* Subroutine */ int dtrt02_(char *uplo, char *trans, char *diag, integer *n, 00022 integer *nrhs, doublereal *a, integer *lda, doublereal *x, integer * 00023 ldx, doublereal *b, integer *ldb, doublereal *work, doublereal *resid) 00024 { 00025 /* System generated locals */ 00026 integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset, i__1; 00027 doublereal d__1, d__2; 00028 00029 /* Local variables */ 00030 integer j; 00031 doublereal eps; 00032 extern logical lsame_(char *, char *); 00033 extern doublereal dasum_(integer *, doublereal *, integer *); 00034 doublereal anorm, bnorm; 00035 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 00036 doublereal *, integer *), daxpy_(integer *, doublereal *, 00037 doublereal *, integer *, doublereal *, integer *), dtrmv_(char *, 00038 char *, char *, integer *, doublereal *, integer *, doublereal *, 00039 integer *); 00040 doublereal xnorm; 00041 extern doublereal dlamch_(char *), dlantr_(char *, char *, char *, 00042 integer *, integer *, doublereal *, integer *, doublereal *); 00043 00044 00045 /* -- LAPACK test routine (version 3.1) -- */ 00046 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00047 /* November 2006 */ 00048 00049 /* .. Scalar Arguments .. */ 00050 /* .. */ 00051 /* .. Array Arguments .. */ 00052 /* .. */ 00053 00054 /* Purpose */ 00055 /* ======= */ 00056 00057 /* DTRT02 computes the residual for the computed solution to a */ 00058 /* triangular system of linear equations A*x = b or A'*x = b. */ 00059 /* Here A is a triangular matrix, A' is the transpose of A, and x and b */ 00060 /* are N by NRHS matrices. The test ratio is the maximum over the */ 00061 /* number of right hand sides of */ 00062 /* norm(b - op(A)*x) / ( norm(op(A)) * norm(x) * EPS ), */ 00063 /* where op(A) denotes A or A' and EPS is the machine epsilon. */ 00064 00065 /* Arguments */ 00066 /* ========= */ 00067 00068 /* UPLO (input) CHARACTER*1 */ 00069 /* Specifies whether the matrix A is upper or lower triangular. */ 00070 /* = 'U': Upper triangular */ 00071 /* = 'L': Lower triangular */ 00072 00073 /* TRANS (input) CHARACTER*1 */ 00074 /* Specifies the operation applied to A. */ 00075 /* = 'N': A *x = b (No transpose) */ 00076 /* = 'T': A'*x = b (Transpose) */ 00077 /* = 'C': A'*x = b (Conjugate transpose = Transpose) */ 00078 00079 /* DIAG (input) CHARACTER*1 */ 00080 /* Specifies whether or not the matrix A is unit triangular. */ 00081 /* = 'N': Non-unit triangular */ 00082 /* = 'U': Unit triangular */ 00083 00084 /* N (input) INTEGER */ 00085 /* The order of the matrix A. N >= 0. */ 00086 00087 /* NRHS (input) INTEGER */ 00088 /* The number of right hand sides, i.e., the number of columns */ 00089 /* of the matrices X and B. NRHS >= 0. */ 00090 00091 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */ 00092 /* The triangular matrix A. If UPLO = 'U', the leading n by n */ 00093 /* upper triangular part of the array A contains the upper */ 00094 /* triangular matrix, and the strictly lower triangular part of */ 00095 /* A is not referenced. If UPLO = 'L', the leading n by n lower */ 00096 /* triangular part of the array A contains the lower triangular */ 00097 /* matrix, and the strictly upper triangular part of A is not */ 00098 /* referenced. If DIAG = 'U', the diagonal elements of A are */ 00099 /* also not referenced and are assumed to be 1. */ 00100 00101 /* LDA (input) INTEGER */ 00102 /* The leading dimension of the array A. LDA >= max(1,N). */ 00103 00104 /* X (input) DOUBLE PRECISION array, dimension (LDX,NRHS) */ 00105 /* The computed solution vectors for the system of linear */ 00106 /* equations. */ 00107 00108 /* LDX (input) INTEGER */ 00109 /* The leading dimension of the array X. LDX >= max(1,N). */ 00110 00111 /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */ 00112 /* The right hand side vectors for the system of linear */ 00113 /* equations. */ 00114 00115 /* LDB (input) INTEGER */ 00116 /* The leading dimension of the array B. LDB >= max(1,N). */ 00117 00118 /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */ 00119 00120 /* RESID (output) DOUBLE PRECISION */ 00121 /* The maximum over the number of right hand sides of */ 00122 /* norm(op(A)*x - b) / ( norm(op(A)) * norm(x) * EPS ). */ 00123 00124 /* ===================================================================== */ 00125 00126 /* .. Parameters .. */ 00127 /* .. */ 00128 /* .. Local Scalars .. */ 00129 /* .. */ 00130 /* .. External Functions .. */ 00131 /* .. */ 00132 /* .. External Subroutines .. */ 00133 /* .. */ 00134 /* .. Intrinsic Functions .. */ 00135 /* .. */ 00136 /* .. Executable Statements .. */ 00137 00138 /* Quick exit if N = 0 or NRHS = 0 */ 00139 00140 /* Parameter adjustments */ 00141 a_dim1 = *lda; 00142 a_offset = 1 + a_dim1; 00143 a -= a_offset; 00144 x_dim1 = *ldx; 00145 x_offset = 1 + x_dim1; 00146 x -= x_offset; 00147 b_dim1 = *ldb; 00148 b_offset = 1 + b_dim1; 00149 b -= b_offset; 00150 --work; 00151 00152 /* Function Body */ 00153 if (*n <= 0 || *nrhs <= 0) { 00154 *resid = 0.; 00155 return 0; 00156 } 00157 00158 /* Compute the 1-norm of A or A'. */ 00159 00160 if (lsame_(trans, "N")) { 00161 anorm = dlantr_("1", uplo, diag, n, n, &a[a_offset], lda, &work[1]); 00162 } else { 00163 anorm = dlantr_("I", uplo, diag, n, n, &a[a_offset], lda, &work[1]); 00164 } 00165 00166 /* Exit with RESID = 1/EPS if ANORM = 0. */ 00167 00168 eps = dlamch_("Epsilon"); 00169 if (anorm <= 0.) { 00170 *resid = 1. / eps; 00171 return 0; 00172 } 00173 00174 /* Compute the maximum over the number of right hand sides of */ 00175 /* norm(op(A)*x - b) / ( norm(op(A)) * norm(x) * EPS ) */ 00176 00177 *resid = 0.; 00178 i__1 = *nrhs; 00179 for (j = 1; j <= i__1; ++j) { 00180 dcopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1); 00181 dtrmv_(uplo, trans, diag, n, &a[a_offset], lda, &work[1], &c__1); 00182 daxpy_(n, &c_b10, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1); 00183 bnorm = dasum_(n, &work[1], &c__1); 00184 xnorm = dasum_(n, &x[j * x_dim1 + 1], &c__1); 00185 if (xnorm <= 0.) { 00186 *resid = 1. / eps; 00187 } else { 00188 /* Computing MAX */ 00189 d__1 = *resid, d__2 = bnorm / anorm / xnorm / eps; 00190 *resid = max(d__1,d__2); 00191 } 00192 /* L10: */ 00193 } 00194 00195 return 0; 00196 00197 /* End of DTRT02 */ 00198 00199 } /* dtrt02_ */