zlaein.c
Go to the documentation of this file.
00001 /* zlaein.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 
00020 /* Subroutine */ int zlaein_(logical *rightv, logical *noinit, integer *n, 
00021         doublecomplex *h__, integer *ldh, doublecomplex *w, doublecomplex *v, 
00022         doublecomplex *b, integer *ldb, doublereal *rwork, doublereal *eps3, 
00023         doublereal *smlnum, integer *info)
00024 {
00025     /* System generated locals */
00026     integer b_dim1, b_offset, h_dim1, h_offset, i__1, i__2, i__3, i__4, i__5;
00027     doublereal d__1, d__2, d__3, d__4;
00028     doublecomplex z__1, z__2;
00029 
00030     /* Builtin functions */
00031     double sqrt(doublereal), d_imag(doublecomplex *);
00032 
00033     /* Local variables */
00034     integer i__, j;
00035     doublecomplex x, ei, ej;
00036     integer its, ierr;
00037     doublecomplex temp;
00038     doublereal scale;
00039     char trans[1];
00040     doublereal rtemp, rootn, vnorm;
00041     extern doublereal dznrm2_(integer *, doublecomplex *, integer *);
00042     extern /* Subroutine */ int zdscal_(integer *, doublereal *, 
00043             doublecomplex *, integer *);
00044     extern integer izamax_(integer *, doublecomplex *, integer *);
00045     extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *, 
00046              doublecomplex *);
00047     char normin[1];
00048     extern doublereal dzasum_(integer *, doublecomplex *, integer *);
00049     doublereal nrmsml;
00050     extern /* Subroutine */ int zlatrs_(char *, char *, char *, char *, 
00051             integer *, doublecomplex *, integer *, doublecomplex *, 
00052             doublereal *, doublereal *, integer *);
00053     doublereal growto;
00054 
00055 
00056 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00057 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00058 /*     November 2006 */
00059 
00060 /*     .. Scalar Arguments .. */
00061 /*     .. */
00062 /*     .. Array Arguments .. */
00063 /*     .. */
00064 
00065 /*  Purpose */
00066 /*  ======= */
00067 
00068 /*  ZLAEIN uses inverse iteration to find a right or left eigenvector */
00069 /*  corresponding to the eigenvalue W of a complex upper Hessenberg */
00070 /*  matrix H. */
00071 
00072 /*  Arguments */
00073 /*  ========= */
00074 
00075 /*  RIGHTV   (input) LOGICAL */
00076 /*          = .TRUE. : compute right eigenvector; */
00077 /*          = .FALSE.: compute left eigenvector. */
00078 
00079 /*  NOINIT   (input) LOGICAL */
00080 /*          = .TRUE. : no initial vector supplied in V */
00081 /*          = .FALSE.: initial vector supplied in V. */
00082 
00083 /*  N       (input) INTEGER */
00084 /*          The order of the matrix H.  N >= 0. */
00085 
00086 /*  H       (input) COMPLEX*16 array, dimension (LDH,N) */
00087 /*          The upper Hessenberg matrix H. */
00088 
00089 /*  LDH     (input) INTEGER */
00090 /*          The leading dimension of the array H.  LDH >= max(1,N). */
00091 
00092 /*  W       (input) COMPLEX*16 */
00093 /*          The eigenvalue of H whose corresponding right or left */
00094 /*          eigenvector is to be computed. */
00095 
00096 /*  V       (input/output) COMPLEX*16 array, dimension (N) */
00097 /*          On entry, if NOINIT = .FALSE., V must contain a starting */
00098 /*          vector for inverse iteration; otherwise V need not be set. */
00099 /*          On exit, V contains the computed eigenvector, normalized so */
00100 /*          that the component of largest magnitude has magnitude 1; here */
00101 /*          the magnitude of a complex number (x,y) is taken to be */
00102 /*          |x| + |y|. */
00103 
00104 /*  B       (workspace) COMPLEX*16 array, dimension (LDB,N) */
00105 
00106 /*  LDB     (input) INTEGER */
00107 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00108 
00109 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (N) */
00110 
00111 /*  EPS3    (input) DOUBLE PRECISION */
00112 /*          A small machine-dependent value which is used to perturb */
00113 /*          close eigenvalues, and to replace zero pivots. */
00114 
00115 /*  SMLNUM  (input) DOUBLE PRECISION */
00116 /*          A machine-dependent value close to the underflow threshold. */
00117 
00118 /*  INFO    (output) INTEGER */
00119 /*          = 0:  successful exit */
00120 /*          = 1:  inverse iteration did not converge; V is set to the */
00121 /*                last iterate. */
00122 
00123 /*  ===================================================================== */
00124 
00125 /*     .. Parameters .. */
00126 /*     .. */
00127 /*     .. Local Scalars .. */
00128 /*     .. */
00129 /*     .. External Functions .. */
00130 /*     .. */
00131 /*     .. External Subroutines .. */
00132 /*     .. */
00133 /*     .. Intrinsic Functions .. */
00134 /*     .. */
00135 /*     .. Statement Functions .. */
00136 /*     .. */
00137 /*     .. Statement Function definitions .. */
00138 /*     .. */
00139 /*     .. Executable Statements .. */
00140 
00141     /* Parameter adjustments */
00142     h_dim1 = *ldh;
00143     h_offset = 1 + h_dim1;
00144     h__ -= h_offset;
00145     --v;
00146     b_dim1 = *ldb;
00147     b_offset = 1 + b_dim1;
00148     b -= b_offset;
00149     --rwork;
00150 
00151     /* Function Body */
00152     *info = 0;
00153 
00154 /*     GROWTO is the threshold used in the acceptance test for an */
00155 /*     eigenvector. */
00156 
00157     rootn = sqrt((doublereal) (*n));
00158     growto = .1 / rootn;
00159 /* Computing MAX */
00160     d__1 = 1., d__2 = *eps3 * rootn;
00161     nrmsml = max(d__1,d__2) * *smlnum;
00162 
00163 /*     Form B = H - W*I (except that the subdiagonal elements are not */
00164 /*     stored). */
00165 
00166     i__1 = *n;
00167     for (j = 1; j <= i__1; ++j) {
00168         i__2 = j - 1;
00169         for (i__ = 1; i__ <= i__2; ++i__) {
00170             i__3 = i__ + j * b_dim1;
00171             i__4 = i__ + j * h_dim1;
00172             b[i__3].r = h__[i__4].r, b[i__3].i = h__[i__4].i;
00173 /* L10: */
00174         }
00175         i__2 = j + j * b_dim1;
00176         i__3 = j + j * h_dim1;
00177         z__1.r = h__[i__3].r - w->r, z__1.i = h__[i__3].i - w->i;
00178         b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00179 /* L20: */
00180     }
00181 
00182     if (*noinit) {
00183 
00184 /*        Initialize V. */
00185 
00186         i__1 = *n;
00187         for (i__ = 1; i__ <= i__1; ++i__) {
00188             i__2 = i__;
00189             v[i__2].r = *eps3, v[i__2].i = 0.;
00190 /* L30: */
00191         }
00192     } else {
00193 
00194 /*        Scale supplied initial vector. */
00195 
00196         vnorm = dznrm2_(n, &v[1], &c__1);
00197         d__1 = *eps3 * rootn / max(vnorm,nrmsml);
00198         zdscal_(n, &d__1, &v[1], &c__1);
00199     }
00200 
00201     if (*rightv) {
00202 
00203 /*        LU decomposition with partial pivoting of B, replacing zero */
00204 /*        pivots by EPS3. */
00205 
00206         i__1 = *n - 1;
00207         for (i__ = 1; i__ <= i__1; ++i__) {
00208             i__2 = i__ + 1 + i__ * h_dim1;
00209             ei.r = h__[i__2].r, ei.i = h__[i__2].i;
00210             i__2 = i__ + i__ * b_dim1;
00211             if ((d__1 = b[i__2].r, abs(d__1)) + (d__2 = d_imag(&b[i__ + i__ * 
00212                     b_dim1]), abs(d__2)) < (d__3 = ei.r, abs(d__3)) + (d__4 = 
00213                     d_imag(&ei), abs(d__4))) {
00214 
00215 /*              Interchange rows and eliminate. */
00216 
00217                 zladiv_(&z__1, &b[i__ + i__ * b_dim1], &ei);
00218                 x.r = z__1.r, x.i = z__1.i;
00219                 i__2 = i__ + i__ * b_dim1;
00220                 b[i__2].r = ei.r, b[i__2].i = ei.i;
00221                 i__2 = *n;
00222                 for (j = i__ + 1; j <= i__2; ++j) {
00223                     i__3 = i__ + 1 + j * b_dim1;
00224                     temp.r = b[i__3].r, temp.i = b[i__3].i;
00225                     i__3 = i__ + 1 + j * b_dim1;
00226                     i__4 = i__ + j * b_dim1;
00227                     z__2.r = x.r * temp.r - x.i * temp.i, z__2.i = x.r * 
00228                             temp.i + x.i * temp.r;
00229                     z__1.r = b[i__4].r - z__2.r, z__1.i = b[i__4].i - z__2.i;
00230                     b[i__3].r = z__1.r, b[i__3].i = z__1.i;
00231                     i__3 = i__ + j * b_dim1;
00232                     b[i__3].r = temp.r, b[i__3].i = temp.i;
00233 /* L40: */
00234                 }
00235             } else {
00236 
00237 /*              Eliminate without interchange. */
00238 
00239                 i__2 = i__ + i__ * b_dim1;
00240                 if (b[i__2].r == 0. && b[i__2].i == 0.) {
00241                     i__3 = i__ + i__ * b_dim1;
00242                     b[i__3].r = *eps3, b[i__3].i = 0.;
00243                 }
00244                 zladiv_(&z__1, &ei, &b[i__ + i__ * b_dim1]);
00245                 x.r = z__1.r, x.i = z__1.i;
00246                 if (x.r != 0. || x.i != 0.) {
00247                     i__2 = *n;
00248                     for (j = i__ + 1; j <= i__2; ++j) {
00249                         i__3 = i__ + 1 + j * b_dim1;
00250                         i__4 = i__ + 1 + j * b_dim1;
00251                         i__5 = i__ + j * b_dim1;
00252                         z__2.r = x.r * b[i__5].r - x.i * b[i__5].i, z__2.i = 
00253                                 x.r * b[i__5].i + x.i * b[i__5].r;
00254                         z__1.r = b[i__4].r - z__2.r, z__1.i = b[i__4].i - 
00255                                 z__2.i;
00256                         b[i__3].r = z__1.r, b[i__3].i = z__1.i;
00257 /* L50: */
00258                     }
00259                 }
00260             }
00261 /* L60: */
00262         }
00263         i__1 = *n + *n * b_dim1;
00264         if (b[i__1].r == 0. && b[i__1].i == 0.) {
00265             i__2 = *n + *n * b_dim1;
00266             b[i__2].r = *eps3, b[i__2].i = 0.;
00267         }
00268 
00269         *(unsigned char *)trans = 'N';
00270 
00271     } else {
00272 
00273 /*        UL decomposition with partial pivoting of B, replacing zero */
00274 /*        pivots by EPS3. */
00275 
00276         for (j = *n; j >= 2; --j) {
00277             i__1 = j + (j - 1) * h_dim1;
00278             ej.r = h__[i__1].r, ej.i = h__[i__1].i;
00279             i__1 = j + j * b_dim1;
00280             if ((d__1 = b[i__1].r, abs(d__1)) + (d__2 = d_imag(&b[j + j * 
00281                     b_dim1]), abs(d__2)) < (d__3 = ej.r, abs(d__3)) + (d__4 = 
00282                     d_imag(&ej), abs(d__4))) {
00283 
00284 /*              Interchange columns and eliminate. */
00285 
00286                 zladiv_(&z__1, &b[j + j * b_dim1], &ej);
00287                 x.r = z__1.r, x.i = z__1.i;
00288                 i__1 = j + j * b_dim1;
00289                 b[i__1].r = ej.r, b[i__1].i = ej.i;
00290                 i__1 = j - 1;
00291                 for (i__ = 1; i__ <= i__1; ++i__) {
00292                     i__2 = i__ + (j - 1) * b_dim1;
00293                     temp.r = b[i__2].r, temp.i = b[i__2].i;
00294                     i__2 = i__ + (j - 1) * b_dim1;
00295                     i__3 = i__ + j * b_dim1;
00296                     z__2.r = x.r * temp.r - x.i * temp.i, z__2.i = x.r * 
00297                             temp.i + x.i * temp.r;
00298                     z__1.r = b[i__3].r - z__2.r, z__1.i = b[i__3].i - z__2.i;
00299                     b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00300                     i__2 = i__ + j * b_dim1;
00301                     b[i__2].r = temp.r, b[i__2].i = temp.i;
00302 /* L70: */
00303                 }
00304             } else {
00305 
00306 /*              Eliminate without interchange. */
00307 
00308                 i__1 = j + j * b_dim1;
00309                 if (b[i__1].r == 0. && b[i__1].i == 0.) {
00310                     i__2 = j + j * b_dim1;
00311                     b[i__2].r = *eps3, b[i__2].i = 0.;
00312                 }
00313                 zladiv_(&z__1, &ej, &b[j + j * b_dim1]);
00314                 x.r = z__1.r, x.i = z__1.i;
00315                 if (x.r != 0. || x.i != 0.) {
00316                     i__1 = j - 1;
00317                     for (i__ = 1; i__ <= i__1; ++i__) {
00318                         i__2 = i__ + (j - 1) * b_dim1;
00319                         i__3 = i__ + (j - 1) * b_dim1;
00320                         i__4 = i__ + j * b_dim1;
00321                         z__2.r = x.r * b[i__4].r - x.i * b[i__4].i, z__2.i = 
00322                                 x.r * b[i__4].i + x.i * b[i__4].r;
00323                         z__1.r = b[i__3].r - z__2.r, z__1.i = b[i__3].i - 
00324                                 z__2.i;
00325                         b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00326 /* L80: */
00327                     }
00328                 }
00329             }
00330 /* L90: */
00331         }
00332         i__1 = b_dim1 + 1;
00333         if (b[i__1].r == 0. && b[i__1].i == 0.) {
00334             i__2 = b_dim1 + 1;
00335             b[i__2].r = *eps3, b[i__2].i = 0.;
00336         }
00337 
00338         *(unsigned char *)trans = 'C';
00339 
00340     }
00341 
00342     *(unsigned char *)normin = 'N';
00343     i__1 = *n;
00344     for (its = 1; its <= i__1; ++its) {
00345 
00346 /*        Solve U*x = scale*v for a right eigenvector */
00347 /*          or U'*x = scale*v for a left eigenvector, */
00348 /*        overwriting x on v. */
00349 
00350         zlatrs_("Upper", trans, "Nonunit", normin, n, &b[b_offset], ldb, &v[1]
00351 , &scale, &rwork[1], &ierr);
00352         *(unsigned char *)normin = 'Y';
00353 
00354 /*        Test for sufficient growth in the norm of v. */
00355 
00356         vnorm = dzasum_(n, &v[1], &c__1);
00357         if (vnorm >= growto * scale) {
00358             goto L120;
00359         }
00360 
00361 /*        Choose new orthogonal starting vector and try again. */
00362 
00363         rtemp = *eps3 / (rootn + 1.);
00364         v[1].r = *eps3, v[1].i = 0.;
00365         i__2 = *n;
00366         for (i__ = 2; i__ <= i__2; ++i__) {
00367             i__3 = i__;
00368             v[i__3].r = rtemp, v[i__3].i = 0.;
00369 /* L100: */
00370         }
00371         i__2 = *n - its + 1;
00372         i__3 = *n - its + 1;
00373         d__1 = *eps3 * rootn;
00374         z__1.r = v[i__3].r - d__1, z__1.i = v[i__3].i;
00375         v[i__2].r = z__1.r, v[i__2].i = z__1.i;
00376 /* L110: */
00377     }
00378 
00379 /*     Failure to find eigenvector in N iterations. */
00380 
00381     *info = 1;
00382 
00383 L120:
00384 
00385 /*     Normalize eigenvector. */
00386 
00387     i__ = izamax_(n, &v[1], &c__1);
00388     i__1 = i__;
00389     d__3 = 1. / ((d__1 = v[i__1].r, abs(d__1)) + (d__2 = d_imag(&v[i__]), abs(
00390             d__2)));
00391     zdscal_(n, &d__3, &v[1], &c__1);
00392 
00393     return 0;
00394 
00395 /*     End of ZLAEIN */
00396 
00397 } /* zlaein_ */


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