00001 /* ctgsna.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 complex c_b19 = {1.f,0.f}; 00020 static complex c_b20 = {0.f,0.f}; 00021 static logical c_false = FALSE_; 00022 static integer c__3 = 3; 00023 00024 /* Subroutine */ int ctgsna_(char *job, char *howmny, logical *select, 00025 integer *n, complex *a, integer *lda, complex *b, integer *ldb, 00026 complex *vl, integer *ldvl, complex *vr, integer *ldvr, real *s, real 00027 *dif, integer *mm, integer *m, complex *work, integer *lwork, integer 00028 *iwork, integer *info) 00029 { 00030 /* System generated locals */ 00031 integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1, 00032 vr_offset, i__1; 00033 real r__1, r__2; 00034 complex q__1; 00035 00036 /* Builtin functions */ 00037 double c_abs(complex *); 00038 00039 /* Local variables */ 00040 integer i__, k, n1, n2, ks; 00041 real eps, cond; 00042 integer ierr, ifst; 00043 real lnrm; 00044 complex yhax, yhbx; 00045 integer ilst; 00046 real rnrm, scale; 00047 extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer 00048 *, complex *, integer *); 00049 extern logical lsame_(char *, char *); 00050 extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex * 00051 , complex *, integer *, complex *, integer *, complex *, complex * 00052 , integer *); 00053 integer lwmin; 00054 logical wants; 00055 complex dummy[1]; 00056 extern doublereal scnrm2_(integer *, complex *, integer *), slapy2_(real * 00057 , real *); 00058 complex dummy1[1]; 00059 extern /* Subroutine */ int slabad_(real *, real *); 00060 extern doublereal slamch_(char *); 00061 extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex 00062 *, integer *, complex *, integer *), ctgexc_(logical *, 00063 logical *, integer *, complex *, integer *, complex *, integer *, 00064 complex *, integer *, complex *, integer *, integer *, integer *, 00065 integer *), xerbla_(char *, integer *); 00066 real bignum; 00067 logical wantbh, wantdf, somcon; 00068 extern /* Subroutine */ int ctgsyl_(char *, integer *, integer *, integer 00069 *, complex *, integer *, complex *, integer *, complex *, integer 00070 *, complex *, integer *, complex *, integer *, complex *, integer 00071 *, real *, real *, complex *, integer *, integer *, integer *); 00072 real smlnum; 00073 logical lquery; 00074 00075 00076 /* -- LAPACK routine (version 3.2) -- */ 00077 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00078 /* November 2006 */ 00079 00080 /* .. Scalar Arguments .. */ 00081 /* .. */ 00082 /* .. Array Arguments .. */ 00083 /* .. */ 00084 00085 /* Purpose */ 00086 /* ======= */ 00087 00088 /* CTGSNA estimates reciprocal condition numbers for specified */ 00089 /* eigenvalues and/or eigenvectors of a matrix pair (A, B). */ 00090 00091 /* (A, B) must be in generalized Schur canonical form, that is, A and */ 00092 /* B are both upper triangular. */ 00093 00094 /* Arguments */ 00095 /* ========= */ 00096 00097 /* JOB (input) CHARACTER*1 */ 00098 /* Specifies whether condition numbers are required for */ 00099 /* eigenvalues (S) or eigenvectors (DIF): */ 00100 /* = 'E': for eigenvalues only (S); */ 00101 /* = 'V': for eigenvectors only (DIF); */ 00102 /* = 'B': for both eigenvalues and eigenvectors (S and DIF). */ 00103 00104 /* HOWMNY (input) CHARACTER*1 */ 00105 /* = 'A': compute condition numbers for all eigenpairs; */ 00106 /* = 'S': compute condition numbers for selected eigenpairs */ 00107 /* specified by the array SELECT. */ 00108 00109 /* SELECT (input) LOGICAL array, dimension (N) */ 00110 /* If HOWMNY = 'S', SELECT specifies the eigenpairs for which */ 00111 /* condition numbers are required. To select condition numbers */ 00112 /* for the corresponding j-th eigenvalue and/or eigenvector, */ 00113 /* SELECT(j) must be set to .TRUE.. */ 00114 /* If HOWMNY = 'A', SELECT is not referenced. */ 00115 00116 /* N (input) INTEGER */ 00117 /* The order of the square matrix pair (A, B). N >= 0. */ 00118 00119 /* A (input) COMPLEX array, dimension (LDA,N) */ 00120 /* The upper triangular matrix A in the pair (A,B). */ 00121 00122 /* LDA (input) INTEGER */ 00123 /* The leading dimension of the array A. LDA >= max(1,N). */ 00124 00125 /* B (input) COMPLEX array, dimension (LDB,N) */ 00126 /* The upper triangular matrix B in the pair (A, B). */ 00127 00128 /* LDB (input) INTEGER */ 00129 /* The leading dimension of the array B. LDB >= max(1,N). */ 00130 00131 /* VL (input) COMPLEX array, dimension (LDVL,M) */ 00132 /* IF JOB = 'E' or 'B', VL must contain left eigenvectors of */ 00133 /* (A, B), corresponding to the eigenpairs specified by HOWMNY */ 00134 /* and SELECT. The eigenvectors must be stored in consecutive */ 00135 /* columns of VL, as returned by CTGEVC. */ 00136 /* If JOB = 'V', VL is not referenced. */ 00137 00138 /* LDVL (input) INTEGER */ 00139 /* The leading dimension of the array VL. LDVL >= 1; and */ 00140 /* If JOB = 'E' or 'B', LDVL >= N. */ 00141 00142 /* VR (input) COMPLEX array, dimension (LDVR,M) */ 00143 /* IF JOB = 'E' or 'B', VR must contain right eigenvectors of */ 00144 /* (A, B), corresponding to the eigenpairs specified by HOWMNY */ 00145 /* and SELECT. The eigenvectors must be stored in consecutive */ 00146 /* columns of VR, as returned by CTGEVC. */ 00147 /* If JOB = 'V', VR is not referenced. */ 00148 00149 /* LDVR (input) INTEGER */ 00150 /* The leading dimension of the array VR. LDVR >= 1; */ 00151 /* If JOB = 'E' or 'B', LDVR >= N. */ 00152 00153 /* S (output) REAL array, dimension (MM) */ 00154 /* If JOB = 'E' or 'B', the reciprocal condition numbers of the */ 00155 /* selected eigenvalues, stored in consecutive elements of the */ 00156 /* array. */ 00157 /* If JOB = 'V', S is not referenced. */ 00158 00159 /* DIF (output) REAL array, dimension (MM) */ 00160 /* If JOB = 'V' or 'B', the estimated reciprocal condition */ 00161 /* numbers of the selected eigenvectors, stored in consecutive */ 00162 /* elements of the array. */ 00163 /* If the eigenvalues cannot be reordered to compute DIF(j), */ 00164 /* DIF(j) is set to 0; this can only occur when the true value */ 00165 /* would be very small anyway. */ 00166 /* For each eigenvalue/vector specified by SELECT, DIF stores */ 00167 /* a Frobenius norm-based estimate of Difl. */ 00168 /* If JOB = 'E', DIF is not referenced. */ 00169 00170 /* MM (input) INTEGER */ 00171 /* The number of elements in the arrays S and DIF. MM >= M. */ 00172 00173 /* M (output) INTEGER */ 00174 /* The number of elements of the arrays S and DIF used to store */ 00175 /* the specified condition numbers; for each selected eigenvalue */ 00176 /* one element is used. If HOWMNY = 'A', M is set to N. */ 00177 00178 /* WORK (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */ 00179 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ 00180 00181 /* LWORK (input) INTEGER */ 00182 /* The dimension of the array WORK. LWORK >= max(1,N). */ 00183 /* If JOB = 'V' or 'B', LWORK >= max(1,2*N*N). */ 00184 00185 /* IWORK (workspace) INTEGER array, dimension (N+2) */ 00186 /* If JOB = 'E', IWORK is not referenced. */ 00187 00188 /* INFO (output) INTEGER */ 00189 /* = 0: Successful exit */ 00190 /* < 0: If INFO = -i, the i-th argument had an illegal value */ 00191 00192 /* Further Details */ 00193 /* =============== */ 00194 00195 /* The reciprocal of the condition number of the i-th generalized */ 00196 /* eigenvalue w = (a, b) is defined as */ 00197 00198 /* S(I) = (|v'Au|**2 + |v'Bu|**2)**(1/2) / (norm(u)*norm(v)) */ 00199 00200 /* where u and v are the right and left eigenvectors of (A, B) */ 00201 /* corresponding to w; |z| denotes the absolute value of the complex */ 00202 /* number, and norm(u) denotes the 2-norm of the vector u. The pair */ 00203 /* (a, b) corresponds to an eigenvalue w = a/b (= v'Au/v'Bu) of the */ 00204 /* matrix pair (A, B). If both a and b equal zero, then (A,B) is */ 00205 /* singular and S(I) = -1 is returned. */ 00206 00207 /* An approximate error bound on the chordal distance between the i-th */ 00208 /* computed generalized eigenvalue w and the corresponding exact */ 00209 /* eigenvalue lambda is */ 00210 00211 /* chord(w, lambda) <= EPS * norm(A, B) / S(I), */ 00212 00213 /* where EPS is the machine precision. */ 00214 00215 /* The reciprocal of the condition number of the right eigenvector u */ 00216 /* and left eigenvector v corresponding to the generalized eigenvalue w */ 00217 /* is defined as follows. Suppose */ 00218 00219 /* (A, B) = ( a * ) ( b * ) 1 */ 00220 /* ( 0 A22 ),( 0 B22 ) n-1 */ 00221 /* 1 n-1 1 n-1 */ 00222 00223 /* Then the reciprocal condition number DIF(I) is */ 00224 00225 /* Difl[(a, b), (A22, B22)] = sigma-min( Zl ) */ 00226 00227 /* where sigma-min(Zl) denotes the smallest singular value of */ 00228 00229 /* Zl = [ kron(a, In-1) -kron(1, A22) ] */ 00230 /* [ kron(b, In-1) -kron(1, B22) ]. */ 00231 00232 /* Here In-1 is the identity matrix of size n-1 and X' is the conjugate */ 00233 /* transpose of X. kron(X, Y) is the Kronecker product between the */ 00234 /* matrices X and Y. */ 00235 00236 /* We approximate the smallest singular value of Zl with an upper */ 00237 /* bound. This is done by CLATDF. */ 00238 00239 /* An approximate error bound for a computed eigenvector VL(i) or */ 00240 /* VR(i) is given by */ 00241 00242 /* EPS * norm(A, B) / DIF(i). */ 00243 00244 /* See ref. [2-3] for more details and further references. */ 00245 00246 /* Based on contributions by */ 00247 /* Bo Kagstrom and Peter Poromaa, Department of Computing Science, */ 00248 /* Umea University, S-901 87 Umea, Sweden. */ 00249 00250 /* References */ 00251 /* ========== */ 00252 00253 /* [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */ 00254 /* Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */ 00255 /* M.S. Moonen et al (eds), Linear Algebra for Large Scale and */ 00256 /* Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */ 00257 00258 /* [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */ 00259 /* Eigenvalues of a Regular Matrix Pair (A, B) and Condition */ 00260 /* Estimation: Theory, Algorithms and Software, Report */ 00261 /* UMINF - 94.04, Department of Computing Science, Umea University, */ 00262 /* S-901 87 Umea, Sweden, 1994. Also as LAPACK Working Note 87. */ 00263 /* To appear in Numerical Algorithms, 1996. */ 00264 00265 /* [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */ 00266 /* for Solving the Generalized Sylvester Equation and Estimating the */ 00267 /* Separation between Regular Matrix Pairs, Report UMINF - 93.23, */ 00268 /* Department of Computing Science, Umea University, S-901 87 Umea, */ 00269 /* Sweden, December 1993, Revised April 1994, Also as LAPACK Working */ 00270 /* Note 75. */ 00271 /* To appear in ACM Trans. on Math. Software, Vol 22, No 1, 1996. */ 00272 00273 /* ===================================================================== */ 00274 00275 /* .. Parameters .. */ 00276 /* .. */ 00277 /* .. Local Scalars .. */ 00278 /* .. */ 00279 /* .. Local Arrays .. */ 00280 /* .. */ 00281 /* .. External Functions .. */ 00282 /* .. */ 00283 /* .. External Subroutines .. */ 00284 /* .. */ 00285 /* .. Intrinsic Functions .. */ 00286 /* .. */ 00287 /* .. Executable Statements .. */ 00288 00289 /* Decode and test the input parameters */ 00290 00291 /* Parameter adjustments */ 00292 --select; 00293 a_dim1 = *lda; 00294 a_offset = 1 + a_dim1; 00295 a -= a_offset; 00296 b_dim1 = *ldb; 00297 b_offset = 1 + b_dim1; 00298 b -= b_offset; 00299 vl_dim1 = *ldvl; 00300 vl_offset = 1 + vl_dim1; 00301 vl -= vl_offset; 00302 vr_dim1 = *ldvr; 00303 vr_offset = 1 + vr_dim1; 00304 vr -= vr_offset; 00305 --s; 00306 --dif; 00307 --work; 00308 --iwork; 00309 00310 /* Function Body */ 00311 wantbh = lsame_(job, "B"); 00312 wants = lsame_(job, "E") || wantbh; 00313 wantdf = lsame_(job, "V") || wantbh; 00314 00315 somcon = lsame_(howmny, "S"); 00316 00317 *info = 0; 00318 lquery = *lwork == -1; 00319 00320 if (! wants && ! wantdf) { 00321 *info = -1; 00322 } else if (! lsame_(howmny, "A") && ! somcon) { 00323 *info = -2; 00324 } else if (*n < 0) { 00325 *info = -4; 00326 } else if (*lda < max(1,*n)) { 00327 *info = -6; 00328 } else if (*ldb < max(1,*n)) { 00329 *info = -8; 00330 } else if (wants && *ldvl < *n) { 00331 *info = -10; 00332 } else if (wants && *ldvr < *n) { 00333 *info = -12; 00334 } else { 00335 00336 /* Set M to the number of eigenpairs for which condition numbers */ 00337 /* are required, and test MM. */ 00338 00339 if (somcon) { 00340 *m = 0; 00341 i__1 = *n; 00342 for (k = 1; k <= i__1; ++k) { 00343 if (select[k]) { 00344 ++(*m); 00345 } 00346 /* L10: */ 00347 } 00348 } else { 00349 *m = *n; 00350 } 00351 00352 if (*n == 0) { 00353 lwmin = 1; 00354 } else if (lsame_(job, "V") || lsame_(job, 00355 "B")) { 00356 lwmin = (*n << 1) * *n; 00357 } else { 00358 lwmin = *n; 00359 } 00360 work[1].r = (real) lwmin, work[1].i = 0.f; 00361 00362 if (*mm < *m) { 00363 *info = -15; 00364 } else if (*lwork < lwmin && ! lquery) { 00365 *info = -18; 00366 } 00367 } 00368 00369 if (*info != 0) { 00370 i__1 = -(*info); 00371 xerbla_("CTGSNA", &i__1); 00372 return 0; 00373 } else if (lquery) { 00374 return 0; 00375 } 00376 00377 /* Quick return if possible */ 00378 00379 if (*n == 0) { 00380 return 0; 00381 } 00382 00383 /* Get machine constants */ 00384 00385 eps = slamch_("P"); 00386 smlnum = slamch_("S") / eps; 00387 bignum = 1.f / smlnum; 00388 slabad_(&smlnum, &bignum); 00389 ks = 0; 00390 i__1 = *n; 00391 for (k = 1; k <= i__1; ++k) { 00392 00393 /* Determine whether condition numbers are required for the k-th */ 00394 /* eigenpair. */ 00395 00396 if (somcon) { 00397 if (! select[k]) { 00398 goto L20; 00399 } 00400 } 00401 00402 ++ks; 00403 00404 if (wants) { 00405 00406 /* Compute the reciprocal condition number of the k-th */ 00407 /* eigenvalue. */ 00408 00409 rnrm = scnrm2_(n, &vr[ks * vr_dim1 + 1], &c__1); 00410 lnrm = scnrm2_(n, &vl[ks * vl_dim1 + 1], &c__1); 00411 cgemv_("N", n, n, &c_b19, &a[a_offset], lda, &vr[ks * vr_dim1 + 1] 00412 , &c__1, &c_b20, &work[1], &c__1); 00413 cdotc_(&q__1, n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &c__1); 00414 yhax.r = q__1.r, yhax.i = q__1.i; 00415 cgemv_("N", n, n, &c_b19, &b[b_offset], ldb, &vr[ks * vr_dim1 + 1] 00416 , &c__1, &c_b20, &work[1], &c__1); 00417 cdotc_(&q__1, n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &c__1); 00418 yhbx.r = q__1.r, yhbx.i = q__1.i; 00419 r__1 = c_abs(&yhax); 00420 r__2 = c_abs(&yhbx); 00421 cond = slapy2_(&r__1, &r__2); 00422 if (cond == 0.f) { 00423 s[ks] = -1.f; 00424 } else { 00425 s[ks] = cond / (rnrm * lnrm); 00426 } 00427 } 00428 00429 if (wantdf) { 00430 if (*n == 1) { 00431 r__1 = c_abs(&a[a_dim1 + 1]); 00432 r__2 = c_abs(&b[b_dim1 + 1]); 00433 dif[ks] = slapy2_(&r__1, &r__2); 00434 } else { 00435 00436 /* Estimate the reciprocal condition number of the k-th */ 00437 /* eigenvectors. */ 00438 00439 /* Copy the matrix (A, B) to the array WORK and move the */ 00440 /* (k,k)th pair to the (1,1) position. */ 00441 00442 clacpy_("Full", n, n, &a[a_offset], lda, &work[1], n); 00443 clacpy_("Full", n, n, &b[b_offset], ldb, &work[*n * *n + 1], 00444 n); 00445 ifst = k; 00446 ilst = 1; 00447 00448 ctgexc_(&c_false, &c_false, n, &work[1], n, &work[*n * *n + 1] 00449 , n, dummy, &c__1, dummy1, &c__1, &ifst, &ilst, &ierr) 00450 ; 00451 00452 if (ierr > 0) { 00453 00454 /* Ill-conditioned problem - swap rejected. */ 00455 00456 dif[ks] = 0.f; 00457 } else { 00458 00459 /* Reordering successful, solve generalized Sylvester */ 00460 /* equation for R and L, */ 00461 /* A22 * R - L * A11 = A12 */ 00462 /* B22 * R - L * B11 = B12, */ 00463 /* and compute estimate of Difl[(A11,B11), (A22, B22)]. */ 00464 00465 n1 = 1; 00466 n2 = *n - n1; 00467 i__ = *n * *n + 1; 00468 ctgsyl_("N", &c__3, &n2, &n1, &work[*n * n1 + n1 + 1], n, 00469 &work[1], n, &work[n1 + 1], n, &work[*n * n1 + n1 00470 + i__], n, &work[i__], n, &work[n1 + i__], n, & 00471 scale, &dif[ks], dummy, &c__1, &iwork[1], &ierr); 00472 } 00473 } 00474 } 00475 00476 L20: 00477 ; 00478 } 00479 work[1].r = (real) lwmin, work[1].i = 0.f; 00480 return 0; 00481 00482 /* End of CTGSNA */ 00483 00484 } /* ctgsna_ */