dsterf.c
Go to the documentation of this file.
00001 /* dsterf.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__0 = 0;
00019 static integer c__1 = 1;
00020 static doublereal c_b32 = 1.;
00021 
00022 /* Subroutine */ int dsterf_(integer *n, doublereal *d__, doublereal *e, 
00023         integer *info)
00024 {
00025     /* System generated locals */
00026     integer i__1;
00027     doublereal d__1, d__2, d__3;
00028 
00029     /* Builtin functions */
00030     double sqrt(doublereal), d_sign(doublereal *, doublereal *);
00031 
00032     /* Local variables */
00033     doublereal c__;
00034     integer i__, l, m;
00035     doublereal p, r__, s;
00036     integer l1;
00037     doublereal bb, rt1, rt2, eps, rte;
00038     integer lsv;
00039     doublereal eps2, oldc;
00040     integer lend, jtot;
00041     extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal 
00042             *, doublereal *, doublereal *);
00043     doublereal gamma, alpha, sigma, anorm;
00044     extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
00045     integer iscale;
00046     extern /* Subroutine */ int dlascl_(char *, integer *, integer *, 
00047             doublereal *, doublereal *, integer *, integer *, doublereal *, 
00048             integer *, integer *);
00049     doublereal oldgam, safmin;
00050     extern /* Subroutine */ int xerbla_(char *, integer *);
00051     doublereal safmax;
00052     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
00053     extern /* Subroutine */ int dlasrt_(char *, integer *, doublereal *, 
00054             integer *);
00055     integer lendsv;
00056     doublereal ssfmin;
00057     integer nmaxit;
00058     doublereal ssfmax;
00059 
00060 
00061 /*  -- LAPACK routine (version 3.2) -- */
00062 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00063 /*     November 2006 */
00064 
00065 /*     .. Scalar Arguments .. */
00066 /*     .. */
00067 /*     .. Array Arguments .. */
00068 /*     .. */
00069 
00070 /*  Purpose */
00071 /*  ======= */
00072 
00073 /*  DSTERF computes all eigenvalues of a symmetric tridiagonal matrix */
00074 /*  using the Pal-Walker-Kahan variant of the QL or QR algorithm. */
00075 
00076 /*  Arguments */
00077 /*  ========= */
00078 
00079 /*  N       (input) INTEGER */
00080 /*          The order of the matrix.  N >= 0. */
00081 
00082 /*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
00083 /*          On entry, the n diagonal elements of the tridiagonal matrix. */
00084 /*          On exit, if INFO = 0, the eigenvalues in ascending order. */
00085 
00086 /*  E       (input/output) DOUBLE PRECISION array, dimension (N-1) */
00087 /*          On entry, the (n-1) subdiagonal elements of the tridiagonal */
00088 /*          matrix. */
00089 /*          On exit, E has been destroyed. */
00090 
00091 /*  INFO    (output) INTEGER */
00092 /*          = 0:  successful exit */
00093 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00094 /*          > 0:  the algorithm failed to find all of the eigenvalues in */
00095 /*                a total of 30*N iterations; if INFO = i, then i */
00096 /*                elements of E have not converged to zero. */
00097 
00098 /*  ===================================================================== */
00099 
00100 /*     .. Parameters .. */
00101 /*     .. */
00102 /*     .. Local Scalars .. */
00103 /*     .. */
00104 /*     .. External Functions .. */
00105 /*     .. */
00106 /*     .. External Subroutines .. */
00107 /*     .. */
00108 /*     .. Intrinsic Functions .. */
00109 /*     .. */
00110 /*     .. Executable Statements .. */
00111 
00112 /*     Test the input parameters. */
00113 
00114     /* Parameter adjustments */
00115     --e;
00116     --d__;
00117 
00118     /* Function Body */
00119     *info = 0;
00120 
00121 /*     Quick return if possible */
00122 
00123     if (*n < 0) {
00124         *info = -1;
00125         i__1 = -(*info);
00126         xerbla_("DSTERF", &i__1);
00127         return 0;
00128     }
00129     if (*n <= 1) {
00130         return 0;
00131     }
00132 
00133 /*     Determine the unit roundoff for this environment. */
00134 
00135     eps = dlamch_("E");
00136 /* Computing 2nd power */
00137     d__1 = eps;
00138     eps2 = d__1 * d__1;
00139     safmin = dlamch_("S");
00140     safmax = 1. / safmin;
00141     ssfmax = sqrt(safmax) / 3.;
00142     ssfmin = sqrt(safmin) / eps2;
00143 
00144 /*     Compute the eigenvalues of the tridiagonal matrix. */
00145 
00146     nmaxit = *n * 30;
00147     sigma = 0.;
00148     jtot = 0;
00149 
00150 /*     Determine where the matrix splits and choose QL or QR iteration */
00151 /*     for each block, according to whether top or bottom diagonal */
00152 /*     element is smaller. */
00153 
00154     l1 = 1;
00155 
00156 L10:
00157     if (l1 > *n) {
00158         goto L170;
00159     }
00160     if (l1 > 1) {
00161         e[l1 - 1] = 0.;
00162     }
00163     i__1 = *n - 1;
00164     for (m = l1; m <= i__1; ++m) {
00165         if ((d__3 = e[m], abs(d__3)) <= sqrt((d__1 = d__[m], abs(d__1))) * 
00166                 sqrt((d__2 = d__[m + 1], abs(d__2))) * eps) {
00167             e[m] = 0.;
00168             goto L30;
00169         }
00170 /* L20: */
00171     }
00172     m = *n;
00173 
00174 L30:
00175     l = l1;
00176     lsv = l;
00177     lend = m;
00178     lendsv = lend;
00179     l1 = m + 1;
00180     if (lend == l) {
00181         goto L10;
00182     }
00183 
00184 /*     Scale submatrix in rows and columns L to LEND */
00185 
00186     i__1 = lend - l + 1;
00187     anorm = dlanst_("I", &i__1, &d__[l], &e[l]);
00188     iscale = 0;
00189     if (anorm > ssfmax) {
00190         iscale = 1;
00191         i__1 = lend - l + 1;
00192         dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &d__[l], n, 
00193                 info);
00194         i__1 = lend - l;
00195         dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &e[l], n, 
00196                 info);
00197     } else if (anorm < ssfmin) {
00198         iscale = 2;
00199         i__1 = lend - l + 1;
00200         dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &d__[l], n, 
00201                 info);
00202         i__1 = lend - l;
00203         dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &e[l], n, 
00204                 info);
00205     }
00206 
00207     i__1 = lend - 1;
00208     for (i__ = l; i__ <= i__1; ++i__) {
00209 /* Computing 2nd power */
00210         d__1 = e[i__];
00211         e[i__] = d__1 * d__1;
00212 /* L40: */
00213     }
00214 
00215 /*     Choose between QL and QR iteration */
00216 
00217     if ((d__1 = d__[lend], abs(d__1)) < (d__2 = d__[l], abs(d__2))) {
00218         lend = lsv;
00219         l = lendsv;
00220     }
00221 
00222     if (lend >= l) {
00223 
00224 /*        QL Iteration */
00225 
00226 /*        Look for small subdiagonal element. */
00227 
00228 L50:
00229         if (l != lend) {
00230             i__1 = lend - 1;
00231             for (m = l; m <= i__1; ++m) {
00232                 if ((d__2 = e[m], abs(d__2)) <= eps2 * (d__1 = d__[m] * d__[m 
00233                         + 1], abs(d__1))) {
00234                     goto L70;
00235                 }
00236 /* L60: */
00237             }
00238         }
00239         m = lend;
00240 
00241 L70:
00242         if (m < lend) {
00243             e[m] = 0.;
00244         }
00245         p = d__[l];
00246         if (m == l) {
00247             goto L90;
00248         }
00249 
00250 /*        If remaining matrix is 2 by 2, use DLAE2 to compute its */
00251 /*        eigenvalues. */
00252 
00253         if (m == l + 1) {
00254             rte = sqrt(e[l]);
00255             dlae2_(&d__[l], &rte, &d__[l + 1], &rt1, &rt2);
00256             d__[l] = rt1;
00257             d__[l + 1] = rt2;
00258             e[l] = 0.;
00259             l += 2;
00260             if (l <= lend) {
00261                 goto L50;
00262             }
00263             goto L150;
00264         }
00265 
00266         if (jtot == nmaxit) {
00267             goto L150;
00268         }
00269         ++jtot;
00270 
00271 /*        Form shift. */
00272 
00273         rte = sqrt(e[l]);
00274         sigma = (d__[l + 1] - p) / (rte * 2.);
00275         r__ = dlapy2_(&sigma, &c_b32);
00276         sigma = p - rte / (sigma + d_sign(&r__, &sigma));
00277 
00278         c__ = 1.;
00279         s = 0.;
00280         gamma = d__[m] - sigma;
00281         p = gamma * gamma;
00282 
00283 /*        Inner loop */
00284 
00285         i__1 = l;
00286         for (i__ = m - 1; i__ >= i__1; --i__) {
00287             bb = e[i__];
00288             r__ = p + bb;
00289             if (i__ != m - 1) {
00290                 e[i__ + 1] = s * r__;
00291             }
00292             oldc = c__;
00293             c__ = p / r__;
00294             s = bb / r__;
00295             oldgam = gamma;
00296             alpha = d__[i__];
00297             gamma = c__ * (alpha - sigma) - s * oldgam;
00298             d__[i__ + 1] = oldgam + (alpha - gamma);
00299             if (c__ != 0.) {
00300                 p = gamma * gamma / c__;
00301             } else {
00302                 p = oldc * bb;
00303             }
00304 /* L80: */
00305         }
00306 
00307         e[l] = s * p;
00308         d__[l] = sigma + gamma;
00309         goto L50;
00310 
00311 /*        Eigenvalue found. */
00312 
00313 L90:
00314         d__[l] = p;
00315 
00316         ++l;
00317         if (l <= lend) {
00318             goto L50;
00319         }
00320         goto L150;
00321 
00322     } else {
00323 
00324 /*        QR Iteration */
00325 
00326 /*        Look for small superdiagonal element. */
00327 
00328 L100:
00329         i__1 = lend + 1;
00330         for (m = l; m >= i__1; --m) {
00331             if ((d__2 = e[m - 1], abs(d__2)) <= eps2 * (d__1 = d__[m] * d__[m 
00332                     - 1], abs(d__1))) {
00333                 goto L120;
00334             }
00335 /* L110: */
00336         }
00337         m = lend;
00338 
00339 L120:
00340         if (m > lend) {
00341             e[m - 1] = 0.;
00342         }
00343         p = d__[l];
00344         if (m == l) {
00345             goto L140;
00346         }
00347 
00348 /*        If remaining matrix is 2 by 2, use DLAE2 to compute its */
00349 /*        eigenvalues. */
00350 
00351         if (m == l - 1) {
00352             rte = sqrt(e[l - 1]);
00353             dlae2_(&d__[l], &rte, &d__[l - 1], &rt1, &rt2);
00354             d__[l] = rt1;
00355             d__[l - 1] = rt2;
00356             e[l - 1] = 0.;
00357             l += -2;
00358             if (l >= lend) {
00359                 goto L100;
00360             }
00361             goto L150;
00362         }
00363 
00364         if (jtot == nmaxit) {
00365             goto L150;
00366         }
00367         ++jtot;
00368 
00369 /*        Form shift. */
00370 
00371         rte = sqrt(e[l - 1]);
00372         sigma = (d__[l - 1] - p) / (rte * 2.);
00373         r__ = dlapy2_(&sigma, &c_b32);
00374         sigma = p - rte / (sigma + d_sign(&r__, &sigma));
00375 
00376         c__ = 1.;
00377         s = 0.;
00378         gamma = d__[m] - sigma;
00379         p = gamma * gamma;
00380 
00381 /*        Inner loop */
00382 
00383         i__1 = l - 1;
00384         for (i__ = m; i__ <= i__1; ++i__) {
00385             bb = e[i__];
00386             r__ = p + bb;
00387             if (i__ != m) {
00388                 e[i__ - 1] = s * r__;
00389             }
00390             oldc = c__;
00391             c__ = p / r__;
00392             s = bb / r__;
00393             oldgam = gamma;
00394             alpha = d__[i__ + 1];
00395             gamma = c__ * (alpha - sigma) - s * oldgam;
00396             d__[i__] = oldgam + (alpha - gamma);
00397             if (c__ != 0.) {
00398                 p = gamma * gamma / c__;
00399             } else {
00400                 p = oldc * bb;
00401             }
00402 /* L130: */
00403         }
00404 
00405         e[l - 1] = s * p;
00406         d__[l] = sigma + gamma;
00407         goto L100;
00408 
00409 /*        Eigenvalue found. */
00410 
00411 L140:
00412         d__[l] = p;
00413 
00414         --l;
00415         if (l >= lend) {
00416             goto L100;
00417         }
00418         goto L150;
00419 
00420     }
00421 
00422 /*     Undo scaling if necessary */
00423 
00424 L150:
00425     if (iscale == 1) {
00426         i__1 = lendsv - lsv + 1;
00427         dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &d__[lsv], 
00428                 n, info);
00429     }
00430     if (iscale == 2) {
00431         i__1 = lendsv - lsv + 1;
00432         dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &d__[lsv], 
00433                 n, info);
00434     }
00435 
00436 /*     Check for no convergence to an eigenvalue after a total */
00437 /*     of N*MAXIT iterations. */
00438 
00439     if (jtot < nmaxit) {
00440         goto L10;
00441     }
00442     i__1 = *n - 1;
00443     for (i__ = 1; i__ <= i__1; ++i__) {
00444         if (e[i__] != 0.) {
00445             ++(*info);
00446         }
00447 /* L160: */
00448     }
00449     goto L180;
00450 
00451 /*     Sort eigenvalues in increasing order. */
00452 
00453 L170:
00454     dlasrt_("I", n, &d__[1], info);
00455 
00456 L180:
00457     return 0;
00458 
00459 /*     End of DSTERF */
00460 
00461 } /* dsterf_ */


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