LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cgees.f
Go to the documentation of this file.
1*> \brief <b> CGEES computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors for GE matrices</b>
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CGEES + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgees.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgees.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgees.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CGEES( JOBVS, SORT, SELECT, N, A, LDA, SDIM, W, VS,
20* LDVS, WORK, LWORK, RWORK, BWORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER JOBVS, SORT
24* INTEGER INFO, LDA, LDVS, LWORK, N, SDIM
25* ..
26* .. Array Arguments ..
27* LOGICAL BWORK( * )
28* REAL RWORK( * )
29* COMPLEX A( LDA, * ), VS( LDVS, * ), W( * ), WORK( * )
30* ..
31* .. Function Arguments ..
32* LOGICAL SELECT
33* EXTERNAL SELECT
34* ..
35*
36*
37*> \par Purpose:
38* =============
39*>
40*> \verbatim
41*>
42*> CGEES computes for an N-by-N complex nonsymmetric matrix A, the
43*> eigenvalues, the Schur form T, and, optionally, the matrix of Schur
44*> vectors Z. This gives the Schur factorization A = Z*T*(Z**H).
45*>
46*> Optionally, it also orders the eigenvalues on the diagonal of the
47*> Schur form so that selected eigenvalues are at the top left.
48*> The leading columns of Z then form an orthonormal basis for the
49*> invariant subspace corresponding to the selected eigenvalues.
50*>
51*> A complex matrix is in Schur form if it is upper triangular.
52*> \endverbatim
53*
54* Arguments:
55* ==========
56*
57*> \param[in] JOBVS
58*> \verbatim
59*> JOBVS is CHARACTER*1
60*> = 'N': Schur vectors are not computed;
61*> = 'V': Schur vectors are computed.
62*> \endverbatim
63*>
64*> \param[in] SORT
65*> \verbatim
66*> SORT is CHARACTER*1
67*> Specifies whether or not to order the eigenvalues on the
68*> diagonal of the Schur form.
69*> = 'N': Eigenvalues are not ordered:
70*> = 'S': Eigenvalues are ordered (see SELECT).
71*> \endverbatim
72*>
73*> \param[in] SELECT
74*> \verbatim
75*> SELECT is a LOGICAL FUNCTION of one COMPLEX argument
76*> SELECT must be declared EXTERNAL in the calling subroutine.
77*> If SORT = 'S', SELECT is used to select eigenvalues to order
78*> to the top left of the Schur form.
79*> IF SORT = 'N', SELECT is not referenced.
80*> The eigenvalue W(j) is selected if SELECT(W(j)) is true.
81*> \endverbatim
82*>
83*> \param[in] N
84*> \verbatim
85*> N is INTEGER
86*> The order of the matrix A. N >= 0.
87*> \endverbatim
88*>
89*> \param[in,out] A
90*> \verbatim
91*> A is COMPLEX array, dimension (LDA,N)
92*> On entry, the N-by-N matrix A.
93*> On exit, A has been overwritten by its Schur form T.
94*> \endverbatim
95*>
96*> \param[in] LDA
97*> \verbatim
98*> LDA is INTEGER
99*> The leading dimension of the array A. LDA >= max(1,N).
100*> \endverbatim
101*>
102*> \param[out] SDIM
103*> \verbatim
104*> SDIM is INTEGER
105*> If SORT = 'N', SDIM = 0.
106*> If SORT = 'S', SDIM = number of eigenvalues for which
107*> SELECT is true.
108*> \endverbatim
109*>
110*> \param[out] W
111*> \verbatim
112*> W is COMPLEX array, dimension (N)
113*> W contains the computed eigenvalues, in the same order that
114*> they appear on the diagonal of the output Schur form T.
115*> \endverbatim
116*>
117*> \param[out] VS
118*> \verbatim
119*> VS is COMPLEX array, dimension (LDVS,N)
120*> If JOBVS = 'V', VS contains the unitary matrix Z of Schur
121*> vectors.
122*> If JOBVS = 'N', VS is not referenced.
123*> \endverbatim
124*>
125*> \param[in] LDVS
126*> \verbatim
127*> LDVS is INTEGER
128*> The leading dimension of the array VS. LDVS >= 1; if
129*> JOBVS = 'V', LDVS >= N.
130*> \endverbatim
131*>
132*> \param[out] WORK
133*> \verbatim
134*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
135*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
136*> \endverbatim
137*>
138*> \param[in] LWORK
139*> \verbatim
140*> LWORK is INTEGER
141*> The dimension of the array WORK. LWORK >= max(1,2*N).
142*> For good performance, LWORK must generally be larger.
143*>
144*> If LWORK = -1, then a workspace query is assumed; the routine
145*> only calculates the optimal size of the WORK array, returns
146*> this value as the first entry of the WORK array, and no error
147*> message related to LWORK is issued by XERBLA.
148*> \endverbatim
149*>
150*> \param[out] RWORK
151*> \verbatim
152*> RWORK is REAL array, dimension (N)
153*> \endverbatim
154*>
155*> \param[out] BWORK
156*> \verbatim
157*> BWORK is LOGICAL array, dimension (N)
158*> Not referenced if SORT = 'N'.
159*> \endverbatim
160*>
161*> \param[out] INFO
162*> \verbatim
163*> INFO is INTEGER
164*> = 0: successful exit
165*> < 0: if INFO = -i, the i-th argument had an illegal value.
166*> > 0: if INFO = i, and i is
167*> <= N: the QR algorithm failed to compute all the
168*> eigenvalues; elements 1:ILO-1 and i+1:N of W
169*> contain those eigenvalues which have converged;
170*> if JOBVS = 'V', VS contains the matrix which
171*> reduces A to its partially converged Schur form.
172*> = N+1: the eigenvalues could not be reordered because
173*> some eigenvalues were too close to separate (the
174*> problem is very ill-conditioned);
175*> = N+2: after reordering, roundoff changed values of
176*> some complex eigenvalues so that leading
177*> eigenvalues in the Schur form no longer satisfy
178*> SELECT = .TRUE.. This could also be caused by
179*> underflow due to scaling.
180*> \endverbatim
181*
182* Authors:
183* ========
184*
185*> \author Univ. of Tennessee
186*> \author Univ. of California Berkeley
187*> \author Univ. of Colorado Denver
188*> \author NAG Ltd.
189*
190*> \ingroup gees
191*
192* =====================================================================
193 SUBROUTINE cgees( JOBVS, SORT, SELECT, N, A, LDA, SDIM, W, VS,
194 $ LDVS, WORK, LWORK, RWORK, BWORK, INFO )
195*
196* -- LAPACK driver routine --
197* -- LAPACK is a software package provided by Univ. of Tennessee, --
198* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
199*
200* .. Scalar Arguments ..
201 CHARACTER JOBVS, SORT
202 INTEGER INFO, LDA, LDVS, LWORK, N, SDIM
203* ..
204* .. Array Arguments ..
205 LOGICAL BWORK( * )
206 REAL RWORK( * )
207 COMPLEX A( LDA, * ), VS( LDVS, * ), W( * ), WORK( * )
208* ..
209* .. Function Arguments ..
210 LOGICAL SELECT
211 EXTERNAL SELECT
212* ..
213*
214* =====================================================================
215*
216* .. Parameters ..
217 REAL ZERO, ONE
218 parameter( zero = 0.0e0, one = 1.0e0 )
219* ..
220* .. Local Scalars ..
221 LOGICAL LQUERY, SCALEA, WANTST, WANTVS
222 INTEGER HSWORK, I, IBAL, ICOND, IERR, IEVAL, IHI, ILO,
223 $ itau, iwrk, maxwrk, minwrk
224 REAL ANRM, BIGNUM, CSCALE, EPS, S, SEP, SMLNUM
225* ..
226* .. Local Arrays ..
227 REAL DUM( 1 )
228* ..
229* .. External Subroutines ..
230 EXTERNAL ccopy, cgebak, cgebal, cgehrd, chseqr,
231 $ clacpy,
233* ..
234* .. External Functions ..
235 LOGICAL LSAME
236 INTEGER ILAENV
237 REAL CLANGE, SLAMCH, SROUNDUP_LWORK
238 EXTERNAL lsame, ilaenv, clange,
239 $ slamch, sroundup_lwork
240* ..
241* .. Intrinsic Functions ..
242 INTRINSIC max, sqrt
243* ..
244* .. Executable Statements ..
245*
246* Test the input arguments
247*
248 info = 0
249 lquery = ( lwork.EQ.-1 )
250 wantvs = lsame( jobvs, 'V' )
251 wantst = lsame( sort, 'S' )
252 IF( ( .NOT.wantvs ) .AND. ( .NOT.lsame( jobvs, 'N' ) ) ) THEN
253 info = -1
254 ELSE IF( ( .NOT.wantst ) .AND.
255 $ ( .NOT.lsame( sort, 'N' ) ) ) THEN
256 info = -2
257 ELSE IF( n.LT.0 ) THEN
258 info = -4
259 ELSE IF( lda.LT.max( 1, n ) ) THEN
260 info = -6
261 ELSE IF( ldvs.LT.1 .OR. ( wantvs .AND. ldvs.LT.n ) ) THEN
262 info = -10
263 END IF
264*
265* Compute workspace
266* (Note: Comments in the code beginning "Workspace:" describe the
267* minimal amount of workspace needed at that point in the code,
268* as well as the preferred amount for good performance.
269* CWorkspace refers to complex workspace, and RWorkspace to real
270* workspace. NB refers to the optimal block size for the
271* immediately following subroutine, as returned by ILAENV.
272* HSWORK refers to the workspace preferred by CHSEQR, as
273* calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
274* the worst case.)
275*
276 IF( info.EQ.0 ) THEN
277 IF( n.EQ.0 ) THEN
278 minwrk = 1
279 maxwrk = 1
280 ELSE
281 maxwrk = n + n*ilaenv( 1, 'CGEHRD', ' ', n, 1, n, 0 )
282 minwrk = 2*n
283*
284 CALL chseqr( 'S', jobvs, n, 1, n, a, lda, w, vs, ldvs,
285 $ work, -1, ieval )
286 hswork = int( work( 1 ) )
287*
288 IF( .NOT.wantvs ) THEN
289 maxwrk = max( maxwrk, hswork )
290 ELSE
291 maxwrk = max( maxwrk, n + ( n - 1 )*ilaenv( 1,
292 $ 'CUNGHR',
293 $ ' ', n, 1, n, -1 ) )
294 maxwrk = max( maxwrk, hswork )
295 END IF
296 END IF
297 work( 1 ) = sroundup_lwork(maxwrk)
298*
299 IF( lwork.LT.minwrk .AND. .NOT.lquery ) THEN
300 info = -12
301 END IF
302 END IF
303*
304 IF( info.NE.0 ) THEN
305 CALL xerbla( 'CGEES ', -info )
306 RETURN
307 ELSE IF( lquery ) THEN
308 RETURN
309 END IF
310*
311* Quick return if possible
312*
313 IF( n.EQ.0 ) THEN
314 sdim = 0
315 RETURN
316 END IF
317*
318* Get machine constants
319*
320 eps = slamch( 'P' )
321 smlnum = slamch( 'S' )
322 bignum = one / smlnum
323 smlnum = sqrt( smlnum ) / eps
324 bignum = one / smlnum
325*
326* Scale A if max element outside range [SMLNUM,BIGNUM]
327*
328 anrm = clange( 'M', n, n, a, lda, dum )
329 scalea = .false.
330 IF( anrm.GT.zero .AND. anrm.LT.smlnum ) THEN
331 scalea = .true.
332 cscale = smlnum
333 ELSE IF( anrm.GT.bignum ) THEN
334 scalea = .true.
335 cscale = bignum
336 END IF
337 IF( scalea )
338 $ CALL clascl( 'G', 0, 0, anrm, cscale, n, n, a, lda, ierr )
339*
340* Permute the matrix to make it more nearly triangular
341* (CWorkspace: none)
342* (RWorkspace: need N)
343*
344 ibal = 1
345 CALL cgebal( 'P', n, a, lda, ilo, ihi, rwork( ibal ), ierr )
346*
347* Reduce to upper Hessenberg form
348* (CWorkspace: need 2*N, prefer N+N*NB)
349* (RWorkspace: none)
350*
351 itau = 1
352 iwrk = n + itau
353 CALL cgehrd( n, ilo, ihi, a, lda, work( itau ), work( iwrk ),
354 $ lwork-iwrk+1, ierr )
355*
356 IF( wantvs ) THEN
357*
358* Copy Householder vectors to VS
359*
360 CALL clacpy( 'L', n, n, a, lda, vs, ldvs )
361*
362* Generate unitary matrix in VS
363* (CWorkspace: need 2*N-1, prefer N+(N-1)*NB)
364* (RWorkspace: none)
365*
366 CALL cunghr( n, ilo, ihi, vs, ldvs, work( itau ),
367 $ work( iwrk ),
368 $ lwork-iwrk+1, ierr )
369 END IF
370*
371 sdim = 0
372*
373* Perform QR iteration, accumulating Schur vectors in VS if desired
374* (CWorkspace: need 1, prefer HSWORK (see comments) )
375* (RWorkspace: none)
376*
377 iwrk = itau
378 CALL chseqr( 'S', jobvs, n, ilo, ihi, a, lda, w, vs, ldvs,
379 $ work( iwrk ), lwork-iwrk+1, ieval )
380 IF( ieval.GT.0 )
381 $ info = ieval
382*
383* Sort eigenvalues if desired
384*
385 IF( wantst .AND. info.EQ.0 ) THEN
386 IF( scalea )
387 $ CALL clascl( 'G', 0, 0, cscale, anrm, n, 1, w, n, ierr )
388 DO 10 i = 1, n
389 bwork( i ) = SELECT( w( i ) )
390 10 CONTINUE
391*
392* Reorder eigenvalues and transform Schur vectors
393* (CWorkspace: none)
394* (RWorkspace: none)
395*
396 CALL ctrsen( 'N', jobvs, bwork, n, a, lda, vs, ldvs, w,
397 $ sdim,
398 $ s, sep, work( iwrk ), lwork-iwrk+1, icond )
399 END IF
400*
401 IF( wantvs ) THEN
402*
403* Undo balancing
404* (CWorkspace: none)
405* (RWorkspace: need N)
406*
407 CALL cgebak( 'P', 'R', n, ilo, ihi, rwork( ibal ), n, vs,
408 $ ldvs,
409 $ ierr )
410 END IF
411*
412 IF( scalea ) THEN
413*
414* Undo scaling for the Schur form of A
415*
416 CALL clascl( 'U', 0, 0, cscale, anrm, n, n, a, lda, ierr )
417 CALL ccopy( n, a, lda+1, w, 1 )
418 END IF
419*
420 work( 1 ) = sroundup_lwork(maxwrk)
421 RETURN
422*
423* End of CGEES
424*
425 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
Definition ccopy.f:81
subroutine cgebak(job, side, n, ilo, ihi, scale, m, v, ldv, info)
CGEBAK
Definition cgebak.f:129
subroutine cgebal(job, n, a, lda, ilo, ihi, scale, info)
CGEBAL
Definition cgebal.f:163
subroutine cgees(jobvs, sort, select, n, a, lda, sdim, w, vs, ldvs, work, lwork, rwork, bwork, info)
CGEES computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors for GE m...
Definition cgees.f:195
subroutine cgehrd(n, ilo, ihi, a, lda, tau, work, lwork, info)
CGEHRD
Definition cgehrd.f:166
subroutine chseqr(job, compz, n, ilo, ihi, h, ldh, w, z, ldz, work, lwork, info)
CHSEQR
Definition chseqr.f:297
subroutine clacpy(uplo, m, n, a, lda, b, ldb)
CLACPY copies all or part of one two-dimensional array to another.
Definition clacpy.f:101
subroutine clascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
CLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
Definition clascl.f:142
subroutine ctrsen(job, compq, select, n, t, ldt, q, ldq, w, m, s, sep, work, lwork, info)
CTRSEN
Definition ctrsen.f:263
subroutine cunghr(n, ilo, ihi, a, lda, tau, work, lwork, info)
CUNGHR
Definition cunghr.f:125