zlahqr.c
Go to the documentation of this file.
00001 /* zlahqr.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 integer c__2 = 2;
00020 
00021 /* Subroutine */ int zlahqr_(logical *wantt, logical *wantz, integer *n, 
00022         integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh, 
00023         doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__, 
00024         integer *ldz, integer *info)
00025 {
00026     /* System generated locals */
00027     integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
00028     doublereal d__1, d__2, d__3, d__4, d__5, d__6;
00029     doublecomplex z__1, z__2, z__3, z__4, z__5, z__6, z__7;
00030 
00031     /* Builtin functions */
00032     double d_imag(doublecomplex *);
00033     void d_cnjg(doublecomplex *, doublecomplex *);
00034     double z_abs(doublecomplex *);
00035     void z_sqrt(doublecomplex *, doublecomplex *), pow_zi(doublecomplex *, 
00036             doublecomplex *, integer *);
00037 
00038     /* Local variables */
00039     integer i__, j, k, l, m;
00040     doublereal s;
00041     doublecomplex t, u, v[2], x, y;
00042     integer i1, i2;
00043     doublecomplex t1;
00044     doublereal t2;
00045     doublecomplex v2;
00046     doublereal aa, ab, ba, bb, h10;
00047     doublecomplex h11;
00048     doublereal h21;
00049     doublecomplex h22, sc;
00050     integer nh, nz;
00051     doublereal sx;
00052     integer jhi;
00053     doublecomplex h11s;
00054     integer jlo, its;
00055     doublereal ulp;
00056     doublecomplex sum;
00057     doublereal tst;
00058     doublecomplex temp;
00059     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
00060             doublecomplex *, integer *);
00061     doublereal rtemp;
00062     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
00063             doublecomplex *, integer *), dlabad_(doublereal *, doublereal *);
00064     extern doublereal dlamch_(char *);
00065     doublereal safmin, safmax;
00066     extern /* Subroutine */ int zlarfg_(integer *, doublecomplex *, 
00067             doublecomplex *, integer *, doublecomplex *);
00068     extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *, 
00069              doublecomplex *);
00070     doublereal smlnum;
00071 
00072 
00073 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00074 /*     Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. */
00075 /*     November 2006 */
00076 
00077 /*     .. Scalar Arguments .. */
00078 /*     .. */
00079 /*     .. Array Arguments .. */
00080 /*     .. */
00081 
00082 /*     Purpose */
00083 /*     ======= */
00084 
00085 /*     ZLAHQR is an auxiliary routine called by CHSEQR to update the */
00086 /*     eigenvalues and Schur decomposition already computed by CHSEQR, by */
00087 /*     dealing with the Hessenberg submatrix in rows and columns ILO to */
00088 /*     IHI. */
00089 
00090 /*     Arguments */
00091 /*     ========= */
00092 
00093 /*     WANTT   (input) LOGICAL */
00094 /*          = .TRUE. : the full Schur form T is required; */
00095 /*          = .FALSE.: only eigenvalues are required. */
00096 
00097 /*     WANTZ   (input) LOGICAL */
00098 /*          = .TRUE. : the matrix of Schur vectors Z is required; */
00099 /*          = .FALSE.: Schur vectors are not required. */
00100 
00101 /*     N       (input) INTEGER */
00102 /*          The order of the matrix H.  N >= 0. */
00103 
00104 /*     ILO     (input) INTEGER */
00105 /*     IHI     (input) INTEGER */
00106 /*          It is assumed that H is already upper triangular in rows and */
00107 /*          columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless ILO = 1). */
00108 /*          ZLAHQR works primarily with the Hessenberg submatrix in rows */
00109 /*          and columns ILO to IHI, but applies transformations to all of */
00110 /*          H if WANTT is .TRUE.. */
00111 /*          1 <= ILO <= max(1,IHI); IHI <= N. */
00112 
00113 /*     H       (input/output) COMPLEX*16 array, dimension (LDH,N) */
00114 /*          On entry, the upper Hessenberg matrix H. */
00115 /*          On exit, if INFO is zero and if WANTT is .TRUE., then H */
00116 /*          is upper triangular in rows and columns ILO:IHI.  If INFO */
00117 /*          is zero and if WANTT is .FALSE., then the contents of H */
00118 /*          are unspecified on exit.  The output state of H in case */
00119 /*          INF is positive is below under the description of INFO. */
00120 
00121 /*     LDH     (input) INTEGER */
00122 /*          The leading dimension of the array H. LDH >= max(1,N). */
00123 
00124 /*     W       (output) COMPLEX*16 array, dimension (N) */
00125 /*          The computed eigenvalues ILO to IHI are stored in the */
00126 /*          corresponding elements of W. If WANTT is .TRUE., the */
00127 /*          eigenvalues are stored in the same order as on the diagonal */
00128 /*          of the Schur form returned in H, with W(i) = H(i,i). */
00129 
00130 /*     ILOZ    (input) INTEGER */
00131 /*     IHIZ    (input) INTEGER */
00132 /*          Specify the rows of Z to which transformations must be */
00133 /*          applied if WANTZ is .TRUE.. */
00134 /*          1 <= ILOZ <= ILO; IHI <= IHIZ <= N. */
00135 
00136 /*     Z       (input/output) COMPLEX*16 array, dimension (LDZ,N) */
00137 /*          If WANTZ is .TRUE., on entry Z must contain the current */
00138 /*          matrix Z of transformations accumulated by CHSEQR, and on */
00139 /*          exit Z has been updated; transformations are applied only to */
00140 /*          the submatrix Z(ILOZ:IHIZ,ILO:IHI). */
00141 /*          If WANTZ is .FALSE., Z is not referenced. */
00142 
00143 /*     LDZ     (input) INTEGER */
00144 /*          The leading dimension of the array Z. LDZ >= max(1,N). */
00145 
00146 /*     INFO    (output) INTEGER */
00147 /*           =   0: successful exit */
00148 /*          .GT. 0: if INFO = i, ZLAHQR failed to compute all the */
00149 /*                  eigenvalues ILO to IHI in a total of 30 iterations */
00150 /*                  per eigenvalue; elements i+1:ihi of W contain */
00151 /*                  those eigenvalues which have been successfully */
00152 /*                  computed. */
00153 
00154 /*                  If INFO .GT. 0 and WANTT is .FALSE., then on exit, */
00155 /*                  the remaining unconverged eigenvalues are the */
00156 /*                  eigenvalues of the upper Hessenberg matrix */
00157 /*                  rows and columns ILO thorugh INFO of the final, */
00158 /*                  output value of H. */
00159 
00160 /*                  If INFO .GT. 0 and WANTT is .TRUE., then on exit */
00161 /*          (*)       (initial value of H)*U  = U*(final value of H) */
00162 /*                  where U is an orthognal matrix.    The final */
00163 /*                  value of H is upper Hessenberg and triangular in */
00164 /*                  rows and columns INFO+1 through IHI. */
00165 
00166 /*                  If INFO .GT. 0 and WANTZ is .TRUE., then on exit */
00167 /*                      (final value of Z)  = (initial value of Z)*U */
00168 /*                  where U is the orthogonal matrix in (*) */
00169 /*                  (regardless of the value of WANTT.) */
00170 
00171 /*     Further Details */
00172 /*     =============== */
00173 
00174 /*     02-96 Based on modifications by */
00175 /*     David Day, Sandia National Laboratory, USA */
00176 
00177 /*     12-04 Further modifications by */
00178 /*     Ralph Byers, University of Kansas, USA */
00179 /*     This is a modified version of ZLAHQR from LAPACK version 3.0. */
00180 /*     It is (1) more robust against overflow and underflow and */
00181 /*     (2) adopts the more conservative Ahues & Tisseur stopping */
00182 /*     criterion (LAWN 122, 1997). */
00183 
00184 /*     ========================================================= */
00185 
00186 /*     .. Parameters .. */
00187 /*     .. */
00188 /*     .. Local Scalars .. */
00189 /*     .. */
00190 /*     .. Local Arrays .. */
00191 /*     .. */
00192 /*     .. External Functions .. */
00193 /*     .. */
00194 /*     .. External Subroutines .. */
00195 /*     .. */
00196 /*     .. Statement Functions .. */
00197 /*     .. */
00198 /*     .. Intrinsic Functions .. */
00199 /*     .. */
00200 /*     .. Statement Function definitions .. */
00201 /*     .. */
00202 /*     .. Executable Statements .. */
00203 
00204     /* Parameter adjustments */
00205     h_dim1 = *ldh;
00206     h_offset = 1 + h_dim1;
00207     h__ -= h_offset;
00208     --w;
00209     z_dim1 = *ldz;
00210     z_offset = 1 + z_dim1;
00211     z__ -= z_offset;
00212 
00213     /* Function Body */
00214     *info = 0;
00215 
00216 /*     Quick return if possible */
00217 
00218     if (*n == 0) {
00219         return 0;
00220     }
00221     if (*ilo == *ihi) {
00222         i__1 = *ilo;
00223         i__2 = *ilo + *ilo * h_dim1;
00224         w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
00225         return 0;
00226     }
00227 
00228 /*     ==== clear out the trash ==== */
00229     i__1 = *ihi - 3;
00230     for (j = *ilo; j <= i__1; ++j) {
00231         i__2 = j + 2 + j * h_dim1;
00232         h__[i__2].r = 0., h__[i__2].i = 0.;
00233         i__2 = j + 3 + j * h_dim1;
00234         h__[i__2].r = 0., h__[i__2].i = 0.;
00235 /* L10: */
00236     }
00237     if (*ilo <= *ihi - 2) {
00238         i__1 = *ihi + (*ihi - 2) * h_dim1;
00239         h__[i__1].r = 0., h__[i__1].i = 0.;
00240     }
00241 /*     ==== ensure that subdiagonal entries are real ==== */
00242     if (*wantt) {
00243         jlo = 1;
00244         jhi = *n;
00245     } else {
00246         jlo = *ilo;
00247         jhi = *ihi;
00248     }
00249     i__1 = *ihi;
00250     for (i__ = *ilo + 1; i__ <= i__1; ++i__) {
00251         if (d_imag(&h__[i__ + (i__ - 1) * h_dim1]) != 0.) {
00252 /*           ==== The following redundant normalization */
00253 /*           .    avoids problems with both gradual and */
00254 /*           .    sudden underflow in ABS(H(I,I-1)) ==== */
00255             i__2 = i__ + (i__ - 1) * h_dim1;
00256             i__3 = i__ + (i__ - 1) * h_dim1;
00257             d__3 = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[i__ 
00258                     + (i__ - 1) * h_dim1]), abs(d__2));
00259             z__1.r = h__[i__2].r / d__3, z__1.i = h__[i__2].i / d__3;
00260             sc.r = z__1.r, sc.i = z__1.i;
00261             d_cnjg(&z__2, &sc);
00262             d__1 = z_abs(&sc);
00263             z__1.r = z__2.r / d__1, z__1.i = z__2.i / d__1;
00264             sc.r = z__1.r, sc.i = z__1.i;
00265             i__2 = i__ + (i__ - 1) * h_dim1;
00266             d__1 = z_abs(&h__[i__ + (i__ - 1) * h_dim1]);
00267             h__[i__2].r = d__1, h__[i__2].i = 0.;
00268             i__2 = jhi - i__ + 1;
00269             zscal_(&i__2, &sc, &h__[i__ + i__ * h_dim1], ldh);
00270 /* Computing MIN */
00271             i__3 = jhi, i__4 = i__ + 1;
00272             i__2 = min(i__3,i__4) - jlo + 1;
00273             d_cnjg(&z__1, &sc);
00274             zscal_(&i__2, &z__1, &h__[jlo + i__ * h_dim1], &c__1);
00275             if (*wantz) {
00276                 i__2 = *ihiz - *iloz + 1;
00277                 d_cnjg(&z__1, &sc);
00278                 zscal_(&i__2, &z__1, &z__[*iloz + i__ * z_dim1], &c__1);
00279             }
00280         }
00281 /* L20: */
00282     }
00283 
00284     nh = *ihi - *ilo + 1;
00285     nz = *ihiz - *iloz + 1;
00286 
00287 /*     Set machine-dependent constants for the stopping criterion. */
00288 
00289     safmin = dlamch_("SAFE MINIMUM");
00290     safmax = 1. / safmin;
00291     dlabad_(&safmin, &safmax);
00292     ulp = dlamch_("PRECISION");
00293     smlnum = safmin * ((doublereal) nh / ulp);
00294 
00295 /*     I1 and I2 are the indices of the first row and last column of H */
00296 /*     to which transformations must be applied. If eigenvalues only are */
00297 /*     being computed, I1 and I2 are set inside the main loop. */
00298 
00299     if (*wantt) {
00300         i1 = 1;
00301         i2 = *n;
00302     }
00303 
00304 /*     The main loop begins here. I is the loop index and decreases from */
00305 /*     IHI to ILO in steps of 1. Each iteration of the loop works */
00306 /*     with the active submatrix in rows and columns L to I. */
00307 /*     Eigenvalues I+1 to IHI have already converged. Either L = ILO, or */
00308 /*     H(L,L-1) is negligible so that the matrix splits. */
00309 
00310     i__ = *ihi;
00311 L30:
00312     if (i__ < *ilo) {
00313         goto L150;
00314     }
00315 
00316 /*     Perform QR iterations on rows and columns ILO to I until a */
00317 /*     submatrix of order 1 splits off at the bottom because a */
00318 /*     subdiagonal element has become negligible. */
00319 
00320     l = *ilo;
00321     for (its = 0; its <= 30; ++its) {
00322 
00323 /*        Look for a single small subdiagonal element. */
00324 
00325         i__1 = l + 1;
00326         for (k = i__; k >= i__1; --k) {
00327             i__2 = k + (k - 1) * h_dim1;
00328             if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[k + (k 
00329                     - 1) * h_dim1]), abs(d__2)) <= smlnum) {
00330                 goto L50;
00331             }
00332             i__2 = k - 1 + (k - 1) * h_dim1;
00333             i__3 = k + k * h_dim1;
00334             tst = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[k - 1 
00335                     + (k - 1) * h_dim1]), abs(d__2)) + ((d__3 = h__[i__3].r, 
00336                     abs(d__3)) + (d__4 = d_imag(&h__[k + k * h_dim1]), abs(
00337                     d__4)));
00338             if (tst == 0.) {
00339                 if (k - 2 >= *ilo) {
00340                     i__2 = k - 1 + (k - 2) * h_dim1;
00341                     tst += (d__1 = h__[i__2].r, abs(d__1));
00342                 }
00343                 if (k + 1 <= *ihi) {
00344                     i__2 = k + 1 + k * h_dim1;
00345                     tst += (d__1 = h__[i__2].r, abs(d__1));
00346                 }
00347             }
00348 /*           ==== The following is a conservative small subdiagonal */
00349 /*           .    deflation criterion due to Ahues & Tisseur (LAWN 122, */
00350 /*           .    1997). It has better mathematical foundation and */
00351 /*           .    improves accuracy in some examples.  ==== */
00352             i__2 = k + (k - 1) * h_dim1;
00353             if ((d__1 = h__[i__2].r, abs(d__1)) <= ulp * tst) {
00354 /* Computing MAX */
00355                 i__2 = k + (k - 1) * h_dim1;
00356                 i__3 = k - 1 + k * h_dim1;
00357                 d__5 = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
00358                         k + (k - 1) * h_dim1]), abs(d__2)), d__6 = (d__3 = 
00359                         h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&h__[k - 1 + 
00360                         k * h_dim1]), abs(d__4));
00361                 ab = max(d__5,d__6);
00362 /* Computing MIN */
00363                 i__2 = k + (k - 1) * h_dim1;
00364                 i__3 = k - 1 + k * h_dim1;
00365                 d__5 = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
00366                         k + (k - 1) * h_dim1]), abs(d__2)), d__6 = (d__3 = 
00367                         h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&h__[k - 1 + 
00368                         k * h_dim1]), abs(d__4));
00369                 ba = min(d__5,d__6);
00370                 i__2 = k - 1 + (k - 1) * h_dim1;
00371                 i__3 = k + k * h_dim1;
00372                 z__2.r = h__[i__2].r - h__[i__3].r, z__2.i = h__[i__2].i - 
00373                         h__[i__3].i;
00374                 z__1.r = z__2.r, z__1.i = z__2.i;
00375 /* Computing MAX */
00376                 i__4 = k + k * h_dim1;
00377                 d__5 = (d__1 = h__[i__4].r, abs(d__1)) + (d__2 = d_imag(&h__[
00378                         k + k * h_dim1]), abs(d__2)), d__6 = (d__3 = z__1.r, 
00379                         abs(d__3)) + (d__4 = d_imag(&z__1), abs(d__4));
00380                 aa = max(d__5,d__6);
00381                 i__2 = k - 1 + (k - 1) * h_dim1;
00382                 i__3 = k + k * h_dim1;
00383                 z__2.r = h__[i__2].r - h__[i__3].r, z__2.i = h__[i__2].i - 
00384                         h__[i__3].i;
00385                 z__1.r = z__2.r, z__1.i = z__2.i;
00386 /* Computing MIN */
00387                 i__4 = k + k * h_dim1;
00388                 d__5 = (d__1 = h__[i__4].r, abs(d__1)) + (d__2 = d_imag(&h__[
00389                         k + k * h_dim1]), abs(d__2)), d__6 = (d__3 = z__1.r, 
00390                         abs(d__3)) + (d__4 = d_imag(&z__1), abs(d__4));
00391                 bb = min(d__5,d__6);
00392                 s = aa + ab;
00393 /* Computing MAX */
00394                 d__1 = smlnum, d__2 = ulp * (bb * (aa / s));
00395                 if (ba * (ab / s) <= max(d__1,d__2)) {
00396                     goto L50;
00397                 }
00398             }
00399 /* L40: */
00400         }
00401 L50:
00402         l = k;
00403         if (l > *ilo) {
00404 
00405 /*           H(L,L-1) is negligible */
00406 
00407             i__1 = l + (l - 1) * h_dim1;
00408             h__[i__1].r = 0., h__[i__1].i = 0.;
00409         }
00410 
00411 /*        Exit from loop if a submatrix of order 1 has split off. */
00412 
00413         if (l >= i__) {
00414             goto L140;
00415         }
00416 
00417 /*        Now the active submatrix is in rows and columns L to I. If */
00418 /*        eigenvalues only are being computed, only the active submatrix */
00419 /*        need be transformed. */
00420 
00421         if (! (*wantt)) {
00422             i1 = l;
00423             i2 = i__;
00424         }
00425 
00426         if (its == 10) {
00427 
00428 /*           Exceptional shift. */
00429 
00430             i__1 = l + 1 + l * h_dim1;
00431             s = (d__1 = h__[i__1].r, abs(d__1)) * .75;
00432             i__1 = l + l * h_dim1;
00433             z__1.r = s + h__[i__1].r, z__1.i = h__[i__1].i;
00434             t.r = z__1.r, t.i = z__1.i;
00435         } else if (its == 20) {
00436 
00437 /*           Exceptional shift. */
00438 
00439             i__1 = i__ + (i__ - 1) * h_dim1;
00440             s = (d__1 = h__[i__1].r, abs(d__1)) * .75;
00441             i__1 = i__ + i__ * h_dim1;
00442             z__1.r = s + h__[i__1].r, z__1.i = h__[i__1].i;
00443             t.r = z__1.r, t.i = z__1.i;
00444         } else {
00445 
00446 /*           Wilkinson's shift. */
00447 
00448             i__1 = i__ + i__ * h_dim1;
00449             t.r = h__[i__1].r, t.i = h__[i__1].i;
00450             z_sqrt(&z__2, &h__[i__ - 1 + i__ * h_dim1]);
00451             z_sqrt(&z__3, &h__[i__ + (i__ - 1) * h_dim1]);
00452             z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r * 
00453                     z__3.i + z__2.i * z__3.r;
00454             u.r = z__1.r, u.i = z__1.i;
00455             s = (d__1 = u.r, abs(d__1)) + (d__2 = d_imag(&u), abs(d__2));
00456             if (s != 0.) {
00457                 i__1 = i__ - 1 + (i__ - 1) * h_dim1;
00458                 z__2.r = h__[i__1].r - t.r, z__2.i = h__[i__1].i - t.i;
00459                 z__1.r = z__2.r * .5, z__1.i = z__2.i * .5;
00460                 x.r = z__1.r, x.i = z__1.i;
00461                 sx = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x), abs(d__2));
00462 /* Computing MAX */
00463                 d__3 = s, d__4 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x),
00464                          abs(d__2));
00465                 s = max(d__3,d__4);
00466                 z__5.r = x.r / s, z__5.i = x.i / s;
00467                 pow_zi(&z__4, &z__5, &c__2);
00468                 z__7.r = u.r / s, z__7.i = u.i / s;
00469                 pow_zi(&z__6, &z__7, &c__2);
00470                 z__3.r = z__4.r + z__6.r, z__3.i = z__4.i + z__6.i;
00471                 z_sqrt(&z__2, &z__3);
00472                 z__1.r = s * z__2.r, z__1.i = s * z__2.i;
00473                 y.r = z__1.r, y.i = z__1.i;
00474                 if (sx > 0.) {
00475                     z__1.r = x.r / sx, z__1.i = x.i / sx;
00476                     z__2.r = x.r / sx, z__2.i = x.i / sx;
00477                     if (z__1.r * y.r + d_imag(&z__2) * d_imag(&y) < 0.) {
00478                         z__3.r = -y.r, z__3.i = -y.i;
00479                         y.r = z__3.r, y.i = z__3.i;
00480                     }
00481                 }
00482                 z__4.r = x.r + y.r, z__4.i = x.i + y.i;
00483                 zladiv_(&z__3, &u, &z__4);
00484                 z__2.r = u.r * z__3.r - u.i * z__3.i, z__2.i = u.r * z__3.i + 
00485                         u.i * z__3.r;
00486                 z__1.r = t.r - z__2.r, z__1.i = t.i - z__2.i;
00487                 t.r = z__1.r, t.i = z__1.i;
00488             }
00489         }
00490 
00491 /*        Look for two consecutive small subdiagonal elements. */
00492 
00493         i__1 = l + 1;
00494         for (m = i__ - 1; m >= i__1; --m) {
00495 
00496 /*           Determine the effect of starting the single-shift QR */
00497 /*           iteration at row M, and see if this would make H(M,M-1) */
00498 /*           negligible. */
00499 
00500             i__2 = m + m * h_dim1;
00501             h11.r = h__[i__2].r, h11.i = h__[i__2].i;
00502             i__2 = m + 1 + (m + 1) * h_dim1;
00503             h22.r = h__[i__2].r, h22.i = h__[i__2].i;
00504             z__1.r = h11.r - t.r, z__1.i = h11.i - t.i;
00505             h11s.r = z__1.r, h11s.i = z__1.i;
00506             i__2 = m + 1 + m * h_dim1;
00507             h21 = h__[i__2].r;
00508             s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2))
00509                      + abs(h21);
00510             z__1.r = h11s.r / s, z__1.i = h11s.i / s;
00511             h11s.r = z__1.r, h11s.i = z__1.i;
00512             h21 /= s;
00513             v[0].r = h11s.r, v[0].i = h11s.i;
00514             v[1].r = h21, v[1].i = 0.;
00515             i__2 = m + (m - 1) * h_dim1;
00516             h10 = h__[i__2].r;
00517             if (abs(h10) * abs(h21) <= ulp * (((d__1 = h11s.r, abs(d__1)) + (
00518                     d__2 = d_imag(&h11s), abs(d__2))) * ((d__3 = h11.r, abs(
00519                     d__3)) + (d__4 = d_imag(&h11), abs(d__4)) + ((d__5 = 
00520                     h22.r, abs(d__5)) + (d__6 = d_imag(&h22), abs(d__6)))))) {
00521                 goto L70;
00522             }
00523 /* L60: */
00524         }
00525         i__1 = l + l * h_dim1;
00526         h11.r = h__[i__1].r, h11.i = h__[i__1].i;
00527         i__1 = l + 1 + (l + 1) * h_dim1;
00528         h22.r = h__[i__1].r, h22.i = h__[i__1].i;
00529         z__1.r = h11.r - t.r, z__1.i = h11.i - t.i;
00530         h11s.r = z__1.r, h11s.i = z__1.i;
00531         i__1 = l + 1 + l * h_dim1;
00532         h21 = h__[i__1].r;
00533         s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2)) + 
00534                 abs(h21);
00535         z__1.r = h11s.r / s, z__1.i = h11s.i / s;
00536         h11s.r = z__1.r, h11s.i = z__1.i;
00537         h21 /= s;
00538         v[0].r = h11s.r, v[0].i = h11s.i;
00539         v[1].r = h21, v[1].i = 0.;
00540 L70:
00541 
00542 /*        Single-shift QR step */
00543 
00544         i__1 = i__ - 1;
00545         for (k = m; k <= i__1; ++k) {
00546 
00547 /*           The first iteration of this loop determines a reflection G */
00548 /*           from the vector V and applies it from left and right to H, */
00549 /*           thus creating a nonzero bulge below the subdiagonal. */
00550 
00551 /*           Each subsequent iteration determines a reflection G to */
00552 /*           restore the Hessenberg form in the (K-1)th column, and thus */
00553 /*           chases the bulge one step toward the bottom of the active */
00554 /*           submatrix. */
00555 
00556 /*           V(2) is always real before the call to ZLARFG, and hence */
00557 /*           after the call T2 ( = T1*V(2) ) is also real. */
00558 
00559             if (k > m) {
00560                 zcopy_(&c__2, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
00561             }
00562             zlarfg_(&c__2, v, &v[1], &c__1, &t1);
00563             if (k > m) {
00564                 i__2 = k + (k - 1) * h_dim1;
00565                 h__[i__2].r = v[0].r, h__[i__2].i = v[0].i;
00566                 i__2 = k + 1 + (k - 1) * h_dim1;
00567                 h__[i__2].r = 0., h__[i__2].i = 0.;
00568             }
00569             v2.r = v[1].r, v2.i = v[1].i;
00570             z__1.r = t1.r * v2.r - t1.i * v2.i, z__1.i = t1.r * v2.i + t1.i * 
00571                     v2.r;
00572             t2 = z__1.r;
00573 
00574 /*           Apply G from the left to transform the rows of the matrix */
00575 /*           in columns K to I2. */
00576 
00577             i__2 = i2;
00578             for (j = k; j <= i__2; ++j) {
00579                 d_cnjg(&z__3, &t1);
00580                 i__3 = k + j * h_dim1;
00581                 z__2.r = z__3.r * h__[i__3].r - z__3.i * h__[i__3].i, z__2.i =
00582                          z__3.r * h__[i__3].i + z__3.i * h__[i__3].r;
00583                 i__4 = k + 1 + j * h_dim1;
00584                 z__4.r = t2 * h__[i__4].r, z__4.i = t2 * h__[i__4].i;
00585                 z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
00586                 sum.r = z__1.r, sum.i = z__1.i;
00587                 i__3 = k + j * h_dim1;
00588                 i__4 = k + j * h_dim1;
00589                 z__1.r = h__[i__4].r - sum.r, z__1.i = h__[i__4].i - sum.i;
00590                 h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
00591                 i__3 = k + 1 + j * h_dim1;
00592                 i__4 = k + 1 + j * h_dim1;
00593                 z__2.r = sum.r * v2.r - sum.i * v2.i, z__2.i = sum.r * v2.i + 
00594                         sum.i * v2.r;
00595                 z__1.r = h__[i__4].r - z__2.r, z__1.i = h__[i__4].i - z__2.i;
00596                 h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
00597 /* L80: */
00598             }
00599 
00600 /*           Apply G from the right to transform the columns of the */
00601 /*           matrix in rows I1 to min(K+2,I). */
00602 
00603 /* Computing MIN */
00604             i__3 = k + 2;
00605             i__2 = min(i__3,i__);
00606             for (j = i1; j <= i__2; ++j) {
00607                 i__3 = j + k * h_dim1;
00608                 z__2.r = t1.r * h__[i__3].r - t1.i * h__[i__3].i, z__2.i = 
00609                         t1.r * h__[i__3].i + t1.i * h__[i__3].r;
00610                 i__4 = j + (k + 1) * h_dim1;
00611                 z__3.r = t2 * h__[i__4].r, z__3.i = t2 * h__[i__4].i;
00612                 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
00613                 sum.r = z__1.r, sum.i = z__1.i;
00614                 i__3 = j + k * h_dim1;
00615                 i__4 = j + k * h_dim1;
00616                 z__1.r = h__[i__4].r - sum.r, z__1.i = h__[i__4].i - sum.i;
00617                 h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
00618                 i__3 = j + (k + 1) * h_dim1;
00619                 i__4 = j + (k + 1) * h_dim1;
00620                 d_cnjg(&z__3, &v2);
00621                 z__2.r = sum.r * z__3.r - sum.i * z__3.i, z__2.i = sum.r * 
00622                         z__3.i + sum.i * z__3.r;
00623                 z__1.r = h__[i__4].r - z__2.r, z__1.i = h__[i__4].i - z__2.i;
00624                 h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
00625 /* L90: */
00626             }
00627 
00628             if (*wantz) {
00629 
00630 /*              Accumulate transformations in the matrix Z */
00631 
00632                 i__2 = *ihiz;
00633                 for (j = *iloz; j <= i__2; ++j) {
00634                     i__3 = j + k * z_dim1;
00635                     z__2.r = t1.r * z__[i__3].r - t1.i * z__[i__3].i, z__2.i =
00636                              t1.r * z__[i__3].i + t1.i * z__[i__3].r;
00637                     i__4 = j + (k + 1) * z_dim1;
00638                     z__3.r = t2 * z__[i__4].r, z__3.i = t2 * z__[i__4].i;
00639                     z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
00640                     sum.r = z__1.r, sum.i = z__1.i;
00641                     i__3 = j + k * z_dim1;
00642                     i__4 = j + k * z_dim1;
00643                     z__1.r = z__[i__4].r - sum.r, z__1.i = z__[i__4].i - 
00644                             sum.i;
00645                     z__[i__3].r = z__1.r, z__[i__3].i = z__1.i;
00646                     i__3 = j + (k + 1) * z_dim1;
00647                     i__4 = j + (k + 1) * z_dim1;
00648                     d_cnjg(&z__3, &v2);
00649                     z__2.r = sum.r * z__3.r - sum.i * z__3.i, z__2.i = sum.r *
00650                              z__3.i + sum.i * z__3.r;
00651                     z__1.r = z__[i__4].r - z__2.r, z__1.i = z__[i__4].i - 
00652                             z__2.i;
00653                     z__[i__3].r = z__1.r, z__[i__3].i = z__1.i;
00654 /* L100: */
00655                 }
00656             }
00657 
00658             if (k == m && m > l) {
00659 
00660 /*              If the QR step was started at row M > L because two */
00661 /*              consecutive small subdiagonals were found, then extra */
00662 /*              scaling must be performed to ensure that H(M,M-1) remains */
00663 /*              real. */
00664 
00665                 z__1.r = 1. - t1.r, z__1.i = 0. - t1.i;
00666                 temp.r = z__1.r, temp.i = z__1.i;
00667                 d__1 = z_abs(&temp);
00668                 z__1.r = temp.r / d__1, z__1.i = temp.i / d__1;
00669                 temp.r = z__1.r, temp.i = z__1.i;
00670                 i__2 = m + 1 + m * h_dim1;
00671                 i__3 = m + 1 + m * h_dim1;
00672                 d_cnjg(&z__2, &temp);
00673                 z__1.r = h__[i__3].r * z__2.r - h__[i__3].i * z__2.i, z__1.i =
00674                          h__[i__3].r * z__2.i + h__[i__3].i * z__2.r;
00675                 h__[i__2].r = z__1.r, h__[i__2].i = z__1.i;
00676                 if (m + 2 <= i__) {
00677                     i__2 = m + 2 + (m + 1) * h_dim1;
00678                     i__3 = m + 2 + (m + 1) * h_dim1;
00679                     z__1.r = h__[i__3].r * temp.r - h__[i__3].i * temp.i, 
00680                             z__1.i = h__[i__3].r * temp.i + h__[i__3].i * 
00681                             temp.r;
00682                     h__[i__2].r = z__1.r, h__[i__2].i = z__1.i;
00683                 }
00684                 i__2 = i__;
00685                 for (j = m; j <= i__2; ++j) {
00686                     if (j != m + 1) {
00687                         if (i2 > j) {
00688                             i__3 = i2 - j;
00689                             zscal_(&i__3, &temp, &h__[j + (j + 1) * h_dim1], 
00690                                     ldh);
00691                         }
00692                         i__3 = j - i1;
00693                         d_cnjg(&z__1, &temp);
00694                         zscal_(&i__3, &z__1, &h__[i1 + j * h_dim1], &c__1);
00695                         if (*wantz) {
00696                             d_cnjg(&z__1, &temp);
00697                             zscal_(&nz, &z__1, &z__[*iloz + j * z_dim1], &
00698                                     c__1);
00699                         }
00700                     }
00701 /* L110: */
00702                 }
00703             }
00704 /* L120: */
00705         }
00706 
00707 /*        Ensure that H(I,I-1) is real. */
00708 
00709         i__1 = i__ + (i__ - 1) * h_dim1;
00710         temp.r = h__[i__1].r, temp.i = h__[i__1].i;
00711         if (d_imag(&temp) != 0.) {
00712             rtemp = z_abs(&temp);
00713             i__1 = i__ + (i__ - 1) * h_dim1;
00714             h__[i__1].r = rtemp, h__[i__1].i = 0.;
00715             z__1.r = temp.r / rtemp, z__1.i = temp.i / rtemp;
00716             temp.r = z__1.r, temp.i = z__1.i;
00717             if (i2 > i__) {
00718                 i__1 = i2 - i__;
00719                 d_cnjg(&z__1, &temp);
00720                 zscal_(&i__1, &z__1, &h__[i__ + (i__ + 1) * h_dim1], ldh);
00721             }
00722             i__1 = i__ - i1;
00723             zscal_(&i__1, &temp, &h__[i1 + i__ * h_dim1], &c__1);
00724             if (*wantz) {
00725                 zscal_(&nz, &temp, &z__[*iloz + i__ * z_dim1], &c__1);
00726             }
00727         }
00728 
00729 /* L130: */
00730     }
00731 
00732 /*     Failure to converge in remaining number of iterations */
00733 
00734     *info = i__;
00735     return 0;
00736 
00737 L140:
00738 
00739 /*     H(I,I-1) is negligible: one eigenvalue has converged. */
00740 
00741     i__1 = i__;
00742     i__2 = i__ + i__ * h_dim1;
00743     w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
00744 
00745 /*     return to start of the main loop with new value of I. */
00746 
00747     i__ = l - 1;
00748     goto L30;
00749 
00750 L150:
00751     return 0;
00752 
00753 /*     End of ZLAHQR */
00754 
00755 } /* zlahqr_ */


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