dlacon.c
Go to the documentation of this file.
00001 /* dlacon.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 integer c__1 = 1;
00019 static doublereal c_b11 = 1.;
00020 
00021 /* Subroutine */ int dlacon_(integer *n, doublereal *v, doublereal *x, 
00022         integer *isgn, doublereal *est, integer *kase)
00023 {
00024     /* System generated locals */
00025     integer i__1;
00026     doublereal d__1;
00027 
00028     /* Builtin functions */
00029     double d_sign(doublereal *, doublereal *);
00030     integer i_dnnt(doublereal *);
00031 
00032     /* Local variables */
00033     static integer i__, j, iter;
00034     static doublereal temp;
00035     static integer jump;
00036     extern doublereal dasum_(integer *, doublereal *, integer *);
00037     static integer jlast;
00038     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00039             doublereal *, integer *);
00040     extern integer idamax_(integer *, doublereal *, integer *);
00041     static doublereal altsgn, estold;
00042 
00043 
00044 /*  -- LAPACK auxiliary routine (version 3.2) -- */
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 /*  DLACON estimates the 1-norm of a square, real matrix A. */
00057 /*  Reverse communication is used for evaluating matrix-vector products. */
00058 
00059 /*  Arguments */
00060 /*  ========= */
00061 
00062 /*  N      (input) INTEGER */
00063 /*         The order of the matrix.  N >= 1. */
00064 
00065 /*  V      (workspace) DOUBLE PRECISION array, dimension (N) */
00066 /*         On the final return, V = A*W,  where  EST = norm(V)/norm(W) */
00067 /*         (W is not returned). */
00068 
00069 /*  X      (input/output) DOUBLE PRECISION array, dimension (N) */
00070 /*         On an intermediate return, X should be overwritten by */
00071 /*               A * X,   if KASE=1, */
00072 /*               A' * X,  if KASE=2, */
00073 /*         and DLACON must be re-called with all the other parameters */
00074 /*         unchanged. */
00075 
00076 /*  ISGN   (workspace) INTEGER array, dimension (N) */
00077 
00078 /*  EST    (input/output) DOUBLE PRECISION */
00079 /*         On entry with KASE = 1 or 2 and JUMP = 3, EST should be */
00080 /*         unchanged from the previous call to DLACON. */
00081 /*         On exit, EST is an estimate (a lower bound) for norm(A). */
00082 
00083 /*  KASE   (input/output) INTEGER */
00084 /*         On the initial call to DLACON, KASE should be 0. */
00085 /*         On an intermediate return, KASE will be 1 or 2, indicating */
00086 /*         whether X should be overwritten by A * X  or A' * X. */
00087 /*         On the final return from DLACON, KASE will again be 0. */
00088 
00089 /*  Further Details */
00090 /*  ======= ======= */
00091 
00092 /*  Contributed by Nick Higham, University of Manchester. */
00093 /*  Originally named SONEST, dated March 16, 1988. */
00094 
00095 /*  Reference: N.J. Higham, "FORTRAN codes for estimating the one-norm of */
00096 /*  a real or complex matrix, with applications to condition estimation", */
00097 /*  ACM Trans. Math. Soft., vol. 14, no. 4, pp. 381-396, December 1988. */
00098 
00099 /*  ===================================================================== */
00100 
00101 /*     .. Parameters .. */
00102 /*     .. */
00103 /*     .. Local Scalars .. */
00104 /*     .. */
00105 /*     .. External Functions .. */
00106 /*     .. */
00107 /*     .. External Subroutines .. */
00108 /*     .. */
00109 /*     .. Intrinsic Functions .. */
00110 /*     .. */
00111 /*     .. Save statement .. */
00112 /*     .. */
00113 /*     .. Executable Statements .. */
00114 
00115     /* Parameter adjustments */
00116     --isgn;
00117     --x;
00118     --v;
00119 
00120     /* Function Body */
00121     if (*kase == 0) {
00122         i__1 = *n;
00123         for (i__ = 1; i__ <= i__1; ++i__) {
00124             x[i__] = 1. / (doublereal) (*n);
00125 /* L10: */
00126         }
00127         *kase = 1;
00128         jump = 1;
00129         return 0;
00130     }
00131 
00132     switch (jump) {
00133         case 1:  goto L20;
00134         case 2:  goto L40;
00135         case 3:  goto L70;
00136         case 4:  goto L110;
00137         case 5:  goto L140;
00138     }
00139 
00140 /*     ................ ENTRY   (JUMP = 1) */
00141 /*     FIRST ITERATION.  X HAS BEEN OVERWRITTEN BY A*X. */
00142 
00143 L20:
00144     if (*n == 1) {
00145         v[1] = x[1];
00146         *est = abs(v[1]);
00147 /*        ... QUIT */
00148         goto L150;
00149     }
00150     *est = dasum_(n, &x[1], &c__1);
00151 
00152     i__1 = *n;
00153     for (i__ = 1; i__ <= i__1; ++i__) {
00154         x[i__] = d_sign(&c_b11, &x[i__]);
00155         isgn[i__] = i_dnnt(&x[i__]);
00156 /* L30: */
00157     }
00158     *kase = 2;
00159     jump = 2;
00160     return 0;
00161 
00162 /*     ................ ENTRY   (JUMP = 2) */
00163 /*     FIRST ITERATION.  X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X. */
00164 
00165 L40:
00166     j = idamax_(n, &x[1], &c__1);
00167     iter = 2;
00168 
00169 /*     MAIN LOOP - ITERATIONS 2,3,...,ITMAX. */
00170 
00171 L50:
00172     i__1 = *n;
00173     for (i__ = 1; i__ <= i__1; ++i__) {
00174         x[i__] = 0.;
00175 /* L60: */
00176     }
00177     x[j] = 1.;
00178     *kase = 1;
00179     jump = 3;
00180     return 0;
00181 
00182 /*     ................ ENTRY   (JUMP = 3) */
00183 /*     X HAS BEEN OVERWRITTEN BY A*X. */
00184 
00185 L70:
00186     dcopy_(n, &x[1], &c__1, &v[1], &c__1);
00187     estold = *est;
00188     *est = dasum_(n, &v[1], &c__1);
00189     i__1 = *n;
00190     for (i__ = 1; i__ <= i__1; ++i__) {
00191         d__1 = d_sign(&c_b11, &x[i__]);
00192         if (i_dnnt(&d__1) != isgn[i__]) {
00193             goto L90;
00194         }
00195 /* L80: */
00196     }
00197 /*     REPEATED SIGN VECTOR DETECTED, HENCE ALGORITHM HAS CONVERGED. */
00198     goto L120;
00199 
00200 L90:
00201 /*     TEST FOR CYCLING. */
00202     if (*est <= estold) {
00203         goto L120;
00204     }
00205 
00206     i__1 = *n;
00207     for (i__ = 1; i__ <= i__1; ++i__) {
00208         x[i__] = d_sign(&c_b11, &x[i__]);
00209         isgn[i__] = i_dnnt(&x[i__]);
00210 /* L100: */
00211     }
00212     *kase = 2;
00213     jump = 4;
00214     return 0;
00215 
00216 /*     ................ ENTRY   (JUMP = 4) */
00217 /*     X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X. */
00218 
00219 L110:
00220     jlast = j;
00221     j = idamax_(n, &x[1], &c__1);
00222     if (x[jlast] != (d__1 = x[j], abs(d__1)) && iter < 5) {
00223         ++iter;
00224         goto L50;
00225     }
00226 
00227 /*     ITERATION COMPLETE.  FINAL STAGE. */
00228 
00229 L120:
00230     altsgn = 1.;
00231     i__1 = *n;
00232     for (i__ = 1; i__ <= i__1; ++i__) {
00233         x[i__] = altsgn * ((doublereal) (i__ - 1) / (doublereal) (*n - 1) + 
00234                 1.);
00235         altsgn = -altsgn;
00236 /* L130: */
00237     }
00238     *kase = 1;
00239     jump = 5;
00240     return 0;
00241 
00242 /*     ................ ENTRY   (JUMP = 5) */
00243 /*     X HAS BEEN OVERWRITTEN BY A*X. */
00244 
00245 L140:
00246     temp = dasum_(n, &x[1], &c__1) / (doublereal) (*n * 3) * 2.;
00247     if (temp > *est) {
00248         dcopy_(n, &x[1], &c__1, &v[1], &c__1);
00249         *est = temp;
00250     }
00251 
00252 L150:
00253     *kase = 0;
00254     return 0;
00255 
00256 /*     End of DLACON */
00257 
00258 } /* dlacon_ */


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