00001 /* slahilb.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 = 0.f; 00019 00020 /* Subroutine */ int slahilb_(integer *n, integer *nrhs, real *a, integer * 00021 lda, real *x, integer *ldx, real *b, integer *ldb, real *work, 00022 integer *info) 00023 { 00024 /* System generated locals */ 00025 integer a_dim1, a_offset, x_dim1, x_offset, b_dim1, b_offset, i__1, i__2; 00026 real r__1; 00027 00028 /* Local variables */ 00029 integer i__, j, m, r__, ti, tm; 00030 extern /* Subroutine */ int xerbla_(char *, integer *), slaset_( 00031 char *, integer *, integer *, real *, real *, real *, integer *); 00032 00033 00034 /* -- LAPACK auxiliary test routine (version 3.0) -- */ 00035 /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */ 00036 /* Courant Institute, Argonne National Lab, and Rice University */ 00037 /* 28 August, 2006 */ 00038 00039 /* David Vu <dtv@cs.berkeley.edu> */ 00040 /* Yozo Hida <yozo@cs.berkeley.edu> */ 00041 /* Jason Riedy <ejr@cs.berkeley.edu> */ 00042 /* D. Halligan <dhalligan@berkeley.edu> */ 00043 00044 /* .. Scalar Arguments .. */ 00045 /* .. Array Arguments .. */ 00046 /* .. */ 00047 00048 /* Purpose */ 00049 /* ======= */ 00050 00051 /* SLAHILB generates an N by N scaled Hilbert matrix in A along with */ 00052 /* NRHS right-hand sides in B and solutions in X such that A*X=B. */ 00053 00054 /* The Hilbert matrix is scaled by M = LCM(1, 2, ..., 2*N-1) so that all */ 00055 /* entries are integers. The right-hand sides are the first NRHS */ 00056 /* columns of M * the identity matrix, and the solutions are the */ 00057 /* first NRHS columns of the inverse Hilbert matrix. */ 00058 00059 /* The condition number of the Hilbert matrix grows exponentially with */ 00060 /* its size, roughly as O(e ** (3.5*N)). Additionally, the inverse */ 00061 /* Hilbert matrices beyond a relatively small dimension cannot be */ 00062 /* generated exactly without extra precision. Precision is exhausted */ 00063 /* when the largest entry in the inverse Hilbert matrix is greater than */ 00064 /* 2 to the power of the number of bits in the fraction of the data type */ 00065 /* used plus one, which is 24 for single precision. */ 00066 00067 /* In single, the generated solution is exact for N <= 6 and has */ 00068 /* small componentwise error for 7 <= N <= 11. */ 00069 00070 /* Arguments */ 00071 /* ========= */ 00072 00073 /* N (input) INTEGER */ 00074 /* The dimension of the matrix A. */ 00075 00076 /* NRHS (input) NRHS */ 00077 /* The requested number of right-hand sides. */ 00078 00079 /* A (output) REAL array, dimension (LDA, N) */ 00080 /* The generated scaled Hilbert matrix. */ 00081 00082 /* LDA (input) INTEGER */ 00083 /* The leading dimension of the array A. LDA >= N. */ 00084 00085 /* X (output) REAL array, dimension (LDX, NRHS) */ 00086 /* The generated exact solutions. Currently, the first NRHS */ 00087 /* columns of the inverse Hilbert matrix. */ 00088 00089 /* LDX (input) INTEGER */ 00090 /* The leading dimension of the array X. LDX >= N. */ 00091 00092 /* B (output) REAL array, dimension (LDB, NRHS) */ 00093 /* The generated right-hand sides. Currently, the first NRHS */ 00094 /* columns of LCM(1, 2, ..., 2*N-1) * the identity matrix. */ 00095 00096 /* LDB (input) INTEGER */ 00097 /* The leading dimension of the array B. LDB >= N. */ 00098 00099 /* WORK (workspace) REAL array, dimension (N) */ 00100 00101 00102 /* INFO (output) INTEGER */ 00103 /* = 0: successful exit */ 00104 /* = 1: N is too large; the data is still generated but may not */ 00105 /* be not exact. */ 00106 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00107 00108 /* ===================================================================== */ 00109 /* .. Local Scalars .. */ 00110 /* .. Parameters .. */ 00111 /* NMAX_EXACT the largest dimension where the generated data is */ 00112 /* exact. */ 00113 /* NMAX_APPROX the largest dimension where the generated data has */ 00114 /* a small componentwise relative error. */ 00115 /* .. */ 00116 /* .. External Functions */ 00117 /* .. */ 00118 /* .. Executable Statements .. */ 00119 00120 /* Test the input arguments */ 00121 00122 /* Parameter adjustments */ 00123 --work; 00124 a_dim1 = *lda; 00125 a_offset = 1 + a_dim1; 00126 a -= a_offset; 00127 x_dim1 = *ldx; 00128 x_offset = 1 + x_dim1; 00129 x -= x_offset; 00130 b_dim1 = *ldb; 00131 b_offset = 1 + b_dim1; 00132 b -= b_offset; 00133 00134 /* Function Body */ 00135 *info = 0; 00136 if (*n < 0 || *n > 11) { 00137 *info = -1; 00138 } else if (*nrhs < 0) { 00139 *info = -2; 00140 } else if (*lda < *n) { 00141 *info = -4; 00142 } else if (*ldx < *n) { 00143 *info = -6; 00144 } else if (*ldb < *n) { 00145 *info = -8; 00146 } 00147 if (*info < 0) { 00148 i__1 = -(*info); 00149 xerbla_("SLAHILB", &i__1); 00150 return 0; 00151 } 00152 if (*n > 6) { 00153 *info = 1; 00154 } 00155 /* Compute M = the LCM of the integers [1, 2*N-1]. The largest */ 00156 /* reasonable N is small enough that integers suffice (up to N = 11). */ 00157 m = 1; 00158 i__1 = (*n << 1) - 1; 00159 for (i__ = 2; i__ <= i__1; ++i__) { 00160 tm = m; 00161 ti = i__; 00162 r__ = tm % ti; 00163 while(r__ != 0) { 00164 tm = ti; 00165 ti = r__; 00166 r__ = tm % ti; 00167 } 00168 m = m / ti * i__; 00169 } 00170 /* Generate the scaled Hilbert matrix in A */ 00171 i__1 = *n; 00172 for (j = 1; j <= i__1; ++j) { 00173 i__2 = *n; 00174 for (i__ = 1; i__ <= i__2; ++i__) { 00175 a[i__ + j * a_dim1] = (real) m / (i__ + j - 1); 00176 } 00177 } 00178 /* Generate matrix B as simply the first NRHS columns of M * the */ 00179 /* identity. */ 00180 r__1 = (real) m; 00181 slaset_("Full", n, nrhs, &c_b4, &r__1, &b[b_offset], ldb); 00182 /* Generate the true solutions in X. Because B = the first NRHS */ 00183 /* columns of M*I, the true solutions are just the first NRHS columns */ 00184 /* of the inverse Hilbert matrix. */ 00185 work[1] = (real) (*n); 00186 i__1 = *n; 00187 for (j = 2; j <= i__1; ++j) { 00188 work[j] = work[j - 1] / (j - 1) * (j - 1 - *n) / (j - 1) * (*n + j - 00189 1); 00190 } 00191 i__1 = *nrhs; 00192 for (j = 1; j <= i__1; ++j) { 00193 i__2 = *n; 00194 for (i__ = 1; i__ <= i__2; ++i__) { 00195 x[i__ + j * x_dim1] = work[i__] * work[j] / (i__ + j - 1); 00196 } 00197 } 00198 return 0; 00199 } /* slahilb_ */