2329
|
1 SUBROUTINE DTRSEN( JOB, COMPQ, SELECT, N, T, LDT, Q, LDQ, WR, WI, |
|
2 $ M, S, SEP, WORK, LWORK, IWORK, LIWORK, INFO ) |
|
3 * |
3333
|
4 * -- LAPACK routine (version 3.0) -- |
2329
|
5 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., |
|
6 * Courant Institute, Argonne National Lab, and Rice University |
3333
|
7 * June 30, 1999 |
2329
|
8 * |
|
9 * .. Scalar Arguments .. |
|
10 CHARACTER COMPQ, JOB |
|
11 INTEGER INFO, LDQ, LDT, LIWORK, LWORK, M, N |
|
12 DOUBLE PRECISION S, SEP |
|
13 * .. |
|
14 * .. Array Arguments .. |
|
15 LOGICAL SELECT( * ) |
|
16 INTEGER IWORK( * ) |
|
17 DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WI( * ), WORK( * ), |
|
18 $ WR( * ) |
|
19 * .. |
|
20 * |
|
21 * Purpose |
|
22 * ======= |
|
23 * |
|
24 * DTRSEN reorders the real Schur factorization of a real matrix |
|
25 * A = Q*T*Q**T, so that a selected cluster of eigenvalues appears in |
|
26 * the leading diagonal blocks of the upper quasi-triangular matrix T, |
|
27 * and the leading columns of Q form an orthonormal basis of the |
|
28 * corresponding right invariant subspace. |
|
29 * |
|
30 * Optionally the routine computes the reciprocal condition numbers of |
|
31 * the cluster of eigenvalues and/or the invariant subspace. |
|
32 * |
|
33 * T must be in Schur canonical form (as returned by DHSEQR), that is, |
|
34 * block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each |
|
35 * 2-by-2 diagonal block has its diagonal elemnts equal and its |
|
36 * off-diagonal elements of opposite sign. |
|
37 * |
|
38 * Arguments |
|
39 * ========= |
|
40 * |
|
41 * JOB (input) CHARACTER*1 |
|
42 * Specifies whether condition numbers are required for the |
|
43 * cluster of eigenvalues (S) or the invariant subspace (SEP): |
|
44 * = 'N': none; |
|
45 * = 'E': for eigenvalues only (S); |
|
46 * = 'V': for invariant subspace only (SEP); |
|
47 * = 'B': for both eigenvalues and invariant subspace (S and |
|
48 * SEP). |
|
49 * |
|
50 * COMPQ (input) CHARACTER*1 |
|
51 * = 'V': update the matrix Q of Schur vectors; |
|
52 * = 'N': do not update Q. |
|
53 * |
|
54 * SELECT (input) LOGICAL array, dimension (N) |
|
55 * SELECT specifies the eigenvalues in the selected cluster. To |
|
56 * select a real eigenvalue w(j), SELECT(j) must be set to |
|
57 * .TRUE.. To select a complex conjugate pair of eigenvalues |
|
58 * w(j) and w(j+1), corresponding to a 2-by-2 diagonal block, |
|
59 * either SELECT(j) or SELECT(j+1) or both must be set to |
|
60 * .TRUE.; a complex conjugate pair of eigenvalues must be |
|
61 * either both included in the cluster or both excluded. |
|
62 * |
|
63 * N (input) INTEGER |
|
64 * The order of the matrix T. N >= 0. |
|
65 * |
|
66 * T (input/output) DOUBLE PRECISION array, dimension (LDT,N) |
|
67 * On entry, the upper quasi-triangular matrix T, in Schur |
|
68 * canonical form. |
|
69 * On exit, T is overwritten by the reordered matrix T, again in |
|
70 * Schur canonical form, with the selected eigenvalues in the |
|
71 * leading diagonal blocks. |
|
72 * |
|
73 * LDT (input) INTEGER |
|
74 * The leading dimension of the array T. LDT >= max(1,N). |
|
75 * |
|
76 * Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N) |
|
77 * On entry, if COMPQ = 'V', the matrix Q of Schur vectors. |
|
78 * On exit, if COMPQ = 'V', Q has been postmultiplied by the |
|
79 * orthogonal transformation matrix which reorders T; the |
|
80 * leading M columns of Q form an orthonormal basis for the |
|
81 * specified invariant subspace. |
|
82 * If COMPQ = 'N', Q is not referenced. |
|
83 * |
|
84 * LDQ (input) INTEGER |
|
85 * The leading dimension of the array Q. |
|
86 * LDQ >= 1; and if COMPQ = 'V', LDQ >= N. |
|
87 * |
|
88 * WR (output) DOUBLE PRECISION array, dimension (N) |
|
89 * WI (output) DOUBLE PRECISION array, dimension (N) |
|
90 * The real and imaginary parts, respectively, of the reordered |
|
91 * eigenvalues of T. The eigenvalues are stored in the same |
|
92 * order as on the diagonal of T, with WR(i) = T(i,i) and, if |
|
93 * T(i:i+1,i:i+1) is a 2-by-2 diagonal block, WI(i) > 0 and |
|
94 * WI(i+1) = -WI(i). Note that if a complex eigenvalue is |
|
95 * sufficiently ill-conditioned, then its value may differ |
|
96 * significantly from its value before reordering. |
|
97 * |
|
98 * M (output) INTEGER |
|
99 * The dimension of the specified invariant subspace. |
|
100 * 0 < = M <= N. |
|
101 * |
|
102 * S (output) DOUBLE PRECISION |
|
103 * If JOB = 'E' or 'B', S is a lower bound on the reciprocal |
|
104 * condition number for the selected cluster of eigenvalues. |
|
105 * S cannot underestimate the true reciprocal condition number |
|
106 * by more than a factor of sqrt(N). If M = 0 or N, S = 1. |
|
107 * If JOB = 'N' or 'V', S is not referenced. |
|
108 * |
|
109 * SEP (output) DOUBLE PRECISION |
|
110 * If JOB = 'V' or 'B', SEP is the estimated reciprocal |
|
111 * condition number of the specified invariant subspace. If |
|
112 * M = 0 or N, SEP = norm(T). |
|
113 * If JOB = 'N' or 'E', SEP is not referenced. |
|
114 * |
3333
|
115 * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) |
|
116 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK. |
2329
|
117 * |
|
118 * LWORK (input) INTEGER |
|
119 * The dimension of the array WORK. |
|
120 * If JOB = 'N', LWORK >= max(1,N); |
|
121 * if JOB = 'E', LWORK >= M*(N-M); |
|
122 * if JOB = 'V' or 'B', LWORK >= 2*M*(N-M). |
|
123 * |
3333
|
124 * If LWORK = -1, then a workspace query is assumed; the routine |
|
125 * only calculates the optimal size of the WORK array, returns |
|
126 * this value as the first entry of the WORK array, and no error |
|
127 * message related to LWORK is issued by XERBLA. |
|
128 * |
2329
|
129 * IWORK (workspace) INTEGER array, dimension (LIWORK) |
|
130 * IF JOB = 'N' or 'E', IWORK is not referenced. |
|
131 * |
|
132 * LIWORK (input) INTEGER |
|
133 * The dimension of the array IWORK. |
|
134 * If JOB = 'N' or 'E', LIWORK >= 1; |
|
135 * if JOB = 'V' or 'B', LIWORK >= M*(N-M). |
|
136 * |
3333
|
137 * If LIWORK = -1, then a workspace query is assumed; the |
|
138 * routine only calculates the optimal size of the IWORK array, |
|
139 * returns this value as the first entry of the IWORK array, and |
|
140 * no error message related to LIWORK is issued by XERBLA. |
|
141 * |
2329
|
142 * INFO (output) INTEGER |
|
143 * = 0: successful exit |
|
144 * < 0: if INFO = -i, the i-th argument had an illegal value |
|
145 * = 1: reordering of T failed because some eigenvalues are too |
|
146 * close to separate (the problem is very ill-conditioned); |
|
147 * T may have been partially reordered, and WR and WI |
|
148 * contain the eigenvalues in the same order as in T; S and |
|
149 * SEP (if requested) are set to zero. |
|
150 * |
|
151 * Further Details |
|
152 * =============== |
|
153 * |
|
154 * DTRSEN first collects the selected eigenvalues by computing an |
|
155 * orthogonal transformation Z to move them to the top left corner of T. |
|
156 * In other words, the selected eigenvalues are the eigenvalues of T11 |
|
157 * in: |
|
158 * |
|
159 * Z'*T*Z = ( T11 T12 ) n1 |
|
160 * ( 0 T22 ) n2 |
|
161 * n1 n2 |
|
162 * |
|
163 * where N = n1+n2 and Z' means the transpose of Z. The first n1 columns |
|
164 * of Z span the specified invariant subspace of T. |
|
165 * |
|
166 * If T has been obtained from the real Schur factorization of a matrix |
|
167 * A = Q*T*Q', then the reordered real Schur factorization of A is given |
|
168 * by A = (Q*Z)*(Z'*T*Z)*(Q*Z)', and the first n1 columns of Q*Z span |
|
169 * the corresponding invariant subspace of A. |
|
170 * |
|
171 * The reciprocal condition number of the average of the eigenvalues of |
|
172 * T11 may be returned in S. S lies between 0 (very badly conditioned) |
|
173 * and 1 (very well conditioned). It is computed as follows. First we |
|
174 * compute R so that |
|
175 * |
|
176 * P = ( I R ) n1 |
|
177 * ( 0 0 ) n2 |
|
178 * n1 n2 |
|
179 * |
|
180 * is the projector on the invariant subspace associated with T11. |
|
181 * R is the solution of the Sylvester equation: |
|
182 * |
|
183 * T11*R - R*T22 = T12. |
|
184 * |
|
185 * Let F-norm(M) denote the Frobenius-norm of M and 2-norm(M) denote |
|
186 * the two-norm of M. Then S is computed as the lower bound |
|
187 * |
|
188 * (1 + F-norm(R)**2)**(-1/2) |
|
189 * |
|
190 * on the reciprocal of 2-norm(P), the true reciprocal condition number. |
|
191 * S cannot underestimate 1 / 2-norm(P) by more than a factor of |
|
192 * sqrt(N). |
|
193 * |
|
194 * An approximate error bound for the computed average of the |
|
195 * eigenvalues of T11 is |
|
196 * |
|
197 * EPS * norm(T) / S |
|
198 * |
|
199 * where EPS is the machine precision. |
|
200 * |
|
201 * The reciprocal condition number of the right invariant subspace |
|
202 * spanned by the first n1 columns of Z (or of Q*Z) is returned in SEP. |
|
203 * SEP is defined as the separation of T11 and T22: |
|
204 * |
|
205 * sep( T11, T22 ) = sigma-min( C ) |
|
206 * |
|
207 * where sigma-min(C) is the smallest singular value of the |
|
208 * n1*n2-by-n1*n2 matrix |
|
209 * |
|
210 * C = kprod( I(n2), T11 ) - kprod( transpose(T22), I(n1) ) |
|
211 * |
|
212 * I(m) is an m by m identity matrix, and kprod denotes the Kronecker |
|
213 * product. We estimate sigma-min(C) by the reciprocal of an estimate of |
|
214 * the 1-norm of inverse(C). The true reciprocal 1-norm of inverse(C) |
|
215 * cannot differ from sigma-min(C) by more than a factor of sqrt(n1*n2). |
|
216 * |
|
217 * When SEP is small, small changes in T can cause large changes in |
|
218 * the invariant subspace. An approximate bound on the maximum angular |
|
219 * error in the computed right invariant subspace is |
|
220 * |
|
221 * EPS * norm(T) / SEP |
|
222 * |
|
223 * ===================================================================== |
|
224 * |
|
225 * .. Parameters .. |
|
226 DOUBLE PRECISION ZERO, ONE |
|
227 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) |
|
228 * .. |
|
229 * .. Local Scalars .. |
3333
|
230 LOGICAL LQUERY, PAIR, SWAP, WANTBH, WANTQ, WANTS, |
|
231 $ WANTSP |
|
232 INTEGER IERR, K, KASE, KK, KS, LIWMIN, LWMIN, N1, N2, |
|
233 $ NN |
2329
|
234 DOUBLE PRECISION EST, RNORM, SCALE |
|
235 * .. |
|
236 * .. External Functions .. |
|
237 LOGICAL LSAME |
|
238 DOUBLE PRECISION DLANGE |
|
239 EXTERNAL LSAME, DLANGE |
|
240 * .. |
|
241 * .. External Subroutines .. |
|
242 EXTERNAL DLACON, DLACPY, DTREXC, DTRSYL, XERBLA |
|
243 * .. |
|
244 * .. Intrinsic Functions .. |
|
245 INTRINSIC ABS, MAX, SQRT |
|
246 * .. |
|
247 * .. Executable Statements .. |
|
248 * |
|
249 * Decode and test the input parameters |
|
250 * |
|
251 WANTBH = LSAME( JOB, 'B' ) |
|
252 WANTS = LSAME( JOB, 'E' ) .OR. WANTBH |
|
253 WANTSP = LSAME( JOB, 'V' ) .OR. WANTBH |
|
254 WANTQ = LSAME( COMPQ, 'V' ) |
|
255 * |
|
256 INFO = 0 |
3333
|
257 LQUERY = ( LWORK.EQ.-1 ) |
2329
|
258 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.WANTS .AND. .NOT.WANTSP ) |
|
259 $ THEN |
|
260 INFO = -1 |
|
261 ELSE IF( .NOT.LSAME( COMPQ, 'N' ) .AND. .NOT.WANTQ ) THEN |
|
262 INFO = -2 |
|
263 ELSE IF( N.LT.0 ) THEN |
|
264 INFO = -4 |
|
265 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN |
|
266 INFO = -6 |
|
267 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN |
|
268 INFO = -8 |
|
269 ELSE |
|
270 * |
|
271 * Set M to the dimension of the specified invariant subspace, |
|
272 * and test LWORK and LIWORK. |
|
273 * |
|
274 M = 0 |
|
275 PAIR = .FALSE. |
|
276 DO 10 K = 1, N |
|
277 IF( PAIR ) THEN |
|
278 PAIR = .FALSE. |
|
279 ELSE |
|
280 IF( K.LT.N ) THEN |
|
281 IF( T( K+1, K ).EQ.ZERO ) THEN |
|
282 IF( SELECT( K ) ) |
|
283 $ M = M + 1 |
|
284 ELSE |
|
285 PAIR = .TRUE. |
|
286 IF( SELECT( K ) .OR. SELECT( K+1 ) ) |
|
287 $ M = M + 2 |
|
288 END IF |
|
289 ELSE |
|
290 IF( SELECT( N ) ) |
|
291 $ M = M + 1 |
|
292 END IF |
|
293 END IF |
|
294 10 CONTINUE |
|
295 * |
|
296 N1 = M |
|
297 N2 = N - M |
|
298 NN = N1*N2 |
|
299 * |
3333
|
300 IF( WANTSP ) THEN |
|
301 LWMIN = MAX( 1, 2*NN ) |
|
302 LIWMIN = MAX( 1, NN ) |
|
303 ELSE IF( LSAME( JOB, 'N' ) ) THEN |
|
304 LWMIN = MAX( 1, N ) |
|
305 LIWMIN = 1 |
|
306 ELSE IF( LSAME( JOB, 'E' ) ) THEN |
|
307 LWMIN = MAX( 1, NN ) |
|
308 LIWMIN = 1 |
|
309 END IF |
|
310 * |
|
311 IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN |
2329
|
312 INFO = -15 |
3333
|
313 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN |
2329
|
314 INFO = -17 |
|
315 END IF |
|
316 END IF |
3333
|
317 * |
|
318 IF( INFO.EQ.0 ) THEN |
|
319 WORK( 1 ) = LWMIN |
|
320 IWORK( 1 ) = LIWMIN |
|
321 END IF |
|
322 * |
2329
|
323 IF( INFO.NE.0 ) THEN |
|
324 CALL XERBLA( 'DTRSEN', -INFO ) |
|
325 RETURN |
3333
|
326 ELSE IF( LQUERY ) THEN |
|
327 RETURN |
2329
|
328 END IF |
|
329 * |
|
330 * Quick return if possible. |
|
331 * |
|
332 IF( M.EQ.N .OR. M.EQ.0 ) THEN |
|
333 IF( WANTS ) |
|
334 $ S = ONE |
|
335 IF( WANTSP ) |
|
336 $ SEP = DLANGE( '1', N, N, T, LDT, WORK ) |
|
337 GO TO 40 |
|
338 END IF |
|
339 * |
|
340 * Collect the selected blocks at the top-left corner of T. |
|
341 * |
|
342 KS = 0 |
|
343 PAIR = .FALSE. |
|
344 DO 20 K = 1, N |
|
345 IF( PAIR ) THEN |
|
346 PAIR = .FALSE. |
|
347 ELSE |
|
348 SWAP = SELECT( K ) |
|
349 IF( K.LT.N ) THEN |
|
350 IF( T( K+1, K ).NE.ZERO ) THEN |
|
351 PAIR = .TRUE. |
|
352 SWAP = SWAP .OR. SELECT( K+1 ) |
|
353 END IF |
|
354 END IF |
|
355 IF( SWAP ) THEN |
|
356 KS = KS + 1 |
|
357 * |
|
358 * Swap the K-th block to position KS. |
|
359 * |
|
360 IERR = 0 |
|
361 KK = K |
|
362 IF( K.NE.KS ) |
|
363 $ CALL DTREXC( COMPQ, N, T, LDT, Q, LDQ, KK, KS, WORK, |
|
364 $ IERR ) |
|
365 IF( IERR.EQ.1 .OR. IERR.EQ.2 ) THEN |
|
366 * |
|
367 * Blocks too close to swap: exit. |
|
368 * |
|
369 INFO = 1 |
|
370 IF( WANTS ) |
|
371 $ S = ZERO |
|
372 IF( WANTSP ) |
|
373 $ SEP = ZERO |
|
374 GO TO 40 |
|
375 END IF |
|
376 IF( PAIR ) |
|
377 $ KS = KS + 1 |
|
378 END IF |
|
379 END IF |
|
380 20 CONTINUE |
|
381 * |
|
382 IF( WANTS ) THEN |
|
383 * |
|
384 * Solve Sylvester equation for R: |
|
385 * |
|
386 * T11*R - R*T22 = scale*T12 |
|
387 * |
|
388 CALL DLACPY( 'F', N1, N2, T( 1, N1+1 ), LDT, WORK, N1 ) |
|
389 CALL DTRSYL( 'N', 'N', -1, N1, N2, T, LDT, T( N1+1, N1+1 ), |
|
390 $ LDT, WORK, N1, SCALE, IERR ) |
|
391 * |
|
392 * Estimate the reciprocal of the condition number of the cluster |
|
393 * of eigenvalues. |
|
394 * |
|
395 RNORM = DLANGE( 'F', N1, N2, WORK, N1, WORK ) |
|
396 IF( RNORM.EQ.ZERO ) THEN |
|
397 S = ONE |
|
398 ELSE |
|
399 S = SCALE / ( SQRT( SCALE*SCALE / RNORM+RNORM )* |
|
400 $ SQRT( RNORM ) ) |
|
401 END IF |
|
402 END IF |
|
403 * |
|
404 IF( WANTSP ) THEN |
|
405 * |
|
406 * Estimate sep(T11,T22). |
|
407 * |
|
408 EST = ZERO |
|
409 KASE = 0 |
|
410 30 CONTINUE |
|
411 CALL DLACON( NN, WORK( NN+1 ), WORK, IWORK, EST, KASE ) |
|
412 IF( KASE.NE.0 ) THEN |
|
413 IF( KASE.EQ.1 ) THEN |
|
414 * |
|
415 * Solve T11*R - R*T22 = scale*X. |
|
416 * |
|
417 CALL DTRSYL( 'N', 'N', -1, N1, N2, T, LDT, |
|
418 $ T( N1+1, N1+1 ), LDT, WORK, N1, SCALE, |
|
419 $ IERR ) |
|
420 ELSE |
|
421 * |
|
422 * Solve T11'*R - R*T22' = scale*X. |
|
423 * |
|
424 CALL DTRSYL( 'T', 'T', -1, N1, N2, T, LDT, |
|
425 $ T( N1+1, N1+1 ), LDT, WORK, N1, SCALE, |
|
426 $ IERR ) |
|
427 END IF |
|
428 GO TO 30 |
|
429 END IF |
|
430 * |
|
431 SEP = SCALE / EST |
|
432 END IF |
|
433 * |
|
434 40 CONTINUE |
|
435 * |
|
436 * Store the output eigenvalues in WR and WI. |
|
437 * |
|
438 DO 50 K = 1, N |
|
439 WR( K ) = T( K, K ) |
|
440 WI( K ) = ZERO |
|
441 50 CONTINUE |
|
442 DO 60 K = 1, N - 1 |
|
443 IF( T( K+1, K ).NE.ZERO ) THEN |
|
444 WI( K ) = SQRT( ABS( T( K, K+1 ) ) )* |
|
445 $ SQRT( ABS( T( K+1, K ) ) ) |
|
446 WI( K+1 ) = -WI( K ) |
|
447 END IF |
|
448 60 CONTINUE |
3333
|
449 * |
|
450 WORK( 1 ) = LWMIN |
|
451 IWORK( 1 ) = LIWMIN |
|
452 * |
2329
|
453 RETURN |
|
454 * |
|
455 * End of DTRSEN |
|
456 * |
|
457 END |