00001 /* sptt02.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_b4 = -1.f; 00019 static real c_b5 = 1.f; 00020 static integer c__1 = 1; 00021 00022 /* Subroutine */ int sptt02_(integer *n, integer *nrhs, real *d__, real *e, 00023 real *x, integer *ldx, real *b, integer *ldb, real *resid) 00024 { 00025 /* System generated locals */ 00026 integer b_dim1, b_offset, x_dim1, x_offset, i__1; 00027 real r__1, r__2; 00028 00029 /* Local variables */ 00030 integer j; 00031 real eps, anorm, bnorm; 00032 extern doublereal sasum_(integer *, real *, integer *); 00033 real xnorm; 00034 extern doublereal slamch_(char *); 00035 extern /* Subroutine */ int slaptm_(integer *, integer *, real *, real *, 00036 real *, real *, integer *, real *, real *, integer *); 00037 extern doublereal slanst_(char *, integer *, real *, 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 /* SPTT02 computes the residual for the solution to a symmetric */ 00053 /* tridiagonal system of equations: */ 00054 /* RESID = norm(B - A*X) / (norm(A) * norm(X) * EPS), */ 00055 /* where EPS is the machine epsilon. */ 00056 00057 /* Arguments */ 00058 /* ========= */ 00059 00060 /* N (input) INTEGTER */ 00061 /* The order of the matrix A. */ 00062 00063 /* NRHS (input) INTEGER */ 00064 /* The number of right hand sides, i.e., the number of columns */ 00065 /* of the matrices B and X. NRHS >= 0. */ 00066 00067 /* D (input) REAL array, dimension (N) */ 00068 /* The n diagonal elements of the tridiagonal matrix A. */ 00069 00070 /* E (input) REAL array, dimension (N-1) */ 00071 /* The (n-1) subdiagonal elements of the tridiagonal matrix A. */ 00072 00073 /* X (input) REAL array, dimension (LDX,NRHS) */ 00074 /* The n by nrhs matrix of solution vectors X. */ 00075 00076 /* LDX (input) INTEGER */ 00077 /* The leading dimension of the array X. LDX >= max(1,N). */ 00078 00079 /* B (input/output) REAL array, dimension (LDB,NRHS) */ 00080 /* On entry, the n by nrhs matrix of right hand side vectors B. */ 00081 /* On exit, B is overwritten with the difference B - A*X. */ 00082 00083 /* LDB (input) INTEGER */ 00084 /* The leading dimension of the array B. LDB >= max(1,N). */ 00085 00086 /* RESID (output) REAL */ 00087 /* norm(B - A*X) / (norm(A) * norm(X) * EPS) */ 00088 00089 /* ===================================================================== */ 00090 00091 /* .. Parameters .. */ 00092 /* .. */ 00093 /* .. Local Scalars .. */ 00094 /* .. */ 00095 /* .. External Functions .. */ 00096 /* .. */ 00097 /* .. Intrinsic Functions .. */ 00098 /* .. */ 00099 /* .. External Subroutines .. */ 00100 /* .. */ 00101 /* .. Executable Statements .. */ 00102 00103 /* Quick return if possible */ 00104 00105 /* Parameter adjustments */ 00106 --d__; 00107 --e; 00108 x_dim1 = *ldx; 00109 x_offset = 1 + x_dim1; 00110 x -= x_offset; 00111 b_dim1 = *ldb; 00112 b_offset = 1 + b_dim1; 00113 b -= b_offset; 00114 00115 /* Function Body */ 00116 if (*n <= 0) { 00117 *resid = 0.f; 00118 return 0; 00119 } 00120 00121 /* Compute the 1-norm of the tridiagonal matrix A. */ 00122 00123 anorm = slanst_("1", n, &d__[1], &e[1]); 00124 00125 /* Exit with RESID = 1/EPS if ANORM = 0. */ 00126 00127 eps = slamch_("Epsilon"); 00128 if (anorm <= 0.f) { 00129 *resid = 1.f / eps; 00130 return 0; 00131 } 00132 00133 /* Compute B - A*X. */ 00134 00135 slaptm_(n, nrhs, &c_b4, &d__[1], &e[1], &x[x_offset], ldx, &c_b5, &b[ 00136 b_offset], ldb); 00137 00138 /* Compute the maximum over the number of right hand sides of */ 00139 /* norm(B - A*X) / ( norm(A) * norm(X) * EPS ). */ 00140 00141 *resid = 0.f; 00142 i__1 = *nrhs; 00143 for (j = 1; j <= i__1; ++j) { 00144 bnorm = sasum_(n, &b[j * b_dim1 + 1], &c__1); 00145 xnorm = sasum_(n, &x[j * x_dim1 + 1], &c__1); 00146 if (xnorm <= 0.f) { 00147 *resid = 1.f / eps; 00148 } else { 00149 /* Computing MAX */ 00150 r__1 = *resid, r__2 = bnorm / anorm / xnorm / eps; 00151 *resid = dmax(r__1,r__2); 00152 } 00153 /* L10: */ 00154 } 00155 00156 return 0; 00157 00158 /* End of SPTT02 */ 00159 00160 } /* sptt02_ */