00001 /* sgtt02.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 real c_b6 = -1.f; 00019 static real c_b7 = 1.f; 00020 static integer c__1 = 1; 00021 00022 /* Subroutine */ int sgtt02_(char *trans, integer *n, integer *nrhs, real *dl, 00023 real *d__, real *du, real *x, integer *ldx, real *b, integer *ldb, 00024 real *rwork, real *resid) 00025 { 00026 /* System generated locals */ 00027 integer b_dim1, b_offset, x_dim1, x_offset, i__1; 00028 real r__1, r__2; 00029 00030 /* Local variables */ 00031 integer j; 00032 real eps; 00033 extern logical lsame_(char *, char *); 00034 real anorm, bnorm; 00035 extern doublereal sasum_(integer *, real *, integer *); 00036 real xnorm; 00037 extern doublereal slamch_(char *); 00038 extern /* Subroutine */ int slagtm_(char *, integer *, integer *, real *, 00039 real *, real *, real *, real *, integer *, real *, real *, 00040 integer *); 00041 extern doublereal slangt_(char *, integer *, real *, real *, real *); 00042 00043 00044 /* -- LAPACK test routine (version 3.1) -- */ 00045 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00046 /* November 2006 */ 00047 00048 /* .. Scalar Arguments .. */ 00049 /* .. */ 00050 /* .. Array Arguments .. */ 00051 /* .. */ 00052 00053 /* Purpose */ 00054 /* ======= */ 00055 00056 /* SGTT02 computes the residual for the solution to a tridiagonal */ 00057 /* system of equations: */ 00058 /* RESID = norm(B - op(A)*X) / (norm(A) * norm(X) * EPS), */ 00059 /* where EPS is the machine epsilon. */ 00060 00061 /* Arguments */ 00062 /* ========= */ 00063 00064 /* TRANS (input) CHARACTER */ 00065 /* Specifies the form of the residual. */ 00066 /* = 'N': B - A * X (No transpose) */ 00067 /* = 'T': B - A'* X (Transpose) */ 00068 /* = 'C': B - A'* X (Conjugate transpose = Transpose) */ 00069 00070 /* N (input) INTEGTER */ 00071 /* The order of the matrix A. N >= 0. */ 00072 00073 /* NRHS (input) INTEGER */ 00074 /* The number of right hand sides, i.e., the number of columns */ 00075 /* of the matrices B and X. NRHS >= 0. */ 00076 00077 /* DL (input) REAL array, dimension (N-1) */ 00078 /* The (n-1) sub-diagonal elements of A. */ 00079 00080 /* D (input) REAL array, dimension (N) */ 00081 /* The diagonal elements of A. */ 00082 00083 /* DU (input) REAL array, dimension (N-1) */ 00084 /* The (n-1) super-diagonal elements of A. */ 00085 00086 /* X (input) REAL array, dimension (LDX,NRHS) */ 00087 /* The computed solution vectors X. */ 00088 00089 /* LDX (input) INTEGER */ 00090 /* The leading dimension of the array X. LDX >= max(1,N). */ 00091 00092 /* B (input/output) REAL array, dimension (LDB,NRHS) */ 00093 /* On entry, the right hand side vectors for the system of */ 00094 /* linear equations. */ 00095 /* On exit, B is overwritten with the difference B - op(A)*X. */ 00096 00097 /* LDB (input) INTEGER */ 00098 /* The leading dimension of the array B. LDB >= max(1,N). */ 00099 00100 /* RWORK (workspace) REAL array, dimension (N) */ 00101 00102 /* RESID (output) REAL */ 00103 /* norm(B - op(A)*X) / (norm(A) * norm(X) * EPS) */ 00104 00105 /* ===================================================================== */ 00106 00107 /* .. Parameters .. */ 00108 /* .. */ 00109 /* .. Local Scalars .. */ 00110 /* .. */ 00111 /* .. External Functions .. */ 00112 /* .. */ 00113 /* .. External Subroutines .. */ 00114 /* .. */ 00115 /* .. Intrinsic Functions .. */ 00116 /* .. */ 00117 /* .. Executable Statements .. */ 00118 00119 /* Quick exit if N = 0 or NRHS = 0 */ 00120 00121 /* Parameter adjustments */ 00122 --dl; 00123 --d__; 00124 --du; 00125 x_dim1 = *ldx; 00126 x_offset = 1 + x_dim1; 00127 x -= x_offset; 00128 b_dim1 = *ldb; 00129 b_offset = 1 + b_dim1; 00130 b -= b_offset; 00131 --rwork; 00132 00133 /* Function Body */ 00134 *resid = 0.f; 00135 if (*n <= 0 || *nrhs == 0) { 00136 return 0; 00137 } 00138 00139 /* Compute the maximum over the number of right hand sides of */ 00140 /* norm(B - op(A)*X) / ( norm(A) * norm(X) * EPS ). */ 00141 00142 if (lsame_(trans, "N")) { 00143 anorm = slangt_("1", n, &dl[1], &d__[1], &du[1]); 00144 } else { 00145 anorm = slangt_("I", n, &dl[1], &d__[1], &du[1]); 00146 } 00147 00148 /* Exit with RESID = 1/EPS if ANORM = 0. */ 00149 00150 eps = slamch_("Epsilon"); 00151 if (anorm <= 0.f) { 00152 *resid = 1.f / eps; 00153 return 0; 00154 } 00155 00156 /* Compute B - op(A)*X. */ 00157 00158 slagtm_(trans, n, nrhs, &c_b6, &dl[1], &d__[1], &du[1], &x[x_offset], ldx, 00159 &c_b7, &b[b_offset], ldb); 00160 00161 i__1 = *nrhs; 00162 for (j = 1; j <= i__1; ++j) { 00163 bnorm = sasum_(n, &b[j * b_dim1 + 1], &c__1); 00164 xnorm = sasum_(n, &x[j * x_dim1 + 1], &c__1); 00165 if (xnorm <= 0.f) { 00166 *resid = 1.f / eps; 00167 } else { 00168 /* Computing MAX */ 00169 r__1 = *resid, r__2 = bnorm / anorm / xnorm / eps; 00170 *resid = dmax(r__1,r__2); 00171 } 00172 /* L10: */ 00173 } 00174 00175 return 0; 00176 00177 /* End of SGTT02 */ 00178 00179 } /* sgtt02_ */