dtgsna.c
Go to the documentation of this file.
00001 /* dtgsna.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 doublereal c_b19 = 1.;
00020 static doublereal c_b21 = 0.;
00021 static integer c__2 = 2;
00022 static logical c_false = FALSE_;
00023 static integer c__3 = 3;
00024 
00025 /* Subroutine */ int dtgsna_(char *job, char *howmny, logical *select, 
00026         integer *n, doublereal *a, integer *lda, doublereal *b, integer *ldb, 
00027         doublereal *vl, integer *ldvl, doublereal *vr, integer *ldvr, 
00028         doublereal *s, doublereal *dif, integer *mm, integer *m, doublereal *
00029         work, integer *lwork, integer *iwork, integer *info)
00030 {
00031     /* System generated locals */
00032     integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1, 
00033             vr_offset, i__1, i__2;
00034     doublereal d__1, d__2;
00035 
00036     /* Builtin functions */
00037     double sqrt(doublereal);
00038 
00039     /* Local variables */
00040     integer i__, k;
00041     doublereal c1, c2;
00042     integer n1, n2, ks, iz;
00043     doublereal eps, beta, cond;
00044     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
00045             integer *);
00046     logical pair;
00047     integer ierr;
00048     doublereal uhav, uhbv;
00049     integer ifst;
00050     doublereal lnrm;
00051     integer ilst;
00052     doublereal rnrm;
00053     extern /* Subroutine */ int dlag2_(doublereal *, integer *, doublereal *, 
00054             integer *, doublereal *, doublereal *, doublereal *, doublereal *, 
00055              doublereal *, doublereal *);
00056     extern doublereal dnrm2_(integer *, doublereal *, integer *);
00057     doublereal root1, root2, scale;
00058     extern logical lsame_(char *, char *);
00059     extern /* Subroutine */ int dgemv_(char *, integer *, integer *, 
00060             doublereal *, doublereal *, integer *, doublereal *, integer *, 
00061             doublereal *, doublereal *, integer *);
00062     doublereal uhavi, uhbvi, tmpii;
00063     integer lwmin;
00064     logical wants;
00065     doublereal tmpir, tmpri, dummy[1], tmprr;
00066     extern doublereal dlapy2_(doublereal *, doublereal *);
00067     doublereal dummy1[1];
00068     extern doublereal dlamch_(char *);
00069     doublereal alphai, alphar;
00070     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, 
00071             doublereal *, integer *, doublereal *, integer *), 
00072             xerbla_(char *, integer *), dtgexc_(logical *, logical *, 
00073             integer *, doublereal *, integer *, doublereal *, integer *, 
00074             doublereal *, integer *, doublereal *, integer *, integer *, 
00075             integer *, doublereal *, integer *, integer *);
00076     logical wantbh, wantdf, somcon;
00077     doublereal alprqt;
00078     extern /* Subroutine */ int dtgsyl_(char *, integer *, integer *, integer 
00079             *, doublereal *, integer *, doublereal *, integer *, doublereal *, 
00080              integer *, doublereal *, integer *, doublereal *, integer *, 
00081             doublereal *, integer *, doublereal *, doublereal *, doublereal *, 
00082              integer *, integer *, integer *);
00083     doublereal smlnum;
00084     logical lquery;
00085 
00086 
00087 /*  -- LAPACK routine (version 3.2) -- */
00088 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00089 /*     November 2006 */
00090 
00091 /*     .. Scalar Arguments .. */
00092 /*     .. */
00093 /*     .. Array Arguments .. */
00094 /*     .. */
00095 
00096 /*  Purpose */
00097 /*  ======= */
00098 
00099 /*  DTGSNA estimates reciprocal condition numbers for specified */
00100 /*  eigenvalues and/or eigenvectors of a matrix pair (A, B) in */
00101 /*  generalized real Schur canonical form (or of any matrix pair */
00102 /*  (Q*A*Z', Q*B*Z') with orthogonal matrices Q and Z, where */
00103 /*  Z' denotes the transpose of Z. */
00104 
00105 /*  (A, B) must be in generalized real Schur form (as returned by DGGES), */
00106 /*  i.e. A is block upper triangular with 1-by-1 and 2-by-2 diagonal */
00107 /*  blocks. B is upper triangular. */
00108 
00109 
00110 /*  Arguments */
00111 /*  ========= */
00112 
00113 /*  JOB     (input) CHARACTER*1 */
00114 /*          Specifies whether condition numbers are required for */
00115 /*          eigenvalues (S) or eigenvectors (DIF): */
00116 /*          = 'E': for eigenvalues only (S); */
00117 /*          = 'V': for eigenvectors only (DIF); */
00118 /*          = 'B': for both eigenvalues and eigenvectors (S and DIF). */
00119 
00120 /*  HOWMNY  (input) CHARACTER*1 */
00121 /*          = 'A': compute condition numbers for all eigenpairs; */
00122 /*          = 'S': compute condition numbers for selected eigenpairs */
00123 /*                 specified by the array SELECT. */
00124 
00125 /*  SELECT  (input) LOGICAL array, dimension (N) */
00126 /*          If HOWMNY = 'S', SELECT specifies the eigenpairs for which */
00127 /*          condition numbers are required. To select condition numbers */
00128 /*          for the eigenpair corresponding to a real eigenvalue w(j), */
00129 /*          SELECT(j) must be set to .TRUE.. To select condition numbers */
00130 /*          corresponding to a complex conjugate pair of eigenvalues w(j) */
00131 /*          and w(j+1), either SELECT(j) or SELECT(j+1) or both, must be */
00132 /*          set to .TRUE.. */
00133 /*          If HOWMNY = 'A', SELECT is not referenced. */
00134 
00135 /*  N       (input) INTEGER */
00136 /*          The order of the square matrix pair (A, B). N >= 0. */
00137 
00138 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00139 /*          The upper quasi-triangular matrix A in the pair (A,B). */
00140 
00141 /*  LDA     (input) INTEGER */
00142 /*          The leading dimension of the array A. LDA >= max(1,N). */
00143 
00144 /*  B       (input) DOUBLE PRECISION array, dimension (LDB,N) */
00145 /*          The upper triangular matrix B in the pair (A,B). */
00146 
00147 /*  LDB     (input) INTEGER */
00148 /*          The leading dimension of the array B. LDB >= max(1,N). */
00149 
00150 /*  VL      (input) DOUBLE PRECISION array, dimension (LDVL,M) */
00151 /*          If JOB = 'E' or 'B', VL must contain left eigenvectors of */
00152 /*          (A, B), corresponding to the eigenpairs specified by HOWMNY */
00153 /*          and SELECT. The eigenvectors must be stored in consecutive */
00154 /*          columns of VL, as returned by DTGEVC. */
00155 /*          If JOB = 'V', VL is not referenced. */
00156 
00157 /*  LDVL    (input) INTEGER */
00158 /*          The leading dimension of the array VL. LDVL >= 1. */
00159 /*          If JOB = 'E' or 'B', LDVL >= N. */
00160 
00161 /*  VR      (input) DOUBLE PRECISION array, dimension (LDVR,M) */
00162 /*          If JOB = 'E' or 'B', VR must contain right eigenvectors of */
00163 /*          (A, B), corresponding to the eigenpairs specified by HOWMNY */
00164 /*          and SELECT. The eigenvectors must be stored in consecutive */
00165 /*          columns ov VR, as returned by DTGEVC. */
00166 /*          If JOB = 'V', VR is not referenced. */
00167 
00168 /*  LDVR    (input) INTEGER */
00169 /*          The leading dimension of the array VR. LDVR >= 1. */
00170 /*          If JOB = 'E' or 'B', LDVR >= N. */
00171 
00172 /*  S       (output) DOUBLE PRECISION array, dimension (MM) */
00173 /*          If JOB = 'E' or 'B', the reciprocal condition numbers of the */
00174 /*          selected eigenvalues, stored in consecutive elements of the */
00175 /*          array. For a complex conjugate pair of eigenvalues two */
00176 /*          consecutive elements of S are set to the same value. Thus */
00177 /*          S(j), DIF(j), and the j-th columns of VL and VR all */
00178 /*          correspond to the same eigenpair (but not in general the */
00179 /*          j-th eigenpair, unless all eigenpairs are selected). */
00180 /*          If JOB = 'V', S is not referenced. */
00181 
00182 /*  DIF     (output) DOUBLE PRECISION array, dimension (MM) */
00183 /*          If JOB = 'V' or 'B', the estimated reciprocal condition */
00184 /*          numbers of the selected eigenvectors, stored in consecutive */
00185 /*          elements of the array. For a complex eigenvector two */
00186 /*          consecutive elements of DIF are set to the same value. If */
00187 /*          the eigenvalues cannot be reordered to compute DIF(j), DIF(j) */
00188 /*          is set to 0; this can only occur when the true value would be */
00189 /*          very small anyway. */
00190 /*          If JOB = 'E', DIF is not referenced. */
00191 
00192 /*  MM      (input) INTEGER */
00193 /*          The number of elements in the arrays S and DIF. MM >= M. */
00194 
00195 /*  M       (output) INTEGER */
00196 /*          The number of elements of the arrays S and DIF used to store */
00197 /*          the specified condition numbers; for each selected real */
00198 /*          eigenvalue one element is used, and for each selected complex */
00199 /*          conjugate pair of eigenvalues, two elements are used. */
00200 /*          If HOWMNY = 'A', M is set to N. */
00201 
00202 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
00203 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00204 
00205 /*  LWORK   (input) INTEGER */
00206 /*          The dimension of the array WORK. LWORK >= max(1,N). */
00207 /*          If JOB = 'V' or 'B' LWORK >= 2*N*(N+2)+16. */
00208 
00209 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00210 /*          only calculates the optimal size of the WORK array, returns */
00211 /*          this value as the first entry of the WORK array, and no error */
00212 /*          message related to LWORK is issued by XERBLA. */
00213 
00214 /*  IWORK   (workspace) INTEGER array, dimension (N + 6) */
00215 /*          If JOB = 'E', IWORK is not referenced. */
00216 
00217 /*  INFO    (output) INTEGER */
00218 /*          =0: Successful exit */
00219 /*          <0: If INFO = -i, the i-th argument had an illegal value */
00220 
00221 
00222 /*  Further Details */
00223 /*  =============== */
00224 
00225 /*  The reciprocal of the condition number of a generalized eigenvalue */
00226 /*  w = (a, b) is defined as */
00227 
00228 /*       S(w) = (|u'Av|**2 + |u'Bv|**2)**(1/2) / (norm(u)*norm(v)) */
00229 
00230 /*  where u and v are the left and right eigenvectors of (A, B) */
00231 /*  corresponding to w; |z| denotes the absolute value of the complex */
00232 /*  number, and norm(u) denotes the 2-norm of the vector u. */
00233 /*  The pair (a, b) corresponds to an eigenvalue w = a/b (= u'Av/u'Bv) */
00234 /*  of the matrix pair (A, B). If both a and b equal zero, then (A B) is */
00235 /*  singular and S(I) = -1 is returned. */
00236 
00237 /*  An approximate error bound on the chordal distance between the i-th */
00238 /*  computed generalized eigenvalue w and the corresponding exact */
00239 /*  eigenvalue lambda is */
00240 
00241 /*       chord(w, lambda) <= EPS * norm(A, B) / S(I) */
00242 
00243 /*  where EPS is the machine precision. */
00244 
00245 /*  The reciprocal of the condition number DIF(i) of right eigenvector u */
00246 /*  and left eigenvector v corresponding to the generalized eigenvalue w */
00247 /*  is defined as follows: */
00248 
00249 /*  a) If the i-th eigenvalue w = (a,b) is real */
00250 
00251 /*     Suppose U and V are orthogonal transformations such that */
00252 
00253 /*                U'*(A, B)*V  = (S, T) = ( a   *  ) ( b  *  )  1 */
00254 /*                                        ( 0  S22 ),( 0 T22 )  n-1 */
00255 /*                                          1  n-1     1 n-1 */
00256 
00257 /*     Then the reciprocal condition number DIF(i) is */
00258 
00259 /*                Difl((a, b), (S22, T22)) = sigma-min( Zl ), */
00260 
00261 /*     where sigma-min(Zl) denotes the smallest singular value of the */
00262 /*     2(n-1)-by-2(n-1) matrix */
00263 
00264 /*         Zl = [ kron(a, In-1)  -kron(1, S22) ] */
00265 /*              [ kron(b, In-1)  -kron(1, T22) ] . */
00266 
00267 /*     Here In-1 is the identity matrix of size n-1. kron(X, Y) is the */
00268 /*     Kronecker product between the matrices X and Y. */
00269 
00270 /*     Note that if the default method for computing DIF(i) is wanted */
00271 /*     (see DLATDF), then the parameter DIFDRI (see below) should be */
00272 /*     changed from 3 to 4 (routine DLATDF(IJOB = 2 will be used)). */
00273 /*     See DTGSYL for more details. */
00274 
00275 /*  b) If the i-th and (i+1)-th eigenvalues are complex conjugate pair, */
00276 
00277 /*     Suppose U and V are orthogonal transformations such that */
00278 
00279 /*                U'*(A, B)*V = (S, T) = ( S11  *   ) ( T11  *  )  2 */
00280 /*                                       ( 0    S22 ),( 0    T22) n-2 */
00281 /*                                         2    n-2     2    n-2 */
00282 
00283 /*     and (S11, T11) corresponds to the complex conjugate eigenvalue */
00284 /*     pair (w, conjg(w)). There exist unitary matrices U1 and V1 such */
00285 /*     that */
00286 
00287 /*         U1'*S11*V1 = ( s11 s12 )   and U1'*T11*V1 = ( t11 t12 ) */
00288 /*                      (  0  s22 )                    (  0  t22 ) */
00289 
00290 /*     where the generalized eigenvalues w = s11/t11 and */
00291 /*     conjg(w) = s22/t22. */
00292 
00293 /*     Then the reciprocal condition number DIF(i) is bounded by */
00294 
00295 /*         min( d1, max( 1, |real(s11)/real(s22)| )*d2 ) */
00296 
00297 /*     where, d1 = Difl((s11, t11), (s22, t22)) = sigma-min(Z1), where */
00298 /*     Z1 is the complex 2-by-2 matrix */
00299 
00300 /*              Z1 =  [ s11  -s22 ] */
00301 /*                    [ t11  -t22 ], */
00302 
00303 /*     This is done by computing (using real arithmetic) the */
00304 /*     roots of the characteristical polynomial det(Z1' * Z1 - lambda I), */
00305 /*     where Z1' denotes the conjugate transpose of Z1 and det(X) denotes */
00306 /*     the determinant of X. */
00307 
00308 /*     and d2 is an upper bound on Difl((S11, T11), (S22, T22)), i.e. an */
00309 /*     upper bound on sigma-min(Z2), where Z2 is (2n-2)-by-(2n-2) */
00310 
00311 /*              Z2 = [ kron(S11', In-2)  -kron(I2, S22) ] */
00312 /*                   [ kron(T11', In-2)  -kron(I2, T22) ] */
00313 
00314 /*     Note that if the default method for computing DIF is wanted (see */
00315 /*     DLATDF), then the parameter DIFDRI (see below) should be changed */
00316 /*     from 3 to 4 (routine DLATDF(IJOB = 2 will be used)). See DTGSYL */
00317 /*     for more details. */
00318 
00319 /*  For each eigenvalue/vector specified by SELECT, DIF stores a */
00320 /*  Frobenius norm-based estimate of Difl. */
00321 
00322 /*  An approximate error bound for the i-th computed eigenvector VL(i) or */
00323 /*  VR(i) is given by */
00324 
00325 /*             EPS * norm(A, B) / DIF(i). */
00326 
00327 /*  See ref. [2-3] for more details and further references. */
00328 
00329 /*  Based on contributions by */
00330 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00331 /*     Umea University, S-901 87 Umea, Sweden. */
00332 
00333 /*  References */
00334 /*  ========== */
00335 
00336 /*  [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
00337 /*      Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
00338 /*      M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
00339 /*      Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
00340 
00341 /*  [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
00342 /*      Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
00343 /*      Estimation: Theory, Algorithms and Software, */
00344 /*      Report UMINF - 94.04, Department of Computing Science, Umea */
00345 /*      University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working */
00346 /*      Note 87. To appear in Numerical Algorithms, 1996. */
00347 
00348 /*  [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */
00349 /*      for Solving the Generalized Sylvester Equation and Estimating the */
00350 /*      Separation between Regular Matrix Pairs, Report UMINF - 93.23, */
00351 /*      Department of Computing Science, Umea University, S-901 87 Umea, */
00352 /*      Sweden, December 1993, Revised April 1994, Also as LAPACK Working */
00353 /*      Note 75.  To appear in ACM Trans. on Math. Software, Vol 22, */
00354 /*      No 1, 1996. */
00355 
00356 /*  ===================================================================== */
00357 
00358 /*     .. Parameters .. */
00359 /*     .. */
00360 /*     .. Local Scalars .. */
00361 /*     .. */
00362 /*     .. Local Arrays .. */
00363 /*     .. */
00364 /*     .. External Functions .. */
00365 /*     .. */
00366 /*     .. External Subroutines .. */
00367 /*     .. */
00368 /*     .. Intrinsic Functions .. */
00369 /*     .. */
00370 /*     .. Executable Statements .. */
00371 
00372 /*     Decode and test the input parameters */
00373 
00374     /* Parameter adjustments */
00375     --select;
00376     a_dim1 = *lda;
00377     a_offset = 1 + a_dim1;
00378     a -= a_offset;
00379     b_dim1 = *ldb;
00380     b_offset = 1 + b_dim1;
00381     b -= b_offset;
00382     vl_dim1 = *ldvl;
00383     vl_offset = 1 + vl_dim1;
00384     vl -= vl_offset;
00385     vr_dim1 = *ldvr;
00386     vr_offset = 1 + vr_dim1;
00387     vr -= vr_offset;
00388     --s;
00389     --dif;
00390     --work;
00391     --iwork;
00392 
00393     /* Function Body */
00394     wantbh = lsame_(job, "B");
00395     wants = lsame_(job, "E") || wantbh;
00396     wantdf = lsame_(job, "V") || wantbh;
00397 
00398     somcon = lsame_(howmny, "S");
00399 
00400     *info = 0;
00401     lquery = *lwork == -1;
00402 
00403     if (! wants && ! wantdf) {
00404         *info = -1;
00405     } else if (! lsame_(howmny, "A") && ! somcon) {
00406         *info = -2;
00407     } else if (*n < 0) {
00408         *info = -4;
00409     } else if (*lda < max(1,*n)) {
00410         *info = -6;
00411     } else if (*ldb < max(1,*n)) {
00412         *info = -8;
00413     } else if (wants && *ldvl < *n) {
00414         *info = -10;
00415     } else if (wants && *ldvr < *n) {
00416         *info = -12;
00417     } else {
00418 
00419 /*        Set M to the number of eigenpairs for which condition numbers */
00420 /*        are required, and test MM. */
00421 
00422         if (somcon) {
00423             *m = 0;
00424             pair = FALSE_;
00425             i__1 = *n;
00426             for (k = 1; k <= i__1; ++k) {
00427                 if (pair) {
00428                     pair = FALSE_;
00429                 } else {
00430                     if (k < *n) {
00431                         if (a[k + 1 + k * a_dim1] == 0.) {
00432                             if (select[k]) {
00433                                 ++(*m);
00434                             }
00435                         } else {
00436                             pair = TRUE_;
00437                             if (select[k] || select[k + 1]) {
00438                                 *m += 2;
00439                             }
00440                         }
00441                     } else {
00442                         if (select[*n]) {
00443                             ++(*m);
00444                         }
00445                     }
00446                 }
00447 /* L10: */
00448             }
00449         } else {
00450             *m = *n;
00451         }
00452 
00453         if (*n == 0) {
00454             lwmin = 1;
00455         } else if (lsame_(job, "V") || lsame_(job, 
00456                 "B")) {
00457             lwmin = (*n << 1) * (*n + 2) + 16;
00458         } else {
00459             lwmin = *n;
00460         }
00461         work[1] = (doublereal) lwmin;
00462 
00463         if (*mm < *m) {
00464             *info = -15;
00465         } else if (*lwork < lwmin && ! lquery) {
00466             *info = -18;
00467         }
00468     }
00469 
00470     if (*info != 0) {
00471         i__1 = -(*info);
00472         xerbla_("DTGSNA", &i__1);
00473         return 0;
00474     } else if (lquery) {
00475         return 0;
00476     }
00477 
00478 /*     Quick return if possible */
00479 
00480     if (*n == 0) {
00481         return 0;
00482     }
00483 
00484 /*     Get machine constants */
00485 
00486     eps = dlamch_("P");
00487     smlnum = dlamch_("S") / eps;
00488     ks = 0;
00489     pair = FALSE_;
00490 
00491     i__1 = *n;
00492     for (k = 1; k <= i__1; ++k) {
00493 
00494 /*        Determine whether A(k,k) begins a 1-by-1 or 2-by-2 block. */
00495 
00496         if (pair) {
00497             pair = FALSE_;
00498             goto L20;
00499         } else {
00500             if (k < *n) {
00501                 pair = a[k + 1 + k * a_dim1] != 0.;
00502             }
00503         }
00504 
00505 /*        Determine whether condition numbers are required for the k-th */
00506 /*        eigenpair. */
00507 
00508         if (somcon) {
00509             if (pair) {
00510                 if (! select[k] && ! select[k + 1]) {
00511                     goto L20;
00512                 }
00513             } else {
00514                 if (! select[k]) {
00515                     goto L20;
00516                 }
00517             }
00518         }
00519 
00520         ++ks;
00521 
00522         if (wants) {
00523 
00524 /*           Compute the reciprocal condition number of the k-th */
00525 /*           eigenvalue. */
00526 
00527             if (pair) {
00528 
00529 /*              Complex eigenvalue pair. */
00530 
00531                 d__1 = dnrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
00532                 d__2 = dnrm2_(n, &vr[(ks + 1) * vr_dim1 + 1], &c__1);
00533                 rnrm = dlapy2_(&d__1, &d__2);
00534                 d__1 = dnrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
00535                 d__2 = dnrm2_(n, &vl[(ks + 1) * vl_dim1 + 1], &c__1);
00536                 lnrm = dlapy2_(&d__1, &d__2);
00537                 dgemv_("N", n, n, &c_b19, &a[a_offset], lda, &vr[ks * vr_dim1 
00538                         + 1], &c__1, &c_b21, &work[1], &c__1);
00539                 tmprr = ddot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &
00540                         c__1);
00541                 tmpri = ddot_(n, &work[1], &c__1, &vl[(ks + 1) * vl_dim1 + 1], 
00542                          &c__1);
00543                 dgemv_("N", n, n, &c_b19, &a[a_offset], lda, &vr[(ks + 1) * 
00544                         vr_dim1 + 1], &c__1, &c_b21, &work[1], &c__1);
00545                 tmpii = ddot_(n, &work[1], &c__1, &vl[(ks + 1) * vl_dim1 + 1], 
00546                          &c__1);
00547                 tmpir = ddot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &
00548                         c__1);
00549                 uhav = tmprr + tmpii;
00550                 uhavi = tmpir - tmpri;
00551                 dgemv_("N", n, n, &c_b19, &b[b_offset], ldb, &vr[ks * vr_dim1 
00552                         + 1], &c__1, &c_b21, &work[1], &c__1);
00553                 tmprr = ddot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &
00554                         c__1);
00555                 tmpri = ddot_(n, &work[1], &c__1, &vl[(ks + 1) * vl_dim1 + 1], 
00556                          &c__1);
00557                 dgemv_("N", n, n, &c_b19, &b[b_offset], ldb, &vr[(ks + 1) * 
00558                         vr_dim1 + 1], &c__1, &c_b21, &work[1], &c__1);
00559                 tmpii = ddot_(n, &work[1], &c__1, &vl[(ks + 1) * vl_dim1 + 1], 
00560                          &c__1);
00561                 tmpir = ddot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &
00562                         c__1);
00563                 uhbv = tmprr + tmpii;
00564                 uhbvi = tmpir - tmpri;
00565                 uhav = dlapy2_(&uhav, &uhavi);
00566                 uhbv = dlapy2_(&uhbv, &uhbvi);
00567                 cond = dlapy2_(&uhav, &uhbv);
00568                 s[ks] = cond / (rnrm * lnrm);
00569                 s[ks + 1] = s[ks];
00570 
00571             } else {
00572 
00573 /*              Real eigenvalue. */
00574 
00575                 rnrm = dnrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
00576                 lnrm = dnrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
00577                 dgemv_("N", n, n, &c_b19, &a[a_offset], lda, &vr[ks * vr_dim1 
00578                         + 1], &c__1, &c_b21, &work[1], &c__1);
00579                 uhav = ddot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &c__1)
00580                         ;
00581                 dgemv_("N", n, n, &c_b19, &b[b_offset], ldb, &vr[ks * vr_dim1 
00582                         + 1], &c__1, &c_b21, &work[1], &c__1);
00583                 uhbv = ddot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &c__1)
00584                         ;
00585                 cond = dlapy2_(&uhav, &uhbv);
00586                 if (cond == 0.) {
00587                     s[ks] = -1.;
00588                 } else {
00589                     s[ks] = cond / (rnrm * lnrm);
00590                 }
00591             }
00592         }
00593 
00594         if (wantdf) {
00595             if (*n == 1) {
00596                 dif[ks] = dlapy2_(&a[a_dim1 + 1], &b[b_dim1 + 1]);
00597                 goto L20;
00598             }
00599 
00600 /*           Estimate the reciprocal condition number of the k-th */
00601 /*           eigenvectors. */
00602             if (pair) {
00603 
00604 /*              Copy the  2-by 2 pencil beginning at (A(k,k), B(k, k)). */
00605 /*              Compute the eigenvalue(s) at position K. */
00606 
00607                 work[1] = a[k + k * a_dim1];
00608                 work[2] = a[k + 1 + k * a_dim1];
00609                 work[3] = a[k + (k + 1) * a_dim1];
00610                 work[4] = a[k + 1 + (k + 1) * a_dim1];
00611                 work[5] = b[k + k * b_dim1];
00612                 work[6] = b[k + 1 + k * b_dim1];
00613                 work[7] = b[k + (k + 1) * b_dim1];
00614                 work[8] = b[k + 1 + (k + 1) * b_dim1];
00615                 d__1 = smlnum * eps;
00616                 dlag2_(&work[1], &c__2, &work[5], &c__2, &d__1, &beta, dummy1, 
00617                          &alphar, dummy, &alphai);
00618                 alprqt = 1.;
00619                 c1 = (alphar * alphar + alphai * alphai + beta * beta) * 2.;
00620                 c2 = beta * 4. * beta * alphai * alphai;
00621                 root1 = c1 + sqrt(c1 * c1 - c2 * 4.);
00622                 root2 = c2 / root1;
00623                 root1 /= 2.;
00624 /* Computing MIN */
00625                 d__1 = sqrt(root1), d__2 = sqrt(root2);
00626                 cond = min(d__1,d__2);
00627             }
00628 
00629 /*           Copy the matrix (A, B) to the array WORK and swap the */
00630 /*           diagonal block beginning at A(k,k) to the (1,1) position. */
00631 
00632             dlacpy_("Full", n, n, &a[a_offset], lda, &work[1], n);
00633             dlacpy_("Full", n, n, &b[b_offset], ldb, &work[*n * *n + 1], n);
00634             ifst = k;
00635             ilst = 1;
00636 
00637             i__2 = *lwork - (*n << 1) * *n;
00638             dtgexc_(&c_false, &c_false, n, &work[1], n, &work[*n * *n + 1], n, 
00639                      dummy, &c__1, dummy1, &c__1, &ifst, &ilst, &work[(*n * *
00640                     n << 1) + 1], &i__2, &ierr);
00641 
00642             if (ierr > 0) {
00643 
00644 /*              Ill-conditioned problem - swap rejected. */
00645 
00646                 dif[ks] = 0.;
00647             } else {
00648 
00649 /*              Reordering successful, solve generalized Sylvester */
00650 /*              equation for R and L, */
00651 /*                         A22 * R - L * A11 = A12 */
00652 /*                         B22 * R - L * B11 = B12, */
00653 /*              and compute estimate of Difl((A11,B11), (A22, B22)). */
00654 
00655                 n1 = 1;
00656                 if (work[2] != 0.) {
00657                     n1 = 2;
00658                 }
00659                 n2 = *n - n1;
00660                 if (n2 == 0) {
00661                     dif[ks] = cond;
00662                 } else {
00663                     i__ = *n * *n + 1;
00664                     iz = (*n << 1) * *n + 1;
00665                     i__2 = *lwork - (*n << 1) * *n;
00666                     dtgsyl_("N", &c__3, &n2, &n1, &work[*n * n1 + n1 + 1], n, 
00667                             &work[1], n, &work[n1 + 1], n, &work[*n * n1 + n1 
00668                             + i__], n, &work[i__], n, &work[n1 + i__], n, &
00669                             scale, &dif[ks], &work[iz + 1], &i__2, &iwork[1], 
00670                             &ierr);
00671 
00672                     if (pair) {
00673 /* Computing MIN */
00674                         d__1 = max(1.,alprqt) * dif[ks];
00675                         dif[ks] = min(d__1,cond);
00676                     }
00677                 }
00678             }
00679             if (pair) {
00680                 dif[ks + 1] = dif[ks];
00681             }
00682         }
00683         if (pair) {
00684             ++ks;
00685         }
00686 
00687 L20:
00688         ;
00689     }
00690     work[1] = (doublereal) lwmin;
00691     return 0;
00692 
00693 /*     End of DTGSNA */
00694 
00695 } /* dtgsna_ */


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