LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cgeev.f
Go to the documentation of this file.
1*> \brief <b> CGEEV computes the eigenvalues and, optionally, the left and/or right eigenvectors 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 CGEEV + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeev.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeev.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeev.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CGEEV( JOBVL, JOBVR, N, A, LDA, W, VL, LDVL, VR, LDVR,
20* WORK, LWORK, RWORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER JOBVL, JOBVR
24* INTEGER INFO, LDA, LDVL, LDVR, LWORK, N
25* ..
26* .. Array Arguments ..
27* REAL RWORK( * )
28* COMPLEX A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
29* $ W( * ), WORK( * )
30* ..
31*
32*
33*> \par Purpose:
34* =============
35*>
36*> \verbatim
37*>
38*> CGEEV computes for an N-by-N complex nonsymmetric matrix A, the
39*> eigenvalues and, optionally, the left and/or right eigenvectors.
40*>
41*> The right eigenvector v(j) of A satisfies
42*> A * v(j) = lambda(j) * v(j)
43*> where lambda(j) is its eigenvalue.
44*> The left eigenvector u(j) of A satisfies
45*> u(j)**H * A = lambda(j) * u(j)**H
46*> where u(j)**H denotes the conjugate transpose of u(j).
47*>
48*> The computed eigenvectors are normalized to have Euclidean norm
49*> equal to 1 and largest component real.
50*> \endverbatim
51*
52* Arguments:
53* ==========
54*
55*> \param[in] JOBVL
56*> \verbatim
57*> JOBVL is CHARACTER*1
58*> = 'N': left eigenvectors of A are not computed;
59*> = 'V': left eigenvectors of are computed.
60*> \endverbatim
61*>
62*> \param[in] JOBVR
63*> \verbatim
64*> JOBVR is CHARACTER*1
65*> = 'N': right eigenvectors of A are not computed;
66*> = 'V': right eigenvectors of A are computed.
67*> \endverbatim
68*>
69*> \param[in] N
70*> \verbatim
71*> N is INTEGER
72*> The order of the matrix A. N >= 0.
73*> \endverbatim
74*>
75*> \param[in,out] A
76*> \verbatim
77*> A is COMPLEX array, dimension (LDA,N)
78*> On entry, the N-by-N matrix A.
79*> On exit, A has been overwritten.
80*> \endverbatim
81*>
82*> \param[in] LDA
83*> \verbatim
84*> LDA is INTEGER
85*> The leading dimension of the array A. LDA >= max(1,N).
86*> \endverbatim
87*>
88*> \param[out] W
89*> \verbatim
90*> W is COMPLEX array, dimension (N)
91*> W contains the computed eigenvalues.
92*> \endverbatim
93*>
94*> \param[out] VL
95*> \verbatim
96*> VL is COMPLEX array, dimension (LDVL,N)
97*> If JOBVL = 'V', the left eigenvectors u(j) are stored one
98*> after another in the columns of VL, in the same order
99*> as their eigenvalues.
100*> If JOBVL = 'N', VL is not referenced.
101*> u(j) = VL(:,j), the j-th column of VL.
102*> \endverbatim
103*>
104*> \param[in] LDVL
105*> \verbatim
106*> LDVL is INTEGER
107*> The leading dimension of the array VL. LDVL >= 1; if
108*> JOBVL = 'V', LDVL >= N.
109*> \endverbatim
110*>
111*> \param[out] VR
112*> \verbatim
113*> VR is COMPLEX array, dimension (LDVR,N)
114*> If JOBVR = 'V', the right eigenvectors v(j) are stored one
115*> after another in the columns of VR, in the same order
116*> as their eigenvalues.
117*> If JOBVR = 'N', VR is not referenced.
118*> v(j) = VR(:,j), the j-th column of VR.
119*> \endverbatim
120*>
121*> \param[in] LDVR
122*> \verbatim
123*> LDVR is INTEGER
124*> The leading dimension of the array VR. LDVR >= 1; if
125*> JOBVR = 'V', LDVR >= N.
126*> \endverbatim
127*>
128*> \param[out] WORK
129*> \verbatim
130*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
131*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
132*> \endverbatim
133*>
134*> \param[in] LWORK
135*> \verbatim
136*> LWORK is INTEGER
137*> The dimension of the array WORK. LWORK >= max(1,2*N).
138*> For good performance, LWORK must generally be larger.
139*>
140*> If LWORK = -1, then a workspace query is assumed; the routine
141*> only calculates the optimal size of the WORK array, returns
142*> this value as the first entry of the WORK array, and no error
143*> message related to LWORK is issued by XERBLA.
144*> \endverbatim
145*>
146*> \param[out] RWORK
147*> \verbatim
148*> RWORK is REAL array, dimension (2*N)
149*> \endverbatim
150*>
151*> \param[out] INFO
152*> \verbatim
153*> INFO is INTEGER
154*> = 0: successful exit
155*> < 0: if INFO = -i, the i-th argument had an illegal value.
156*> > 0: if INFO = i, the QR algorithm failed to compute all the
157*> eigenvalues, and no eigenvectors have been computed;
158*> elements i+1:N of W contain eigenvalues which have
159*> converged.
160*> \endverbatim
161*
162* Authors:
163* ========
164*
165*> \author Univ. of Tennessee
166*> \author Univ. of California Berkeley
167*> \author Univ. of Colorado Denver
168*> \author NAG Ltd.
169*
170*
171* @generated from zgeev.f, fortran z -> c, Tue Apr 19 01:47:44 2016
172*
173*> \ingroup geev
174*
175* =====================================================================
176 SUBROUTINE cgeev( JOBVL, JOBVR, N, A, LDA, W, VL, LDVL, VR,
177 $ LDVR,
178 $ WORK, LWORK, RWORK, INFO )
179 implicit none
180*
181* -- LAPACK driver routine --
182* -- LAPACK is a software package provided by Univ. of Tennessee, --
183* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
184*
185* .. Scalar Arguments ..
186 CHARACTER JOBVL, JOBVR
187 INTEGER INFO, LDA, LDVL, LDVR, LWORK, N
188* ..
189* .. Array Arguments ..
190 REAL RWORK( * )
191 COMPLEX A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
192 $ w( * ), work( * )
193* ..
194*
195* =====================================================================
196*
197* .. Parameters ..
198 REAL ZERO, ONE
199 PARAMETER ( ZERO = 0.0e0, one = 1.0e0 )
200* ..
201* .. Local Scalars ..
202 LOGICAL LQUERY, SCALEA, WANTVL, WANTVR
203 CHARACTER SIDE
204 INTEGER HSWORK, I, IBAL, IERR, IHI, ILO, IRWORK, ITAU,
205 $ iwrk, k, lwork_trevc, maxwrk, minwrk, nout
206 REAL ANRM, BIGNUM, CSCALE, EPS, SCL, SMLNUM
207 COMPLEX TMP
208* ..
209* .. Local Arrays ..
210 LOGICAL SELECT( 1 )
211 REAL DUM( 1 )
212* ..
213* .. External Subroutines ..
214 EXTERNAL xerbla, csscal, cgebak,
215 $ cgebal, cgehrd, chseqr,
216 $ clacpy, clascl, cscal,
217 $ ctrevc3, cunghr
218* ..
219* .. External Functions ..
220 LOGICAL LSAME
221 INTEGER ISAMAX, ILAENV
222 REAL SLAMCH, SCNRM2, CLANGE,
224 EXTERNAL lsame, isamax, ilaenv,
225 $ slamch, scnrm2, clange,
227* ..
228* .. Intrinsic Functions ..
229 INTRINSIC real, cmplx, conjg, aimag, max, sqrt
230* ..
231* .. Executable Statements ..
232*
233* Test the input arguments
234*
235 info = 0
236 lquery = ( lwork.EQ.-1 )
237 wantvl = lsame( jobvl, 'V' )
238 wantvr = lsame( jobvr, 'V' )
239 IF( ( .NOT.wantvl ) .AND. ( .NOT.lsame( jobvl, 'N' ) ) ) THEN
240 info = -1
241 ELSE IF( ( .NOT.wantvr ) .AND.
242 $ ( .NOT.lsame( jobvr, 'N' ) ) ) THEN
243 info = -2
244 ELSE IF( n.LT.0 ) THEN
245 info = -3
246 ELSE IF( lda.LT.max( 1, n ) ) THEN
247 info = -5
248 ELSE IF( ldvl.LT.1 .OR. ( wantvl .AND. ldvl.LT.n ) ) THEN
249 info = -8
250 ELSE IF( ldvr.LT.1 .OR. ( wantvr .AND. ldvr.LT.n ) ) THEN
251 info = -10
252 END IF
253*
254* Compute workspace
255* (Note: Comments in the code beginning "Workspace:" describe the
256* minimal amount of workspace needed at that point in the code,
257* as well as the preferred amount for good performance.
258* CWorkspace refers to complex workspace, and RWorkspace to real
259* workspace. NB refers to the optimal block size for the
260* immediately following subroutine, as returned by ILAENV.
261* HSWORK refers to the workspace preferred by CHSEQR, as
262* calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
263* the worst case.)
264*
265 IF( info.EQ.0 ) THEN
266 IF( n.EQ.0 ) THEN
267 minwrk = 1
268 maxwrk = 1
269 ELSE
270 maxwrk = n + n*ilaenv( 1, 'CGEHRD', ' ', n, 1, n, 0 )
271 minwrk = 2*n
272 IF( wantvl ) THEN
273 maxwrk = max( maxwrk, n + ( n - 1 )*ilaenv( 1,
274 $ 'CUNGHR',
275 $ ' ', n, 1, n, -1 ) )
276 CALL ctrevc3( 'L', 'B', SELECT, n, a, lda,
277 $ vl, ldvl, vr, ldvr,
278 $ n, nout, work, -1, rwork, -1, ierr )
279 lwork_trevc = int( work(1) )
280 maxwrk = max( maxwrk, n + lwork_trevc )
281 CALL chseqr( 'S', 'V', n, 1, n, a, lda, w, vl, ldvl,
282 $ work, -1, info )
283 ELSE IF( wantvr ) THEN
284 maxwrk = max( maxwrk, n + ( n - 1 )*ilaenv( 1,
285 $ 'CUNGHR',
286 $ ' ', n, 1, n, -1 ) )
287 CALL ctrevc3( 'R', 'B', SELECT, n, a, lda,
288 $ vl, ldvl, vr, ldvr,
289 $ n, nout, work, -1, rwork, -1, ierr )
290 lwork_trevc = int( work(1) )
291 maxwrk = max( maxwrk, n + lwork_trevc )
292 CALL chseqr( 'S', 'V', n, 1, n, a, lda, w, vr, ldvr,
293 $ work, -1, info )
294 ELSE
295 CALL chseqr( 'E', 'N', n, 1, n, a, lda, w, vr, ldvr,
296 $ work, -1, info )
297 END IF
298 hswork = int( work(1) )
299 maxwrk = max( maxwrk, hswork, minwrk )
300 END IF
301 work( 1 ) = sroundup_lwork(maxwrk)
302*
303 IF( lwork.LT.minwrk .AND. .NOT.lquery ) THEN
304 info = -12
305 END IF
306 END IF
307*
308 IF( info.NE.0 ) THEN
309 CALL xerbla( 'CGEEV ', -info )
310 RETURN
311 ELSE IF( lquery ) THEN
312 RETURN
313 END IF
314*
315* Quick return if possible
316*
317 IF( n.EQ.0 )
318 $ RETURN
319*
320* Get machine constants
321*
322 eps = slamch( 'P' )
323 smlnum = slamch( 'S' )
324 bignum = one / smlnum
325 smlnum = sqrt( smlnum ) / eps
326 bignum = one / smlnum
327*
328* Scale A if max element outside range [SMLNUM,BIGNUM]
329*
330 anrm = clange( 'M', n, n, a, lda, dum )
331 scalea = .false.
332 IF( anrm.GT.zero .AND. anrm.LT.smlnum ) THEN
333 scalea = .true.
334 cscale = smlnum
335 ELSE IF( anrm.GT.bignum ) THEN
336 scalea = .true.
337 cscale = bignum
338 END IF
339 IF( scalea )
340 $ CALL clascl( 'G', 0, 0, anrm, cscale, n, n, a, lda, ierr )
341*
342* Balance the matrix
343* (CWorkspace: none)
344* (RWorkspace: need N)
345*
346 ibal = 1
347 CALL cgebal( 'B', n, a, lda, ilo, ihi, rwork( ibal ), ierr )
348*
349* Reduce to upper Hessenberg form
350* (CWorkspace: need 2*N, prefer N+N*NB)
351* (RWorkspace: none)
352*
353 itau = 1
354 iwrk = itau + n
355 CALL cgehrd( n, ilo, ihi, a, lda, work( itau ), work( iwrk ),
356 $ lwork-iwrk+1, ierr )
357*
358 IF( wantvl ) THEN
359*
360* Want left eigenvectors
361* Copy Householder vectors to VL
362*
363 side = 'L'
364 CALL clacpy( 'L', n, n, a, lda, vl, ldvl )
365*
366* Generate unitary matrix in VL
367* (CWorkspace: need 2*N-1, prefer N+(N-1)*NB)
368* (RWorkspace: none)
369*
370 CALL cunghr( n, ilo, ihi, vl, ldvl, work( itau ),
371 $ work( iwrk ),
372 $ lwork-iwrk+1, ierr )
373*
374* Perform QR iteration, accumulating Schur vectors in VL
375* (CWorkspace: need 1, prefer HSWORK (see comments) )
376* (RWorkspace: none)
377*
378 iwrk = itau
379 CALL chseqr( 'S', 'V', n, ilo, ihi, a, lda, w, vl, ldvl,
380 $ work( iwrk ), lwork-iwrk+1, info )
381*
382 IF( wantvr ) THEN
383*
384* Want left and right eigenvectors
385* Copy Schur vectors to VR
386*
387 side = 'B'
388 CALL clacpy( 'F', n, n, vl, ldvl, vr, ldvr )
389 END IF
390*
391 ELSE IF( wantvr ) THEN
392*
393* Want right eigenvectors
394* Copy Householder vectors to VR
395*
396 side = 'R'
397 CALL clacpy( 'L', n, n, a, lda, vr, ldvr )
398*
399* Generate unitary matrix in VR
400* (CWorkspace: need 2*N-1, prefer N+(N-1)*NB)
401* (RWorkspace: none)
402*
403 CALL cunghr( n, ilo, ihi, vr, ldvr, work( itau ),
404 $ work( iwrk ),
405 $ lwork-iwrk+1, ierr )
406*
407* Perform QR iteration, accumulating Schur vectors in VR
408* (CWorkspace: need 1, prefer HSWORK (see comments) )
409* (RWorkspace: none)
410*
411 iwrk = itau
412 CALL chseqr( 'S', 'V', n, ilo, ihi, a, lda, w, vr, ldvr,
413 $ work( iwrk ), lwork-iwrk+1, info )
414*
415 ELSE
416*
417* Compute eigenvalues only
418* (CWorkspace: need 1, prefer HSWORK (see comments) )
419* (RWorkspace: none)
420*
421 iwrk = itau
422 CALL chseqr( 'E', 'N', n, ilo, ihi, a, lda, w, vr, ldvr,
423 $ work( iwrk ), lwork-iwrk+1, info )
424 END IF
425*
426* If INFO .NE. 0 from CHSEQR, then quit
427*
428 IF( info.NE.0 )
429 $ GO TO 50
430*
431 IF( wantvl .OR. wantvr ) THEN
432*
433* Compute left and/or right eigenvectors
434* (CWorkspace: need 2*N, prefer N + 2*N*NB)
435* (RWorkspace: need 2*N)
436*
437 irwork = ibal + n
438 CALL ctrevc3( side, 'B', SELECT, n, a, lda, vl, ldvl, vr,
439 $ ldvr,
440 $ n, nout, work( iwrk ), lwork-iwrk+1,
441 $ rwork( irwork ), n, ierr )
442 END IF
443*
444 IF( wantvl ) THEN
445*
446* Undo balancing of left eigenvectors
447* (CWorkspace: none)
448* (RWorkspace: need N)
449*
450 CALL cgebak( 'B', 'L', n, ilo, ihi, rwork( ibal ), n, vl,
451 $ ldvl,
452 $ ierr )
453*
454* Normalize left eigenvectors and make largest component real
455*
456 DO 20 i = 1, n
457 scl = one / scnrm2( n, vl( 1, i ), 1 )
458 CALL csscal( n, scl, vl( 1, i ), 1 )
459 DO 10 k = 1, n
460 rwork( irwork+k-1 ) = real( vl( k, i ) )**2 +
461 $ aimag( vl( k, i ) )**2
462 10 CONTINUE
463 k = isamax( n, rwork( irwork ), 1 )
464 tmp = conjg( vl( k, i ) ) / sqrt( rwork( irwork+k-1 ) )
465 CALL cscal( n, tmp, vl( 1, i ), 1 )
466 vl( k, i ) = cmplx( real( vl( k, i ) ), zero )
467 20 CONTINUE
468 END IF
469*
470 IF( wantvr ) THEN
471*
472* Undo balancing of right eigenvectors
473* (CWorkspace: none)
474* (RWorkspace: need N)
475*
476 CALL cgebak( 'B', 'R', n, ilo, ihi, rwork( ibal ), n, vr,
477 $ ldvr,
478 $ ierr )
479*
480* Normalize right eigenvectors and make largest component real
481*
482 DO 40 i = 1, n
483 scl = one / scnrm2( n, vr( 1, i ), 1 )
484 CALL csscal( n, scl, vr( 1, i ), 1 )
485 DO 30 k = 1, n
486 rwork( irwork+k-1 ) = real( vr( k, i ) )**2 +
487 $ aimag( vr( k, i ) )**2
488 30 CONTINUE
489 k = isamax( n, rwork( irwork ), 1 )
490 tmp = conjg( vr( k, i ) ) / sqrt( rwork( irwork+k-1 ) )
491 CALL cscal( n, tmp, vr( 1, i ), 1 )
492 vr( k, i ) = cmplx( real( vr( k, i ) ), zero )
493 40 CONTINUE
494 END IF
495*
496* Undo scaling if necessary
497*
498 50 CONTINUE
499 IF( scalea ) THEN
500 CALL clascl( 'G', 0, 0, cscale, anrm, n-info, 1,
501 $ w( info+1 ),
502 $ max( n-info, 1 ), ierr )
503 IF( info.GT.0 ) THEN
504 CALL clascl( 'G', 0, 0, cscale, anrm, ilo-1, 1, w, n,
505 $ ierr )
506 END IF
507 END IF
508*
509 work( 1 ) = sroundup_lwork(maxwrk)
510 RETURN
511*
512* End of CGEEV
513*
514 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
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 cgeev(jobvl, jobvr, n, a, lda, w, vl, ldvl, vr, ldvr, work, lwork, rwork, info)
CGEEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices
Definition cgeev.f:179
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
real function sroundup_lwork(lwork)
SROUNDUP_LWORK
subroutine csscal(n, sa, cx, incx)
CSSCAL
Definition csscal.f:78
subroutine cscal(n, ca, cx, incx)
CSCAL
Definition cscal.f:78
subroutine ctrevc3(side, howmny, select, n, t, ldt, vl, ldvl, vr, ldvr, mm, m, work, lwork, rwork, lrwork, info)
CTREVC3
Definition ctrevc3.f:243
subroutine cunghr(n, ilo, ihi, a, lda, tau, work, lwork, info)
CUNGHR
Definition cunghr.f:125