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