slasq4.c
Go to the documentation of this file.
00001 /* slasq4.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 /* Subroutine */ int slasq4_(integer *i0, integer *n0, real *z__, integer *pp, 
00017          integer *n0in, real *dmin__, real *dmin1, real *dmin2, real *dn, 
00018         real *dn1, real *dn2, real *tau, integer *ttype, real *g)
00019 {
00020     /* System generated locals */
00021     integer i__1;
00022     real r__1, r__2;
00023 
00024     /* Builtin functions */
00025     double sqrt(doublereal);
00026 
00027     /* Local variables */
00028     real s, a2, b1, b2;
00029     integer i4, nn, np;
00030     real gam, gap1, gap2;
00031 
00032 
00033 /*  -- LAPACK routine (version 3.2)                                    -- */
00034 
00035 /*  -- Contributed by Osni Marques of the Lawrence Berkeley National   -- */
00036 /*  -- Laboratory and Beresford Parlett of the Univ. of California at  -- */
00037 /*  -- Berkeley                                                        -- */
00038 /*  -- November 2008                                                   -- */
00039 
00040 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
00041 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
00042 
00043 /*     .. Scalar Arguments .. */
00044 /*     .. */
00045 /*     .. Array Arguments .. */
00046 /*     .. */
00047 
00048 /*  Purpose */
00049 /*  ======= */
00050 
00051 /*  SLASQ4 computes an approximation TAU to the smallest eigenvalue */
00052 /*  using values of d from the previous transform. */
00053 
00054 /*  I0    (input) INTEGER */
00055 /*        First index. */
00056 
00057 /*  N0    (input) INTEGER */
00058 /*        Last index. */
00059 
00060 /*  Z     (input) REAL array, dimension ( 4*N ) */
00061 /*        Z holds the qd array. */
00062 
00063 /*  PP    (input) INTEGER */
00064 /*        PP=0 for ping, PP=1 for pong. */
00065 
00066 /*  NOIN  (input) INTEGER */
00067 /*        The value of N0 at start of EIGTEST. */
00068 
00069 /*  DMIN  (input) REAL */
00070 /*        Minimum value of d. */
00071 
00072 /*  DMIN1 (input) REAL */
00073 /*        Minimum value of d, excluding D( N0 ). */
00074 
00075 /*  DMIN2 (input) REAL */
00076 /*        Minimum value of d, excluding D( N0 ) and D( N0-1 ). */
00077 
00078 /*  DN    (input) REAL */
00079 /*        d(N) */
00080 
00081 /*  DN1   (input) REAL */
00082 /*        d(N-1) */
00083 
00084 /*  DN2   (input) REAL */
00085 /*        d(N-2) */
00086 
00087 /*  TAU   (output) REAL */
00088 /*        This is the shift. */
00089 
00090 /*  TTYPE (output) INTEGER */
00091 /*        Shift type. */
00092 
00093 /*  G     (input/output) REAL */
00094 /*        G is passed as an argument in order to save its value between */
00095 /*        calls to SLASQ4. */
00096 
00097 /*  Further Details */
00098 /*  =============== */
00099 /*  CNST1 = 9/16 */
00100 
00101 /*  ===================================================================== */
00102 
00103 /*     .. Parameters .. */
00104 /*     .. */
00105 /*     .. Local Scalars .. */
00106 /*     .. */
00107 /*     .. Intrinsic Functions .. */
00108 /*     .. */
00109 /*     .. Executable Statements .. */
00110 
00111 /*     A negative DMIN forces the shift to take that absolute value */
00112 /*     TTYPE records the type of shift. */
00113 
00114     /* Parameter adjustments */
00115     --z__;
00116 
00117     /* Function Body */
00118     if (*dmin__ <= 0.f) {
00119         *tau = -(*dmin__);
00120         *ttype = -1;
00121         return 0;
00122     }
00123 
00124     nn = (*n0 << 2) + *pp;
00125     if (*n0in == *n0) {
00126 
00127 /*        No eigenvalues deflated. */
00128 
00129         if (*dmin__ == *dn || *dmin__ == *dn1) {
00130 
00131             b1 = sqrt(z__[nn - 3]) * sqrt(z__[nn - 5]);
00132             b2 = sqrt(z__[nn - 7]) * sqrt(z__[nn - 9]);
00133             a2 = z__[nn - 7] + z__[nn - 5];
00134 
00135 /*           Cases 2 and 3. */
00136 
00137             if (*dmin__ == *dn && *dmin1 == *dn1) {
00138                 gap2 = *dmin2 - a2 - *dmin2 * .25f;
00139                 if (gap2 > 0.f && gap2 > b2) {
00140                     gap1 = a2 - *dn - b2 / gap2 * b2;
00141                 } else {
00142                     gap1 = a2 - *dn - (b1 + b2);
00143                 }
00144                 if (gap1 > 0.f && gap1 > b1) {
00145 /* Computing MAX */
00146                     r__1 = *dn - b1 / gap1 * b1, r__2 = *dmin__ * .5f;
00147                     s = dmax(r__1,r__2);
00148                     *ttype = -2;
00149                 } else {
00150                     s = 0.f;
00151                     if (*dn > b1) {
00152                         s = *dn - b1;
00153                     }
00154                     if (a2 > b1 + b2) {
00155 /* Computing MIN */
00156                         r__1 = s, r__2 = a2 - (b1 + b2);
00157                         s = dmin(r__1,r__2);
00158                     }
00159 /* Computing MAX */
00160                     r__1 = s, r__2 = *dmin__ * .333f;
00161                     s = dmax(r__1,r__2);
00162                     *ttype = -3;
00163                 }
00164             } else {
00165 
00166 /*              Case 4. */
00167 
00168                 *ttype = -4;
00169                 s = *dmin__ * .25f;
00170                 if (*dmin__ == *dn) {
00171                     gam = *dn;
00172                     a2 = 0.f;
00173                     if (z__[nn - 5] > z__[nn - 7]) {
00174                         return 0;
00175                     }
00176                     b2 = z__[nn - 5] / z__[nn - 7];
00177                     np = nn - 9;
00178                 } else {
00179                     np = nn - (*pp << 1);
00180                     b2 = z__[np - 2];
00181                     gam = *dn1;
00182                     if (z__[np - 4] > z__[np - 2]) {
00183                         return 0;
00184                     }
00185                     a2 = z__[np - 4] / z__[np - 2];
00186                     if (z__[nn - 9] > z__[nn - 11]) {
00187                         return 0;
00188                     }
00189                     b2 = z__[nn - 9] / z__[nn - 11];
00190                     np = nn - 13;
00191                 }
00192 
00193 /*              Approximate contribution to norm squared from I < NN-1. */
00194 
00195                 a2 += b2;
00196                 i__1 = (*i0 << 2) - 1 + *pp;
00197                 for (i4 = np; i4 >= i__1; i4 += -4) {
00198                     if (b2 == 0.f) {
00199                         goto L20;
00200                     }
00201                     b1 = b2;
00202                     if (z__[i4] > z__[i4 - 2]) {
00203                         return 0;
00204                     }
00205                     b2 *= z__[i4] / z__[i4 - 2];
00206                     a2 += b2;
00207                     if (dmax(b2,b1) * 100.f < a2 || .563f < a2) {
00208                         goto L20;
00209                     }
00210 /* L10: */
00211                 }
00212 L20:
00213                 a2 *= 1.05f;
00214 
00215 /*              Rayleigh quotient residual bound. */
00216 
00217                 if (a2 < .563f) {
00218                     s = gam * (1.f - sqrt(a2)) / (a2 + 1.f);
00219                 }
00220             }
00221         } else if (*dmin__ == *dn2) {
00222 
00223 /*           Case 5. */
00224 
00225             *ttype = -5;
00226             s = *dmin__ * .25f;
00227 
00228 /*           Compute contribution to norm squared from I > NN-2. */
00229 
00230             np = nn - (*pp << 1);
00231             b1 = z__[np - 2];
00232             b2 = z__[np - 6];
00233             gam = *dn2;
00234             if (z__[np - 8] > b2 || z__[np - 4] > b1) {
00235                 return 0;
00236             }
00237             a2 = z__[np - 8] / b2 * (z__[np - 4] / b1 + 1.f);
00238 
00239 /*           Approximate contribution to norm squared from I < NN-2. */
00240 
00241             if (*n0 - *i0 > 2) {
00242                 b2 = z__[nn - 13] / z__[nn - 15];
00243                 a2 += b2;
00244                 i__1 = (*i0 << 2) - 1 + *pp;
00245                 for (i4 = nn - 17; i4 >= i__1; i4 += -4) {
00246                     if (b2 == 0.f) {
00247                         goto L40;
00248                     }
00249                     b1 = b2;
00250                     if (z__[i4] > z__[i4 - 2]) {
00251                         return 0;
00252                     }
00253                     b2 *= z__[i4] / z__[i4 - 2];
00254                     a2 += b2;
00255                     if (dmax(b2,b1) * 100.f < a2 || .563f < a2) {
00256                         goto L40;
00257                     }
00258 /* L30: */
00259                 }
00260 L40:
00261                 a2 *= 1.05f;
00262             }
00263 
00264             if (a2 < .563f) {
00265                 s = gam * (1.f - sqrt(a2)) / (a2 + 1.f);
00266             }
00267         } else {
00268 
00269 /*           Case 6, no information to guide us. */
00270 
00271             if (*ttype == -6) {
00272                 *g += (1.f - *g) * .333f;
00273             } else if (*ttype == -18) {
00274                 *g = .083250000000000005f;
00275             } else {
00276                 *g = .25f;
00277             }
00278             s = *g * *dmin__;
00279             *ttype = -6;
00280         }
00281 
00282     } else if (*n0in == *n0 + 1) {
00283 
00284 /*        One eigenvalue just deflated. Use DMIN1, DN1 for DMIN and DN. */
00285 
00286         if (*dmin1 == *dn1 && *dmin2 == *dn2) {
00287 
00288 /*           Cases 7 and 8. */
00289 
00290             *ttype = -7;
00291             s = *dmin1 * .333f;
00292             if (z__[nn - 5] > z__[nn - 7]) {
00293                 return 0;
00294             }
00295             b1 = z__[nn - 5] / z__[nn - 7];
00296             b2 = b1;
00297             if (b2 == 0.f) {
00298                 goto L60;
00299             }
00300             i__1 = (*i0 << 2) - 1 + *pp;
00301             for (i4 = (*n0 << 2) - 9 + *pp; i4 >= i__1; i4 += -4) {
00302                 a2 = b1;
00303                 if (z__[i4] > z__[i4 - 2]) {
00304                     return 0;
00305                 }
00306                 b1 *= z__[i4] / z__[i4 - 2];
00307                 b2 += b1;
00308                 if (dmax(b1,a2) * 100.f < b2) {
00309                     goto L60;
00310                 }
00311 /* L50: */
00312             }
00313 L60:
00314             b2 = sqrt(b2 * 1.05f);
00315 /* Computing 2nd power */
00316             r__1 = b2;
00317             a2 = *dmin1 / (r__1 * r__1 + 1.f);
00318             gap2 = *dmin2 * .5f - a2;
00319             if (gap2 > 0.f && gap2 > b2 * a2) {
00320 /* Computing MAX */
00321                 r__1 = s, r__2 = a2 * (1.f - a2 * 1.01f * (b2 / gap2) * b2);
00322                 s = dmax(r__1,r__2);
00323             } else {
00324 /* Computing MAX */
00325                 r__1 = s, r__2 = a2 * (1.f - b2 * 1.01f);
00326                 s = dmax(r__1,r__2);
00327                 *ttype = -8;
00328             }
00329         } else {
00330 
00331 /*           Case 9. */
00332 
00333             s = *dmin1 * .25f;
00334             if (*dmin1 == *dn1) {
00335                 s = *dmin1 * .5f;
00336             }
00337             *ttype = -9;
00338         }
00339 
00340     } else if (*n0in == *n0 + 2) {
00341 
00342 /*        Two eigenvalues deflated. Use DMIN2, DN2 for DMIN and DN. */
00343 
00344 /*        Cases 10 and 11. */
00345 
00346         if (*dmin2 == *dn2 && z__[nn - 5] * 2.f < z__[nn - 7]) {
00347             *ttype = -10;
00348             s = *dmin2 * .333f;
00349             if (z__[nn - 5] > z__[nn - 7]) {
00350                 return 0;
00351             }
00352             b1 = z__[nn - 5] / z__[nn - 7];
00353             b2 = b1;
00354             if (b2 == 0.f) {
00355                 goto L80;
00356             }
00357             i__1 = (*i0 << 2) - 1 + *pp;
00358             for (i4 = (*n0 << 2) - 9 + *pp; i4 >= i__1; i4 += -4) {
00359                 if (z__[i4] > z__[i4 - 2]) {
00360                     return 0;
00361                 }
00362                 b1 *= z__[i4] / z__[i4 - 2];
00363                 b2 += b1;
00364                 if (b1 * 100.f < b2) {
00365                     goto L80;
00366                 }
00367 /* L70: */
00368             }
00369 L80:
00370             b2 = sqrt(b2 * 1.05f);
00371 /* Computing 2nd power */
00372             r__1 = b2;
00373             a2 = *dmin2 / (r__1 * r__1 + 1.f);
00374             gap2 = z__[nn - 7] + z__[nn - 9] - sqrt(z__[nn - 11]) * sqrt(z__[
00375                     nn - 9]) - a2;
00376             if (gap2 > 0.f && gap2 > b2 * a2) {
00377 /* Computing MAX */
00378                 r__1 = s, r__2 = a2 * (1.f - a2 * 1.01f * (b2 / gap2) * b2);
00379                 s = dmax(r__1,r__2);
00380             } else {
00381 /* Computing MAX */
00382                 r__1 = s, r__2 = a2 * (1.f - b2 * 1.01f);
00383                 s = dmax(r__1,r__2);
00384             }
00385         } else {
00386             s = *dmin2 * .25f;
00387             *ttype = -11;
00388         }
00389     } else if (*n0in > *n0 + 2) {
00390 
00391 /*        Case 12, more than two eigenvalues deflated. No information. */
00392 
00393         s = 0.f;
00394         *ttype = -12;
00395     }
00396 
00397     *tau = s;
00398     return 0;
00399 
00400 /*     End of SLASQ4 */
00401 
00402 } /* slasq4_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:11