00001 /* cgbt02.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 complex c_b1 = {1.f,0.f}; 00019 static integer c__1 = 1; 00020 00021 /* Subroutine */ int cgbt02_(char *trans, integer *m, integer *n, integer *kl, 00022 integer *ku, integer *nrhs, complex *a, integer *lda, complex *x, 00023 integer *ldx, complex *b, integer *ldb, real *resid) 00024 { 00025 /* System generated locals */ 00026 integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, 00027 i__3; 00028 real r__1, r__2; 00029 complex q__1; 00030 00031 /* Local variables */ 00032 integer j, i1, i2, n1, kd; 00033 real eps; 00034 extern /* Subroutine */ int cgbmv_(char *, integer *, integer *, integer * 00035 , integer *, complex *, complex *, integer *, complex *, integer * 00036 , complex *, complex *, integer *); 00037 extern logical lsame_(char *, char *); 00038 real anorm, bnorm, xnorm; 00039 extern doublereal slamch_(char *), scasum_(integer *, complex *, 00040 integer *); 00041 00042 00043 /* -- LAPACK test routine (version 3.1) -- */ 00044 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00045 /* November 2006 */ 00046 00047 /* .. Scalar Arguments .. */ 00048 /* .. */ 00049 /* .. Array Arguments .. */ 00050 /* .. */ 00051 00052 /* Purpose */ 00053 /* ======= */ 00054 00055 /* CGBT02 computes the residual for a solution of a banded system of */ 00056 /* equations A*x = b or A'*x = b: */ 00057 /* RESID = norm( B - A*X ) / ( norm(A) * norm(X) * EPS). */ 00058 /* where EPS is the machine precision. */ 00059 00060 /* Arguments */ 00061 /* ========= */ 00062 00063 /* TRANS (input) CHARACTER*1 */ 00064 /* Specifies the form of the system of equations: */ 00065 /* = 'N': A *x = b */ 00066 /* = 'T': A'*x = b, where A' is the transpose of A */ 00067 /* = 'C': A'*x = b, where A' is the transpose of A */ 00068 00069 /* M (input) INTEGER */ 00070 /* The number of rows of the matrix A. M >= 0. */ 00071 00072 /* N (input) INTEGER */ 00073 /* The number of columns of the matrix A. N >= 0. */ 00074 00075 /* KL (input) INTEGER */ 00076 /* The number of subdiagonals within the band of A. KL >= 0. */ 00077 00078 /* KU (input) INTEGER */ 00079 /* The number of superdiagonals within the band of A. KU >= 0. */ 00080 00081 /* NRHS (input) INTEGER */ 00082 /* The number of columns of B. NRHS >= 0. */ 00083 00084 /* A (input) COMPLEX array, dimension (LDA,N) */ 00085 /* The original matrix A in band storage, stored in rows 1 to */ 00086 /* KL+KU+1. */ 00087 00088 /* LDA (input) INTEGER */ 00089 /* The leading dimension of the array A. LDA >= max(1,KL+KU+1). */ 00090 00091 /* X (input) COMPLEX array, dimension (LDX,NRHS) */ 00092 /* The computed solution vectors for the system of linear */ 00093 /* equations. */ 00094 00095 /* LDX (input) INTEGER */ 00096 /* The leading dimension of the array X. If TRANS = 'N', */ 00097 /* LDX >= max(1,N); if TRANS = 'T' or 'C', LDX >= max(1,M). */ 00098 00099 /* B (input/output) COMPLEX array, dimension (LDB,NRHS) */ 00100 /* On entry, the right hand side vectors for the system of */ 00101 /* linear equations. */ 00102 /* On exit, B is overwritten with the difference B - A*X. */ 00103 00104 /* LDB (input) INTEGER */ 00105 /* The leading dimension of the array B. IF TRANS = 'N', */ 00106 /* LDB >= max(1,M); if TRANS = 'T' or 'C', LDB >= max(1,N). */ 00107 00108 /* RESID (output) REAL */ 00109 /* The maximum over the number of right hand sides of */ 00110 /* norm(B - A*X) / ( norm(A) * norm(X) * EPS ). */ 00111 00112 /* ===================================================================== */ 00113 00114 /* .. Parameters .. */ 00115 /* .. */ 00116 /* .. Local Scalars .. */ 00117 /* .. */ 00118 /* .. External Functions .. */ 00119 /* .. */ 00120 /* .. External Subroutines .. */ 00121 /* .. */ 00122 /* .. Intrinsic Functions .. */ 00123 /* .. */ 00124 /* .. Executable Statements .. */ 00125 00126 /* Quick return if N = 0 pr NRHS = 0 */ 00127 00128 /* Parameter adjustments */ 00129 a_dim1 = *lda; 00130 a_offset = 1 + a_dim1; 00131 a -= a_offset; 00132 x_dim1 = *ldx; 00133 x_offset = 1 + x_dim1; 00134 x -= x_offset; 00135 b_dim1 = *ldb; 00136 b_offset = 1 + b_dim1; 00137 b -= b_offset; 00138 00139 /* Function Body */ 00140 if (*m <= 0 || *n <= 0 || *nrhs <= 0) { 00141 *resid = 0.f; 00142 return 0; 00143 } 00144 00145 /* Exit with RESID = 1/EPS if ANORM = 0. */ 00146 00147 eps = slamch_("Epsilon"); 00148 kd = *ku + 1; 00149 anorm = 0.f; 00150 i__1 = *n; 00151 for (j = 1; j <= i__1; ++j) { 00152 /* Computing MAX */ 00153 i__2 = kd + 1 - j; 00154 i1 = max(i__2,1); 00155 /* Computing MIN */ 00156 i__2 = kd + *m - j, i__3 = *kl + kd; 00157 i2 = min(i__2,i__3); 00158 /* Computing MAX */ 00159 i__2 = i2 - i1 + 1; 00160 r__1 = anorm, r__2 = scasum_(&i__2, &a[i1 + j * a_dim1], &c__1); 00161 anorm = dmax(r__1,r__2); 00162 /* L10: */ 00163 } 00164 if (anorm <= 0.f) { 00165 *resid = 1.f / eps; 00166 return 0; 00167 } 00168 00169 if (lsame_(trans, "T") || lsame_(trans, "C")) { 00170 n1 = *n; 00171 } else { 00172 n1 = *m; 00173 } 00174 00175 /* Compute B - A*X (or B - A'*X ) */ 00176 00177 i__1 = *nrhs; 00178 for (j = 1; j <= i__1; ++j) { 00179 q__1.r = -1.f, q__1.i = -0.f; 00180 cgbmv_(trans, m, n, kl, ku, &q__1, &a[a_offset], lda, &x[j * x_dim1 + 00181 1], &c__1, &c_b1, &b[j * b_dim1 + 1], &c__1); 00182 /* L20: */ 00183 } 00184 00185 /* Compute the maximum over the number of right hand sides of */ 00186 /* norm(B - A*X) / ( norm(A) * norm(X) * EPS ). */ 00187 00188 *resid = 0.f; 00189 i__1 = *nrhs; 00190 for (j = 1; j <= i__1; ++j) { 00191 bnorm = scasum_(&n1, &b[j * b_dim1 + 1], &c__1); 00192 xnorm = scasum_(&n1, &x[j * x_dim1 + 1], &c__1); 00193 if (xnorm <= 0.f) { 00194 *resid = 1.f / eps; 00195 } else { 00196 /* Computing MAX */ 00197 r__1 = *resid, r__2 = bnorm / anorm / xnorm / eps; 00198 *resid = dmax(r__1,r__2); 00199 } 00200 /* L30: */ 00201 } 00202 00203 return 0; 00204 00205 /* End of CGBT02 */ 00206 00207 } /* cgbt02_ */