dgeevx.c
Go to the documentation of this file.
00001 /* dgeevx.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__0 = 0;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int dgeevx_(char *balanc, char *jobvl, char *jobvr, char *
00023         sense, integer *n, doublereal *a, integer *lda, doublereal *wr, 
00024         doublereal *wi, doublereal *vl, integer *ldvl, doublereal *vr, 
00025         integer *ldvr, integer *ilo, integer *ihi, doublereal *scale, 
00026         doublereal *abnrm, doublereal *rconde, doublereal *rcondv, doublereal 
00027         *work, integer *lwork, integer *iwork, integer *info)
00028 {
00029     /* System generated locals */
00030     integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1, 
00031             i__2, i__3;
00032     doublereal d__1, d__2;
00033 
00034     /* Builtin functions */
00035     double sqrt(doublereal);
00036 
00037     /* Local variables */
00038     integer i__, k;
00039     doublereal r__, cs, sn;
00040     char job[1];
00041     doublereal scl, dum[1], eps;
00042     char side[1];
00043     doublereal anrm;
00044     integer ierr, itau;
00045     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *, 
00046             doublereal *, integer *, doublereal *, doublereal *);
00047     integer iwrk, nout;
00048     extern doublereal dnrm2_(integer *, doublereal *, integer *);
00049     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00050             integer *);
00051     integer icond;
00052     extern logical lsame_(char *, char *);
00053     extern doublereal dlapy2_(doublereal *, doublereal *);
00054     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *), dgebak_(
00055             char *, char *, integer *, integer *, integer *, doublereal *, 
00056             integer *, doublereal *, integer *, integer *), 
00057             dgebal_(char *, integer *, doublereal *, integer *, integer *, 
00058             integer *, doublereal *, integer *);
00059     logical scalea;
00060     extern doublereal dlamch_(char *);
00061     doublereal cscale;
00062     extern doublereal dlange_(char *, integer *, integer *, doublereal *, 
00063             integer *, doublereal *);
00064     extern /* Subroutine */ int dgehrd_(integer *, integer *, integer *, 
00065             doublereal *, integer *, doublereal *, doublereal *, integer *, 
00066             integer *), dlascl_(char *, integer *, integer *, doublereal *, 
00067             doublereal *, integer *, integer *, doublereal *, integer *, 
00068             integer *);
00069     extern integer idamax_(integer *, doublereal *, integer *);
00070     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, 
00071             doublereal *, integer *, doublereal *, integer *), 
00072             dlartg_(doublereal *, doublereal *, doublereal *, doublereal *, 
00073             doublereal *), xerbla_(char *, integer *);
00074     logical select[1];
00075     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00076             integer *, integer *);
00077     doublereal bignum;
00078     extern /* Subroutine */ int dorghr_(integer *, integer *, integer *, 
00079             doublereal *, integer *, doublereal *, doublereal *, integer *, 
00080             integer *), dhseqr_(char *, char *, integer *, integer *, integer 
00081             *, doublereal *, integer *, doublereal *, doublereal *, 
00082             doublereal *, integer *, doublereal *, integer *, integer *), dtrevc_(char *, char *, logical *, integer *, 
00083             doublereal *, integer *, doublereal *, integer *, doublereal *, 
00084             integer *, integer *, integer *, doublereal *, integer *), dtrsna_(char *, char *, logical *, integer *, doublereal 
00085             *, integer *, doublereal *, integer *, doublereal *, integer *, 
00086             doublereal *, doublereal *, integer *, integer *, doublereal *, 
00087             integer *, integer *, integer *);
00088     integer minwrk, maxwrk;
00089     logical wantvl, wntsnb;
00090     integer hswork;
00091     logical wntsne;
00092     doublereal smlnum;
00093     logical lquery, wantvr, wntsnn, wntsnv;
00094 
00095 
00096 /*  -- LAPACK driver routine (version 3.2) -- */
00097 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00098 /*     November 2006 */
00099 
00100 /*     .. Scalar Arguments .. */
00101 /*     .. */
00102 /*     .. Array Arguments .. */
00103 /*     .. */
00104 
00105 /*  Purpose */
00106 /*  ======= */
00107 
00108 /*  DGEEVX computes for an N-by-N real nonsymmetric matrix A, the */
00109 /*  eigenvalues and, optionally, the left and/or right eigenvectors. */
00110 
00111 /*  Optionally also, it computes a balancing transformation to improve */
00112 /*  the conditioning of the eigenvalues and eigenvectors (ILO, IHI, */
00113 /*  SCALE, and ABNRM), reciprocal condition numbers for the eigenvalues */
00114 /*  (RCONDE), and reciprocal condition numbers for the right */
00115 /*  eigenvectors (RCONDV). */
00116 
00117 /*  The right eigenvector v(j) of A satisfies */
00118 /*                   A * v(j) = lambda(j) * v(j) */
00119 /*  where lambda(j) is its eigenvalue. */
00120 /*  The left eigenvector u(j) of A satisfies */
00121 /*                u(j)**H * A = lambda(j) * u(j)**H */
00122 /*  where u(j)**H denotes the conjugate transpose of u(j). */
00123 
00124 /*  The computed eigenvectors are normalized to have Euclidean norm */
00125 /*  equal to 1 and largest component real. */
00126 
00127 /*  Balancing a matrix means permuting the rows and columns to make it */
00128 /*  more nearly upper triangular, and applying a diagonal similarity */
00129 /*  transformation D * A * D**(-1), where D is a diagonal matrix, to */
00130 /*  make its rows and columns closer in norm and the condition numbers */
00131 /*  of its eigenvalues and eigenvectors smaller.  The computed */
00132 /*  reciprocal condition numbers correspond to the balanced matrix. */
00133 /*  Permuting rows and columns will not change the condition numbers */
00134 /*  (in exact arithmetic) but diagonal scaling will.  For further */
00135 /*  explanation of balancing, see section 4.10.2 of the LAPACK */
00136 /*  Users' Guide. */
00137 
00138 /*  Arguments */
00139 /*  ========= */
00140 
00141 /*  BALANC  (input) CHARACTER*1 */
00142 /*          Indicates how the input matrix should be diagonally scaled */
00143 /*          and/or permuted to improve the conditioning of its */
00144 /*          eigenvalues. */
00145 /*          = 'N': Do not diagonally scale or permute; */
00146 /*          = 'P': Perform permutations to make the matrix more nearly */
00147 /*                 upper triangular. Do not diagonally scale; */
00148 /*          = 'S': Diagonally scale the matrix, i.e. replace A by */
00149 /*                 D*A*D**(-1), where D is a diagonal matrix chosen */
00150 /*                 to make the rows and columns of A more equal in */
00151 /*                 norm. Do not permute; */
00152 /*          = 'B': Both diagonally scale and permute A. */
00153 
00154 /*          Computed reciprocal condition numbers will be for the matrix */
00155 /*          after balancing and/or permuting. Permuting does not change */
00156 /*          condition numbers (in exact arithmetic), but balancing does. */
00157 
00158 /*  JOBVL   (input) CHARACTER*1 */
00159 /*          = 'N': left eigenvectors of A are not computed; */
00160 /*          = 'V': left eigenvectors of A are computed. */
00161 /*          If SENSE = 'E' or 'B', JOBVL must = 'V'. */
00162 
00163 /*  JOBVR   (input) CHARACTER*1 */
00164 /*          = 'N': right eigenvectors of A are not computed; */
00165 /*          = 'V': right eigenvectors of A are computed. */
00166 /*          If SENSE = 'E' or 'B', JOBVR must = 'V'. */
00167 
00168 /*  SENSE   (input) CHARACTER*1 */
00169 /*          Determines which reciprocal condition numbers are computed. */
00170 /*          = 'N': None are computed; */
00171 /*          = 'E': Computed for eigenvalues only; */
00172 /*          = 'V': Computed for right eigenvectors only; */
00173 /*          = 'B': Computed for eigenvalues and right eigenvectors. */
00174 
00175 /*          If SENSE = 'E' or 'B', both left and right eigenvectors */
00176 /*          must also be computed (JOBVL = 'V' and JOBVR = 'V'). */
00177 
00178 /*  N       (input) INTEGER */
00179 /*          The order of the matrix A. N >= 0. */
00180 
00181 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
00182 /*          On entry, the N-by-N matrix A. */
00183 /*          On exit, A has been overwritten.  If JOBVL = 'V' or */
00184 /*          JOBVR = 'V', A contains the real Schur form of the balanced */
00185 /*          version of the input matrix A. */
00186 
00187 /*  LDA     (input) INTEGER */
00188 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00189 
00190 /*  WR      (output) DOUBLE PRECISION array, dimension (N) */
00191 /*  WI      (output) DOUBLE PRECISION array, dimension (N) */
00192 /*          WR and WI contain the real and imaginary parts, */
00193 /*          respectively, of the computed eigenvalues.  Complex */
00194 /*          conjugate pairs of eigenvalues will appear consecutively */
00195 /*          with the eigenvalue having the positive imaginary part */
00196 /*          first. */
00197 
00198 /*  VL      (output) DOUBLE PRECISION array, dimension (LDVL,N) */
00199 /*          If JOBVL = 'V', the left eigenvectors u(j) are stored one */
00200 /*          after another in the columns of VL, in the same order */
00201 /*          as their eigenvalues. */
00202 /*          If JOBVL = 'N', VL is not referenced. */
00203 /*          If the j-th eigenvalue is real, then u(j) = VL(:,j), */
00204 /*          the j-th column of VL. */
00205 /*          If the j-th and (j+1)-st eigenvalues form a complex */
00206 /*          conjugate pair, then u(j) = VL(:,j) + i*VL(:,j+1) and */
00207 /*          u(j+1) = VL(:,j) - i*VL(:,j+1). */
00208 
00209 /*  LDVL    (input) INTEGER */
00210 /*          The leading dimension of the array VL.  LDVL >= 1; if */
00211 /*          JOBVL = 'V', LDVL >= N. */
00212 
00213 /*  VR      (output) DOUBLE PRECISION array, dimension (LDVR,N) */
00214 /*          If JOBVR = 'V', the right eigenvectors v(j) are stored one */
00215 /*          after another in the columns of VR, in the same order */
00216 /*          as their eigenvalues. */
00217 /*          If JOBVR = 'N', VR is not referenced. */
00218 /*          If the j-th eigenvalue is real, then v(j) = VR(:,j), */
00219 /*          the j-th column of VR. */
00220 /*          If the j-th and (j+1)-st eigenvalues form a complex */
00221 /*          conjugate pair, then v(j) = VR(:,j) + i*VR(:,j+1) and */
00222 /*          v(j+1) = VR(:,j) - i*VR(:,j+1). */
00223 
00224 /*  LDVR    (input) INTEGER */
00225 /*          The leading dimension of the array VR.  LDVR >= 1, and if */
00226 /*          JOBVR = 'V', LDVR >= N. */
00227 
00228 /*  ILO     (output) INTEGER */
00229 /*  IHI     (output) INTEGER */
00230 /*          ILO and IHI are integer values determined when A was */
00231 /*          balanced.  The balanced A(i,j) = 0 if I > J and */
00232 /*          J = 1,...,ILO-1 or I = IHI+1,...,N. */
00233 
00234 /*  SCALE   (output) DOUBLE PRECISION array, dimension (N) */
00235 /*          Details of the permutations and scaling factors applied */
00236 /*          when balancing A.  If P(j) is the index of the row and column */
00237 /*          interchanged with row and column j, and D(j) is the scaling */
00238 /*          factor applied to row and column j, then */
00239 /*          SCALE(J) = P(J),    for J = 1,...,ILO-1 */
00240 /*                   = D(J),    for J = ILO,...,IHI */
00241 /*                   = P(J)     for J = IHI+1,...,N. */
00242 /*          The order in which the interchanges are made is N to IHI+1, */
00243 /*          then 1 to ILO-1. */
00244 
00245 /*  ABNRM   (output) DOUBLE PRECISION */
00246 /*          The one-norm of the balanced matrix (the maximum */
00247 /*          of the sum of absolute values of elements of any column). */
00248 
00249 /*  RCONDE  (output) DOUBLE PRECISION array, dimension (N) */
00250 /*          RCONDE(j) is the reciprocal condition number of the j-th */
00251 /*          eigenvalue. */
00252 
00253 /*  RCONDV  (output) DOUBLE PRECISION array, dimension (N) */
00254 /*          RCONDV(j) is the reciprocal condition number of the j-th */
00255 /*          right eigenvector. */
00256 
00257 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
00258 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00259 
00260 /*  LWORK   (input) INTEGER */
00261 /*          The dimension of the array WORK.   If SENSE = 'N' or 'E', */
00262 /*          LWORK >= max(1,2*N), and if JOBVL = 'V' or JOBVR = 'V', */
00263 /*          LWORK >= 3*N.  If SENSE = 'V' or 'B', LWORK >= N*(N+6). */
00264 /*          For good performance, LWORK must generally be larger. */
00265 
00266 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00267 /*          only calculates the optimal size of the WORK array, returns */
00268 /*          this value as the first entry of the WORK array, and no error */
00269 /*          message related to LWORK is issued by XERBLA. */
00270 
00271 /*  IWORK   (workspace) INTEGER array, dimension (2*N-2) */
00272 /*          If SENSE = 'N' or 'E', not referenced. */
00273 
00274 /*  INFO    (output) INTEGER */
00275 /*          = 0:  successful exit */
00276 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00277 /*          > 0:  if INFO = i, the QR algorithm failed to compute all the */
00278 /*                eigenvalues, and no eigenvectors or condition numbers */
00279 /*                have been computed; elements 1:ILO-1 and i+1:N of WR */
00280 /*                and WI contain eigenvalues which have converged. */
00281 
00282 /*  ===================================================================== */
00283 
00284 /*     .. Parameters .. */
00285 /*     .. */
00286 /*     .. Local Scalars .. */
00287 /*     .. */
00288 /*     .. Local Arrays .. */
00289 /*     .. */
00290 /*     .. External Subroutines .. */
00291 /*     .. */
00292 /*     .. External Functions .. */
00293 /*     .. */
00294 /*     .. Intrinsic Functions .. */
00295 /*     .. */
00296 /*     .. Executable Statements .. */
00297 
00298 /*     Test the input arguments */
00299 
00300     /* Parameter adjustments */
00301     a_dim1 = *lda;
00302     a_offset = 1 + a_dim1;
00303     a -= a_offset;
00304     --wr;
00305     --wi;
00306     vl_dim1 = *ldvl;
00307     vl_offset = 1 + vl_dim1;
00308     vl -= vl_offset;
00309     vr_dim1 = *ldvr;
00310     vr_offset = 1 + vr_dim1;
00311     vr -= vr_offset;
00312     --scale;
00313     --rconde;
00314     --rcondv;
00315     --work;
00316     --iwork;
00317 
00318     /* Function Body */
00319     *info = 0;
00320     lquery = *lwork == -1;
00321     wantvl = lsame_(jobvl, "V");
00322     wantvr = lsame_(jobvr, "V");
00323     wntsnn = lsame_(sense, "N");
00324     wntsne = lsame_(sense, "E");
00325     wntsnv = lsame_(sense, "V");
00326     wntsnb = lsame_(sense, "B");
00327     if (! (lsame_(balanc, "N") || lsame_(balanc, "S") || lsame_(balanc, "P") 
00328             || lsame_(balanc, "B"))) {
00329         *info = -1;
00330     } else if (! wantvl && ! lsame_(jobvl, "N")) {
00331         *info = -2;
00332     } else if (! wantvr && ! lsame_(jobvr, "N")) {
00333         *info = -3;
00334     } else if (! (wntsnn || wntsne || wntsnb || wntsnv) || (wntsne || wntsnb) 
00335             && ! (wantvl && wantvr)) {
00336         *info = -4;
00337     } else if (*n < 0) {
00338         *info = -5;
00339     } else if (*lda < max(1,*n)) {
00340         *info = -7;
00341     } else if (*ldvl < 1 || wantvl && *ldvl < *n) {
00342         *info = -11;
00343     } else if (*ldvr < 1 || wantvr && *ldvr < *n) {
00344         *info = -13;
00345     }
00346 
00347 /*     Compute workspace */
00348 /*      (Note: Comments in the code beginning "Workspace:" describe the */
00349 /*       minimal amount of workspace needed at that point in the code, */
00350 /*       as well as the preferred amount for good performance. */
00351 /*       NB refers to the optimal block size for the immediately */
00352 /*       following subroutine, as returned by ILAENV. */
00353 /*       HSWORK refers to the workspace preferred by DHSEQR, as */
00354 /*       calculated below. HSWORK is computed assuming ILO=1 and IHI=N, */
00355 /*       the worst case.) */
00356 
00357     if (*info == 0) {
00358         if (*n == 0) {
00359             minwrk = 1;
00360             maxwrk = 1;
00361         } else {
00362             maxwrk = *n + *n * ilaenv_(&c__1, "DGEHRD", " ", n, &c__1, n, &
00363                     c__0);
00364 
00365             if (wantvl) {
00366                 dhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00367                         1], &vl[vl_offset], ldvl, &work[1], &c_n1, info);
00368             } else if (wantvr) {
00369                 dhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00370                         1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
00371             } else {
00372                 if (wntsnn) {
00373                     dhseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &wr[1], 
00374                             &wi[1], &vr[vr_offset], ldvr, &work[1], &c_n1, 
00375                             info);
00376                 } else {
00377                     dhseqr_("S", "N", n, &c__1, n, &a[a_offset], lda, &wr[1], 
00378                             &wi[1], &vr[vr_offset], ldvr, &work[1], &c_n1, 
00379                             info);
00380                 }
00381             }
00382             hswork = (integer) work[1];
00383 
00384             if (! wantvl && ! wantvr) {
00385                 minwrk = *n << 1;
00386                 if (! wntsnn) {
00387 /* Computing MAX */
00388                     i__1 = minwrk, i__2 = *n * *n + *n * 6;
00389                     minwrk = max(i__1,i__2);
00390                 }
00391                 maxwrk = max(maxwrk,hswork);
00392                 if (! wntsnn) {
00393 /* Computing MAX */
00394                     i__1 = maxwrk, i__2 = *n * *n + *n * 6;
00395                     maxwrk = max(i__1,i__2);
00396                 }
00397             } else {
00398                 minwrk = *n * 3;
00399                 if (! wntsnn && ! wntsne) {
00400 /* Computing MAX */
00401                     i__1 = minwrk, i__2 = *n * *n + *n * 6;
00402                     minwrk = max(i__1,i__2);
00403                 }
00404                 maxwrk = max(maxwrk,hswork);
00405 /* Computing MAX */
00406                 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "DORGHR", 
00407                          " ", n, &c__1, n, &c_n1);
00408                 maxwrk = max(i__1,i__2);
00409                 if (! wntsnn && ! wntsne) {
00410 /* Computing MAX */
00411                     i__1 = maxwrk, i__2 = *n * *n + *n * 6;
00412                     maxwrk = max(i__1,i__2);
00413                 }
00414 /* Computing MAX */
00415                 i__1 = maxwrk, i__2 = *n * 3;
00416                 maxwrk = max(i__1,i__2);
00417             }
00418             maxwrk = max(maxwrk,minwrk);
00419         }
00420         work[1] = (doublereal) maxwrk;
00421 
00422         if (*lwork < minwrk && ! lquery) {
00423             *info = -21;
00424         }
00425     }
00426 
00427     if (*info != 0) {
00428         i__1 = -(*info);
00429         xerbla_("DGEEVX", &i__1);
00430         return 0;
00431     } else if (lquery) {
00432         return 0;
00433     }
00434 
00435 /*     Quick return if possible */
00436 
00437     if (*n == 0) {
00438         return 0;
00439     }
00440 
00441 /*     Get machine constants */
00442 
00443     eps = dlamch_("P");
00444     smlnum = dlamch_("S");
00445     bignum = 1. / smlnum;
00446     dlabad_(&smlnum, &bignum);
00447     smlnum = sqrt(smlnum) / eps;
00448     bignum = 1. / smlnum;
00449 
00450 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
00451 
00452     icond = 0;
00453     anrm = dlange_("M", n, n, &a[a_offset], lda, dum);
00454     scalea = FALSE_;
00455     if (anrm > 0. && anrm < smlnum) {
00456         scalea = TRUE_;
00457         cscale = smlnum;
00458     } else if (anrm > bignum) {
00459         scalea = TRUE_;
00460         cscale = bignum;
00461     }
00462     if (scalea) {
00463         dlascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00464                 ierr);
00465     }
00466 
00467 /*     Balance the matrix and compute ABNRM */
00468 
00469     dgebal_(balanc, n, &a[a_offset], lda, ilo, ihi, &scale[1], &ierr);
00470     *abnrm = dlange_("1", n, n, &a[a_offset], lda, dum);
00471     if (scalea) {
00472         dum[0] = *abnrm;
00473         dlascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &c__1, &
00474                 ierr);
00475         *abnrm = dum[0];
00476     }
00477 
00478 /*     Reduce to upper Hessenberg form */
00479 /*     (Workspace: need 2*N, prefer N+N*NB) */
00480 
00481     itau = 1;
00482     iwrk = itau + *n;
00483     i__1 = *lwork - iwrk + 1;
00484     dgehrd_(n, ilo, ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1, &
00485             ierr);
00486 
00487     if (wantvl) {
00488 
00489 /*        Want left eigenvectors */
00490 /*        Copy Householder vectors to VL */
00491 
00492         *(unsigned char *)side = 'L';
00493         dlacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
00494                 ;
00495 
00496 /*        Generate orthogonal matrix in VL */
00497 /*        (Workspace: need 2*N-1, prefer N+(N-1)*NB) */
00498 
00499         i__1 = *lwork - iwrk + 1;
00500         dorghr_(n, ilo, ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk], &
00501                 i__1, &ierr);
00502 
00503 /*        Perform QR iteration, accumulating Schur vectors in VL */
00504 /*        (Workspace: need 1, prefer HSWORK (see comments) ) */
00505 
00506         iwrk = itau;
00507         i__1 = *lwork - iwrk + 1;
00508         dhseqr_("S", "V", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vl[
00509                 vl_offset], ldvl, &work[iwrk], &i__1, info);
00510 
00511         if (wantvr) {
00512 
00513 /*           Want left and right eigenvectors */
00514 /*           Copy Schur vectors to VR */
00515 
00516             *(unsigned char *)side = 'B';
00517             dlacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
00518         }
00519 
00520     } else if (wantvr) {
00521 
00522 /*        Want right eigenvectors */
00523 /*        Copy Householder vectors to VR */
00524 
00525         *(unsigned char *)side = 'R';
00526         dlacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
00527                 ;
00528 
00529 /*        Generate orthogonal matrix in VR */
00530 /*        (Workspace: need 2*N-1, prefer N+(N-1)*NB) */
00531 
00532         i__1 = *lwork - iwrk + 1;
00533         dorghr_(n, ilo, ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk], &
00534                 i__1, &ierr);
00535 
00536 /*        Perform QR iteration, accumulating Schur vectors in VR */
00537 /*        (Workspace: need 1, prefer HSWORK (see comments) ) */
00538 
00539         iwrk = itau;
00540         i__1 = *lwork - iwrk + 1;
00541         dhseqr_("S", "V", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vr[
00542                 vr_offset], ldvr, &work[iwrk], &i__1, info);
00543 
00544     } else {
00545 
00546 /*        Compute eigenvalues only */
00547 /*        If condition numbers desired, compute Schur form */
00548 
00549         if (wntsnn) {
00550             *(unsigned char *)job = 'E';
00551         } else {
00552             *(unsigned char *)job = 'S';
00553         }
00554 
00555 /*        (Workspace: need 1, prefer HSWORK (see comments) ) */
00556 
00557         iwrk = itau;
00558         i__1 = *lwork - iwrk + 1;
00559         dhseqr_(job, "N", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vr[
00560                 vr_offset], ldvr, &work[iwrk], &i__1, info);
00561     }
00562 
00563 /*     If INFO > 0 from DHSEQR, then quit */
00564 
00565     if (*info > 0) {
00566         goto L50;
00567     }
00568 
00569     if (wantvl || wantvr) {
00570 
00571 /*        Compute left and/or right eigenvectors */
00572 /*        (Workspace: need 3*N) */
00573 
00574         dtrevc_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset], ldvl, 
00575                  &vr[vr_offset], ldvr, n, &nout, &work[iwrk], &ierr);
00576     }
00577 
00578 /*     Compute condition numbers if desired */
00579 /*     (Workspace: need N*N+6*N unless SENSE = 'E') */
00580 
00581     if (! wntsnn) {
00582         dtrsna_(sense, "A", select, n, &a[a_offset], lda, &vl[vl_offset], 
00583                 ldvl, &vr[vr_offset], ldvr, &rconde[1], &rcondv[1], n, &nout, 
00584                 &work[iwrk], n, &iwork[1], &icond);
00585     }
00586 
00587     if (wantvl) {
00588 
00589 /*        Undo balancing of left eigenvectors */
00590 
00591         dgebak_(balanc, "L", n, ilo, ihi, &scale[1], n, &vl[vl_offset], ldvl, 
00592                 &ierr);
00593 
00594 /*        Normalize left eigenvectors and make largest component real */
00595 
00596         i__1 = *n;
00597         for (i__ = 1; i__ <= i__1; ++i__) {
00598             if (wi[i__] == 0.) {
00599                 scl = 1. / dnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00600                 dscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00601             } else if (wi[i__] > 0.) {
00602                 d__1 = dnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00603                 d__2 = dnrm2_(n, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
00604                 scl = 1. / dlapy2_(&d__1, &d__2);
00605                 dscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00606                 dscal_(n, &scl, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
00607                 i__2 = *n;
00608                 for (k = 1; k <= i__2; ++k) {
00609 /* Computing 2nd power */
00610                     d__1 = vl[k + i__ * vl_dim1];
00611 /* Computing 2nd power */
00612                     d__2 = vl[k + (i__ + 1) * vl_dim1];
00613                     work[k] = d__1 * d__1 + d__2 * d__2;
00614 /* L10: */
00615                 }
00616                 k = idamax_(n, &work[1], &c__1);
00617                 dlartg_(&vl[k + i__ * vl_dim1], &vl[k + (i__ + 1) * vl_dim1], 
00618                         &cs, &sn, &r__);
00619                 drot_(n, &vl[i__ * vl_dim1 + 1], &c__1, &vl[(i__ + 1) * 
00620                         vl_dim1 + 1], &c__1, &cs, &sn);
00621                 vl[k + (i__ + 1) * vl_dim1] = 0.;
00622             }
00623 /* L20: */
00624         }
00625     }
00626 
00627     if (wantvr) {
00628 
00629 /*        Undo balancing of right eigenvectors */
00630 
00631         dgebak_(balanc, "R", n, ilo, ihi, &scale[1], n, &vr[vr_offset], ldvr, 
00632                 &ierr);
00633 
00634 /*        Normalize right eigenvectors and make largest component real */
00635 
00636         i__1 = *n;
00637         for (i__ = 1; i__ <= i__1; ++i__) {
00638             if (wi[i__] == 0.) {
00639                 scl = 1. / dnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00640                 dscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00641             } else if (wi[i__] > 0.) {
00642                 d__1 = dnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00643                 d__2 = dnrm2_(n, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
00644                 scl = 1. / dlapy2_(&d__1, &d__2);
00645                 dscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00646                 dscal_(n, &scl, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
00647                 i__2 = *n;
00648                 for (k = 1; k <= i__2; ++k) {
00649 /* Computing 2nd power */
00650                     d__1 = vr[k + i__ * vr_dim1];
00651 /* Computing 2nd power */
00652                     d__2 = vr[k + (i__ + 1) * vr_dim1];
00653                     work[k] = d__1 * d__1 + d__2 * d__2;
00654 /* L30: */
00655                 }
00656                 k = idamax_(n, &work[1], &c__1);
00657                 dlartg_(&vr[k + i__ * vr_dim1], &vr[k + (i__ + 1) * vr_dim1], 
00658                         &cs, &sn, &r__);
00659                 drot_(n, &vr[i__ * vr_dim1 + 1], &c__1, &vr[(i__ + 1) * 
00660                         vr_dim1 + 1], &c__1, &cs, &sn);
00661                 vr[k + (i__ + 1) * vr_dim1] = 0.;
00662             }
00663 /* L40: */
00664         }
00665     }
00666 
00667 /*     Undo scaling if necessary */
00668 
00669 L50:
00670     if (scalea) {
00671         i__1 = *n - *info;
00672 /* Computing MAX */
00673         i__3 = *n - *info;
00674         i__2 = max(i__3,1);
00675         dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[*info + 
00676                 1], &i__2, &ierr);
00677         i__1 = *n - *info;
00678 /* Computing MAX */
00679         i__3 = *n - *info;
00680         i__2 = max(i__3,1);
00681         dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[*info + 
00682                 1], &i__2, &ierr);
00683         if (*info == 0) {
00684             if ((wntsnv || wntsnb) && icond == 0) {
00685                 dlascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &rcondv[
00686                         1], n, &ierr);
00687             }
00688         } else {
00689             i__1 = *ilo - 1;
00690             dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[1], 
00691                     n, &ierr);
00692             i__1 = *ilo - 1;
00693             dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[1], 
00694                     n, &ierr);
00695         }
00696     }
00697 
00698     work[1] = (doublereal) maxwrk;
00699     return 0;
00700 
00701 /*     End of DGEEVX */
00702 
00703 } /* dgeevx_ */


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