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