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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:46