LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
dtrsen.f
Go to the documentation of this file.
1*> \brief \b DTRSEN
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download DTRSEN + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrsen.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrsen.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrsen.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE DTRSEN( JOB, COMPQ, SELECT, N, T, LDT, Q, LDQ, WR, WI,
20* M, S, SEP, WORK, LWORK, IWORK, LIWORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER COMPQ, JOB
24* INTEGER INFO, LDQ, LDT, LIWORK, LWORK, M, N
25* DOUBLE PRECISION S, SEP
26* ..
27* .. Array Arguments ..
28* LOGICAL SELECT( * )
29* INTEGER IWORK( * )
30* DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WI( * ), WORK( * ),
31* $ WR( * )
32* ..
33*
34*
35*> \par Purpose:
36* =============
37*>
38*> \verbatim
39*>
40*> DTRSEN reorders the real Schur factorization of a real matrix
41*> A = Q*T*Q**T, so that a selected cluster of eigenvalues appears in
42*> the leading diagonal blocks of the upper quasi-triangular matrix T,
43*> and the leading columns of Q form an orthonormal basis of the
44*> corresponding right invariant subspace.
45*>
46*> Optionally the routine computes the reciprocal condition numbers of
47*> the cluster of eigenvalues and/or the invariant subspace.
48*>
49*> T must be in Schur canonical form (as returned by DHSEQR), that is,
50*> block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each
51*> 2-by-2 diagonal block has its diagonal elements equal and its
52*> off-diagonal elements of opposite sign.
53*> \endverbatim
54*
55* Arguments:
56* ==========
57*
58*> \param[in] JOB
59*> \verbatim
60*> JOB is CHARACTER*1
61*> Specifies whether condition numbers are required for the
62*> cluster of eigenvalues (S) or the invariant subspace (SEP):
63*> = 'N': none;
64*> = 'E': for eigenvalues only (S);
65*> = 'V': for invariant subspace only (SEP);
66*> = 'B': for both eigenvalues and invariant subspace (S and
67*> SEP).
68*> \endverbatim
69*>
70*> \param[in] COMPQ
71*> \verbatim
72*> COMPQ is CHARACTER*1
73*> = 'V': update the matrix Q of Schur vectors;
74*> = 'N': do not update Q.
75*> \endverbatim
76*>
77*> \param[in] SELECT
78*> \verbatim
79*> SELECT is LOGICAL array, dimension (N)
80*> SELECT specifies the eigenvalues in the selected cluster. To
81*> select a real eigenvalue w(j), SELECT(j) must be set to
82*> .TRUE.. To select a complex conjugate pair of eigenvalues
83*> w(j) and w(j+1), corresponding to a 2-by-2 diagonal block,
84*> either SELECT(j) or SELECT(j+1) or both must be set to
85*> .TRUE.; a complex conjugate pair of eigenvalues must be
86*> either both included in the cluster or both excluded.
87*> \endverbatim
88*>
89*> \param[in] N
90*> \verbatim
91*> N is INTEGER
92*> The order of the matrix T. N >= 0.
93*> \endverbatim
94*>
95*> \param[in,out] T
96*> \verbatim
97*> T is DOUBLE PRECISION array, dimension (LDT,N)
98*> On entry, the upper quasi-triangular matrix T, in Schur
99*> canonical form.
100*> On exit, T is overwritten by the reordered matrix T, again in
101*> Schur canonical form, with the selected eigenvalues in the
102*> leading diagonal blocks.
103*> \endverbatim
104*>
105*> \param[in] LDT
106*> \verbatim
107*> LDT is INTEGER
108*> The leading dimension of the array T. LDT >= max(1,N).
109*> \endverbatim
110*>
111*> \param[in,out] Q
112*> \verbatim
113*> Q is DOUBLE PRECISION array, dimension (LDQ,N)
114*> On entry, if COMPQ = 'V', the matrix Q of Schur vectors.
115*> On exit, if COMPQ = 'V', Q has been postmultiplied by the
116*> orthogonal transformation matrix which reorders T; the
117*> leading M columns of Q form an orthonormal basis for the
118*> specified invariant subspace.
119*> If COMPQ = 'N', Q is not referenced.
120*> \endverbatim
121*>
122*> \param[in] LDQ
123*> \verbatim
124*> LDQ is INTEGER
125*> The leading dimension of the array Q.
126*> LDQ >= 1; and if COMPQ = 'V', LDQ >= N.
127*> \endverbatim
128*>
129*> \param[out] WR
130*> \verbatim
131*> WR is DOUBLE PRECISION array, dimension (N)
132*> \endverbatim
133*> \param[out] WI
134*> \verbatim
135*> WI is DOUBLE PRECISION array, dimension (N)
136*>
137*> The real and imaginary parts, respectively, of the reordered
138*> eigenvalues of T. The eigenvalues are stored in the same
139*> order as on the diagonal of T, with WR(i) = T(i,i) and, if
140*> T(i:i+1,i:i+1) is a 2-by-2 diagonal block, WI(i) > 0 and
141*> WI(i+1) = -WI(i). Note that if a complex eigenvalue is
142*> sufficiently ill-conditioned, then its value may differ
143*> significantly from its value before reordering.
144*> \endverbatim
145*>
146*> \param[out] M
147*> \verbatim
148*> M is INTEGER
149*> The dimension of the specified invariant subspace.
150*> 0 < = M <= N.
151*> \endverbatim
152*>
153*> \param[out] S
154*> \verbatim
155*> S is DOUBLE PRECISION
156*> If JOB = 'E' or 'B', S is a lower bound on the reciprocal
157*> condition number for the selected cluster of eigenvalues.
158*> S cannot underestimate the true reciprocal condition number
159*> by more than a factor of sqrt(N). If M = 0 or N, S = 1.
160*> If JOB = 'N' or 'V', S is not referenced.
161*> \endverbatim
162*>
163*> \param[out] SEP
164*> \verbatim
165*> SEP is DOUBLE PRECISION
166*> If JOB = 'V' or 'B', SEP is the estimated reciprocal
167*> condition number of the specified invariant subspace. If
168*> M = 0 or N, SEP = norm(T).
169*> If JOB = 'N' or 'E', SEP is not referenced.
170*> \endverbatim
171*>
172*> \param[out] WORK
173*> \verbatim
174*> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
175*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
176*> \endverbatim
177*>
178*> \param[in] LWORK
179*> \verbatim
180*> LWORK is INTEGER
181*> The dimension of the array WORK.
182*> If JOB = 'N', LWORK >= max(1,N);
183*> if JOB = 'E', LWORK >= max(1,M*(N-M));
184*> if JOB = 'V' or 'B', LWORK >= max(1,2*M*(N-M)).
185*>
186*> If LWORK = -1, then a workspace query is assumed; the routine
187*> only calculates the optimal size of the WORK array, returns
188*> this value as the first entry of the WORK array, and no error
189*> message related to LWORK is issued by XERBLA.
190*> \endverbatim
191*>
192*> \param[out] IWORK
193*> \verbatim
194*> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
195*> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
196*> \endverbatim
197*>
198*> \param[in] LIWORK
199*> \verbatim
200*> LIWORK is INTEGER
201*> The dimension of the array IWORK.
202*> If JOB = 'N' or 'E', LIWORK >= 1;
203*> if JOB = 'V' or 'B', LIWORK >= max(1,M*(N-M)).
204*>
205*> If LIWORK = -1, then a workspace query is assumed; the
206*> routine only calculates the optimal size of the IWORK array,
207*> returns this value as the first entry of the IWORK array, and
208*> no error message related to LIWORK is issued by XERBLA.
209*> \endverbatim
210*>
211*> \param[out] INFO
212*> \verbatim
213*> INFO is INTEGER
214*> = 0: successful exit
215*> < 0: if INFO = -i, the i-th argument had an illegal value
216*> = 1: reordering of T failed because some eigenvalues are too
217*> close to separate (the problem is very ill-conditioned);
218*> T may have been partially reordered, and WR and WI
219*> contain the eigenvalues in the same order as in T; S and
220*> SEP (if requested) are set to zero.
221*> \endverbatim
222*
223* Authors:
224* ========
225*
226*> \author Univ. of Tennessee
227*> \author Univ. of California Berkeley
228*> \author Univ. of Colorado Denver
229*> \author NAG Ltd.
230*
231*> \ingroup trsen
232*
233*> \par Further Details:
234* =====================
235*>
236*> \verbatim
237*>
238*> DTRSEN first collects the selected eigenvalues by computing an
239*> orthogonal transformation Z to move them to the top left corner of T.
240*> In other words, the selected eigenvalues are the eigenvalues of T11
241*> in:
242*>
243*> Z**T * T * Z = ( T11 T12 ) n1
244*> ( 0 T22 ) n2
245*> n1 n2
246*>
247*> where N = n1+n2 and Z**T means the transpose of Z. The first n1 columns
248*> of Z span the specified invariant subspace of T.
249*>
250*> If T has been obtained from the real Schur factorization of a matrix
251*> A = Q*T*Q**T, then the reordered real Schur factorization of A is given
252*> by A = (Q*Z)*(Z**T*T*Z)*(Q*Z)**T, and the first n1 columns of Q*Z span
253*> the corresponding invariant subspace of A.
254*>
255*> The reciprocal condition number of the average of the eigenvalues of
256*> T11 may be returned in S. S lies between 0 (very badly conditioned)
257*> and 1 (very well conditioned). It is computed as follows. First we
258*> compute R so that
259*>
260*> P = ( I R ) n1
261*> ( 0 0 ) n2
262*> n1 n2
263*>
264*> is the projector on the invariant subspace associated with T11.
265*> R is the solution of the Sylvester equation:
266*>
267*> T11*R - R*T22 = T12.
268*>
269*> Let F-norm(M) denote the Frobenius-norm of M and 2-norm(M) denote
270*> the two-norm of M. Then S is computed as the lower bound
271*>
272*> (1 + F-norm(R)**2)**(-1/2)
273*>
274*> on the reciprocal of 2-norm(P), the true reciprocal condition number.
275*> S cannot underestimate 1 / 2-norm(P) by more than a factor of
276*> sqrt(N).
277*>
278*> An approximate error bound for the computed average of the
279*> eigenvalues of T11 is
280*>
281*> EPS * norm(T) / S
282*>
283*> where EPS is the machine precision.
284*>
285*> The reciprocal condition number of the right invariant subspace
286*> spanned by the first n1 columns of Z (or of Q*Z) is returned in SEP.
287*> SEP is defined as the separation of T11 and T22:
288*>
289*> sep( T11, T22 ) = sigma-min( C )
290*>
291*> where sigma-min(C) is the smallest singular value of the
292*> n1*n2-by-n1*n2 matrix
293*>
294*> C = kprod( I(n2), T11 ) - kprod( transpose(T22), I(n1) )
295*>
296*> I(m) is an m by m identity matrix, and kprod denotes the Kronecker
297*> product. We estimate sigma-min(C) by the reciprocal of an estimate of
298*> the 1-norm of inverse(C). The true reciprocal 1-norm of inverse(C)
299*> cannot differ from sigma-min(C) by more than a factor of sqrt(n1*n2).
300*>
301*> When SEP is small, small changes in T can cause large changes in
302*> the invariant subspace. An approximate bound on the maximum angular
303*> error in the computed right invariant subspace is
304*>
305*> EPS * norm(T) / SEP
306*> \endverbatim
307*>
308* =====================================================================
309 SUBROUTINE dtrsen( JOB, COMPQ, SELECT, N, T, LDT, Q, LDQ, WR,
310 $ WI,
311 $ M, S, SEP, WORK, LWORK, IWORK, LIWORK, INFO )
312*
313* -- LAPACK computational routine --
314* -- LAPACK is a software package provided by Univ. of Tennessee, --
315* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
316*
317* .. Scalar Arguments ..
318 CHARACTER COMPQ, JOB
319 INTEGER INFO, LDQ, LDT, LIWORK, LWORK, M, N
320 DOUBLE PRECISION S, SEP
321* ..
322* .. Array Arguments ..
323 LOGICAL SELECT( * )
324 INTEGER IWORK( * )
325 DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WI( * ), WORK( * ),
326 $ wr( * )
327* ..
328*
329* =====================================================================
330*
331* .. Parameters ..
332 DOUBLE PRECISION ZERO, ONE
333 PARAMETER ( ZERO = 0.0d+0, one = 1.0d+0 )
334* ..
335* .. Local Scalars ..
336 LOGICAL LQUERY, PAIR, SWAP, WANTBH, WANTQ, WANTS,
337 $ WANTSP
338 INTEGER IERR, K, KASE, KK, KS, LIWMIN, LWMIN, N1, N2,
339 $ NN
340 DOUBLE PRECISION EST, RNORM, SCALE
341* ..
342* .. Local Arrays ..
343 INTEGER ISAVE( 3 )
344* ..
345* .. External Functions ..
346 LOGICAL LSAME
347 DOUBLE PRECISION DLANGE
348 EXTERNAL lsame, dlange
349* ..
350* .. External Subroutines ..
351 EXTERNAL dlacn2, dlacpy, dtrexc, dtrsyl,
352 $ xerbla
353* ..
354* .. Intrinsic Functions ..
355 INTRINSIC abs, max, sqrt
356* ..
357* .. Executable Statements ..
358*
359* Decode and test the input parameters
360*
361 wantbh = lsame( job, 'B' )
362 wants = lsame( job, 'E' ) .OR. wantbh
363 wantsp = lsame( job, 'V' ) .OR. wantbh
364 wantq = lsame( compq, 'V' )
365*
366 info = 0
367 lquery = ( lwork.EQ.-1 )
368 IF( .NOT.lsame( job, 'N' ) .AND. .NOT.wants .AND. .NOT.wantsp )
369 $ THEN
370 info = -1
371 ELSE IF( .NOT.lsame( compq, 'N' ) .AND. .NOT.wantq ) THEN
372 info = -2
373 ELSE IF( n.LT.0 ) THEN
374 info = -4
375 ELSE IF( ldt.LT.max( 1, n ) ) THEN
376 info = -6
377 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) ) THEN
378 info = -8
379 ELSE
380*
381* Set M to the dimension of the specified invariant subspace,
382* and test LWORK and LIWORK.
383*
384 m = 0
385 pair = .false.
386 DO 10 k = 1, n
387 IF( pair ) THEN
388 pair = .false.
389 ELSE
390 IF( k.LT.n ) THEN
391 IF( t( k+1, k ).EQ.zero ) THEN
392 IF( SELECT( k ) )
393 $ m = m + 1
394 ELSE
395 pair = .true.
396 IF( SELECT( k ) .OR. SELECT( k+1 ) )
397 $ m = m + 2
398 END IF
399 ELSE
400 IF( SELECT( n ) )
401 $ m = m + 1
402 END IF
403 END IF
404 10 CONTINUE
405*
406 n1 = m
407 n2 = n - m
408 nn = n1*n2
409*
410 IF( wantsp ) THEN
411 lwmin = max( 1, 2*nn )
412 liwmin = max( 1, nn )
413 ELSE IF( lsame( job, 'N' ) ) THEN
414 lwmin = max( 1, n )
415 liwmin = 1
416 ELSE IF( lsame( job, 'E' ) ) THEN
417 lwmin = max( 1, nn )
418 liwmin = 1
419 END IF
420*
421 IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
422 info = -15
423 ELSE IF( liwork.LT.liwmin .AND. .NOT.lquery ) THEN
424 info = -17
425 END IF
426 END IF
427*
428 IF( info.EQ.0 ) THEN
429 work( 1 ) = lwmin
430 iwork( 1 ) = liwmin
431 END IF
432*
433 IF( info.NE.0 ) THEN
434 CALL xerbla( 'DTRSEN', -info )
435 RETURN
436 ELSE IF( lquery ) THEN
437 RETURN
438 END IF
439*
440* Quick return if possible.
441*
442 IF( m.EQ.n .OR. m.EQ.0 ) THEN
443 IF( wants )
444 $ s = one
445 IF( wantsp )
446 $ sep = dlange( '1', n, n, t, ldt, work )
447 GO TO 40
448 END IF
449*
450* Collect the selected blocks at the top-left corner of T.
451*
452 ks = 0
453 pair = .false.
454 DO 20 k = 1, n
455 IF( pair ) THEN
456 pair = .false.
457 ELSE
458 swap = SELECT( k )
459 IF( k.LT.n ) THEN
460 IF( t( k+1, k ).NE.zero ) THEN
461 pair = .true.
462 swap = swap .OR. SELECT( k+1 )
463 END IF
464 END IF
465 IF( swap ) THEN
466 ks = ks + 1
467*
468* Swap the K-th block to position KS.
469*
470 ierr = 0
471 kk = k
472 IF( k.NE.ks )
473 $ CALL dtrexc( compq, n, t, ldt, q, ldq, kk, ks,
474 $ work,
475 $ ierr )
476 IF( ierr.EQ.1 .OR. ierr.EQ.2 ) THEN
477*
478* Blocks too close to swap: exit.
479*
480 info = 1
481 IF( wants )
482 $ s = zero
483 IF( wantsp )
484 $ sep = zero
485 GO TO 40
486 END IF
487 IF( pair )
488 $ ks = ks + 1
489 END IF
490 END IF
491 20 CONTINUE
492*
493 IF( wants ) THEN
494*
495* Solve Sylvester equation for R:
496*
497* T11*R - R*T22 = scale*T12
498*
499 CALL dlacpy( 'F', n1, n2, t( 1, n1+1 ), ldt, work, n1 )
500 CALL dtrsyl( 'N', 'N', -1, n1, n2, t, ldt, t( n1+1, n1+1 ),
501 $ ldt, work, n1, scale, ierr )
502*
503* Estimate the reciprocal of the condition number of the cluster
504* of eigenvalues.
505*
506 rnorm = dlange( 'F', n1, n2, work, n1, work )
507 IF( rnorm.EQ.zero ) THEN
508 s = one
509 ELSE
510 s = scale / ( sqrt( scale*scale / rnorm+rnorm )*
511 $ sqrt( rnorm ) )
512 END IF
513 END IF
514*
515 IF( wantsp ) THEN
516*
517* Estimate sep(T11,T22).
518*
519 est = zero
520 kase = 0
521 30 CONTINUE
522 CALL dlacn2( nn, work( nn+1 ), work, iwork, est, kase,
523 $ isave )
524 IF( kase.NE.0 ) THEN
525 IF( kase.EQ.1 ) THEN
526*
527* Solve T11*R - R*T22 = scale*X.
528*
529 CALL dtrsyl( 'N', 'N', -1, n1, n2, t, ldt,
530 $ t( n1+1, n1+1 ), ldt, work, n1, scale,
531 $ ierr )
532 ELSE
533*
534* Solve T11**T*R - R*T22**T = scale*X.
535*
536 CALL dtrsyl( 'T', 'T', -1, n1, n2, t, ldt,
537 $ t( n1+1, n1+1 ), ldt, work, n1, scale,
538 $ ierr )
539 END IF
540 GO TO 30
541 END IF
542*
543 sep = scale / est
544 END IF
545*
546 40 CONTINUE
547*
548* Store the output eigenvalues in WR and WI.
549*
550 DO 50 k = 1, n
551 wr( k ) = t( k, k )
552 wi( k ) = zero
553 50 CONTINUE
554 DO 60 k = 1, n - 1
555 IF( t( k+1, k ).NE.zero ) THEN
556 wi( k ) = sqrt( abs( t( k, k+1 ) ) )*
557 $ sqrt( abs( t( k+1, k ) ) )
558 wi( k+1 ) = -wi( k )
559 END IF
560 60 CONTINUE
561*
562 work( 1 ) = lwmin
563 iwork( 1 ) = liwmin
564*
565 RETURN
566*
567* End of DTRSEN
568*
569 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine dlacn2(n, v, x, isgn, est, kase, isave)
DLACN2 estimates the 1-norm of a square matrix, using reverse communication for evaluating matrix-vec...
Definition dlacn2.f:134
subroutine dlacpy(uplo, m, n, a, lda, b, ldb)
DLACPY copies all or part of one two-dimensional array to another.
Definition dlacpy.f:101
subroutine dtrexc(compq, n, t, ldt, q, ldq, ifst, ilst, work, info)
DTREXC
Definition dtrexc.f:146
subroutine dtrsen(job, compq, select, n, t, ldt, q, ldq, wr, wi, m, s, sep, work, lwork, iwork, liwork, info)
DTRSEN
Definition dtrsen.f:312
subroutine dtrsyl(trana, tranb, isgn, m, n, a, lda, b, ldb, c, ldc, scale, info)
DTRSYL
Definition dtrsyl.f:162