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