LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cggev3.f
Go to the documentation of this file.
1*> \brief <b> CGGEV3 computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices (blocked algorithm)</b>
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CGGEV3 + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggev3.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggev3.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggev3.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CGGEV3( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA, BETA,
20* $ VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER JOBVL, JOBVR
24* INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
25* ..
26* .. Array Arguments ..
27* REAL RWORK( * )
28* COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
29* $ BETA( * ), VL( LDVL, * ), VR( LDVR, * ),
30* $ WORK( * )
31* ..
32*
33*
34*> \par Purpose:
35* =============
36*>
37*> \verbatim
38*>
39*> CGGEV3 computes for a pair of N-by-N complex nonsymmetric matrices
40*> (A,B), the generalized eigenvalues, and optionally, the left and/or
41*> right generalized eigenvectors.
42*>
43*> A generalized eigenvalue for a pair of matrices (A,B) is a scalar
44*> lambda or a ratio alpha/beta = lambda, such that A - lambda*B is
45*> singular. It is usually represented as the pair (alpha,beta), as
46*> there is a reasonable interpretation for beta=0, and even for both
47*> being zero.
48*>
49*> The right generalized eigenvector v(j) corresponding to the
50*> generalized eigenvalue lambda(j) of (A,B) satisfies
51*>
52*> A * v(j) = lambda(j) * B * v(j).
53*>
54*> The left generalized eigenvector u(j) corresponding to the
55*> generalized eigenvalues lambda(j) of (A,B) satisfies
56*>
57*> u(j)**H * A = lambda(j) * u(j)**H * B
58*>
59*> where u(j)**H is the conjugate-transpose of u(j).
60*> \endverbatim
61*
62* Arguments:
63* ==========
64*
65*> \param[in] JOBVL
66*> \verbatim
67*> JOBVL is CHARACTER*1
68*> = 'N': do not compute the left generalized eigenvectors;
69*> = 'V': compute the left generalized eigenvectors.
70*> \endverbatim
71*>
72*> \param[in] JOBVR
73*> \verbatim
74*> JOBVR is CHARACTER*1
75*> = 'N': do not compute the right generalized eigenvectors;
76*> = 'V': compute the right generalized eigenvectors.
77*> \endverbatim
78*>
79*> \param[in] N
80*> \verbatim
81*> N is INTEGER
82*> The order of the matrices A, B, VL, and VR. N >= 0.
83*> \endverbatim
84*>
85*> \param[in,out] A
86*> \verbatim
87*> A is COMPLEX array, dimension (LDA, N)
88*> On entry, the matrix A in the pair (A,B).
89*> On exit, A has been overwritten.
90*> \endverbatim
91*>
92*> \param[in] LDA
93*> \verbatim
94*> LDA is INTEGER
95*> The leading dimension of A. LDA >= max(1,N).
96*> \endverbatim
97*>
98*> \param[in,out] B
99*> \verbatim
100*> B is COMPLEX array, dimension (LDB, N)
101*> On entry, the matrix B in the pair (A,B).
102*> On exit, B has been overwritten.
103*> \endverbatim
104*>
105*> \param[in] LDB
106*> \verbatim
107*> LDB is INTEGER
108*> The leading dimension of B. LDB >= max(1,N).
109*> \endverbatim
110*>
111*> \param[out] ALPHA
112*> \verbatim
113*> ALPHA is COMPLEX array, dimension (N)
114*> \endverbatim
115*>
116*> \param[out] BETA
117*> \verbatim
118*> BETA is COMPLEX array, dimension (N)
119*> On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the
120*> generalized eigenvalues.
121*>
122*> Note: the quotients ALPHA(j)/BETA(j) may easily over- or
123*> underflow, and BETA(j) may even be zero. Thus, the user
124*> should avoid naively computing the ratio alpha/beta.
125*> However, ALPHA will be always less than and usually
126*> comparable with norm(A) in magnitude, and BETA always less
127*> than and usually comparable with norm(B).
128*> \endverbatim
129*>
130*> \param[out] VL
131*> \verbatim
132*> VL is COMPLEX array, dimension (LDVL,N)
133*> If JOBVL = 'V', the left generalized eigenvectors u(j) are
134*> stored one after another in the columns of VL, in the same
135*> order as their eigenvalues.
136*> Each eigenvector is scaled so the largest component has
137*> abs(real part) + abs(imag. part) = 1.
138*> Not referenced if JOBVL = 'N'.
139*> \endverbatim
140*>
141*> \param[in] LDVL
142*> \verbatim
143*> LDVL is INTEGER
144*> The leading dimension of the matrix VL. LDVL >= 1, and
145*> if JOBVL = 'V', LDVL >= N.
146*> \endverbatim
147*>
148*> \param[out] VR
149*> \verbatim
150*> VR is COMPLEX array, dimension (LDVR,N)
151*> If JOBVR = 'V', the right generalized eigenvectors v(j) are
152*> stored one after another in the columns of VR, in the same
153*> order as their eigenvalues.
154*> Each eigenvector is scaled so the largest component has
155*> abs(real part) + abs(imag. part) = 1.
156*> Not referenced if JOBVR = 'N'.
157*> \endverbatim
158*>
159*> \param[in] LDVR
160*> \verbatim
161*> LDVR is INTEGER
162*> The leading dimension of the matrix VR. LDVR >= 1, and
163*> if JOBVR = 'V', LDVR >= N.
164*> \endverbatim
165*>
166*> \param[out] WORK
167*> \verbatim
168*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
169*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
170*> \endverbatim
171*>
172*> \param[in] LWORK
173*> \verbatim
174*> LWORK is INTEGER
175*> The dimension of the array WORK. LWORK >= MAX(1,2*N).
176*> For good performance, LWORK must generally be larger.
177*>
178*> If LWORK = -1, then a workspace query is assumed; the routine
179*> only calculates the optimal size of the WORK array, returns
180*> this value as the first entry of the WORK array, and no error
181*> message related to LWORK is issued by XERBLA.
182*> \endverbatim
183*>
184*> \param[out] RWORK
185*> \verbatim
186*> RWORK is REAL array, dimension (8*N)
187*> \endverbatim
188*>
189*> \param[out] INFO
190*> \verbatim
191*> INFO is INTEGER
192*> = 0: successful exit
193*> < 0: if INFO = -i, the i-th argument had an illegal value.
194*> =1,...,N:
195*> The QZ iteration failed. No eigenvectors have been
196*> calculated, but ALPHA(j) and BETA(j) should be
197*> correct for j=INFO+1,...,N.
198*> > N: =N+1: other then QZ iteration failed in CHGEQZ,
199*> =N+2: error return from CTGEVC.
200*> \endverbatim
201*
202* Authors:
203* ========
204*
205*> \author Univ. of Tennessee
206*> \author Univ. of California Berkeley
207*> \author Univ. of Colorado Denver
208*> \author NAG Ltd.
209*
210*> \ingroup ggev3
211*
212* =====================================================================
213 SUBROUTINE cggev3( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA,
214 $ BETA,
215 $ VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO )
216*
217* -- LAPACK driver routine --
218* -- LAPACK is a software package provided by Univ. of Tennessee, --
219* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
220*
221* .. Scalar Arguments ..
222 CHARACTER JOBVL, JOBVR
223 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
224* ..
225* .. Array Arguments ..
226 REAL RWORK( * )
227 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
228 $ beta( * ), vl( ldvl, * ), vr( ldvr, * ),
229 $ work( * )
230* ..
231*
232* =====================================================================
233*
234* .. Parameters ..
235 REAL ZERO, ONE
236 PARAMETER ( ZERO = 0.0e0, one = 1.0e0 )
237 COMPLEX CZERO, CONE
238 parameter( czero = ( 0.0e0, 0.0e0 ),
239 $ cone = ( 1.0e0, 0.0e0 ) )
240* ..
241* .. Local Scalars ..
242 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY
243 CHARACTER CHTEMP
244 INTEGER ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, ILO,
245 $ in, iright, irows, irwrk, itau, iwrk, jc, jr,
246 $ lwkopt, lwkmin
247 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
248 $ SMLNUM, TEMP
249 COMPLEX X
250* ..
251* .. Local Arrays ..
252 LOGICAL LDUMMA( 1 )
253* ..
254* .. External Subroutines ..
255 EXTERNAL cgeqrf, cggbak, cggbal, cgghd3, claqz0,
256 $ clacpy,
258* ..
259* .. External Functions ..
260 LOGICAL LSAME
261 REAL CLANGE, SLAMCH, SROUNDUP_LWORK
262 EXTERNAL lsame, clange, slamch,
263 $ sroundup_lwork
264* ..
265* .. Intrinsic Functions ..
266 INTRINSIC abs, aimag, max, real, sqrt
267* ..
268* .. Statement Functions ..
269 REAL ABS1
270* ..
271* .. Statement Function definitions ..
272 abs1( x ) = abs( real( x ) ) + abs( aimag( x ) )
273* ..
274* .. Executable Statements ..
275*
276* Decode the input arguments
277*
278 IF( lsame( jobvl, 'N' ) ) THEN
279 ijobvl = 1
280 ilvl = .false.
281 ELSE IF( lsame( jobvl, 'V' ) ) THEN
282 ijobvl = 2
283 ilvl = .true.
284 ELSE
285 ijobvl = -1
286 ilvl = .false.
287 END IF
288*
289 IF( lsame( jobvr, 'N' ) ) THEN
290 ijobvr = 1
291 ilvr = .false.
292 ELSE IF( lsame( jobvr, 'V' ) ) THEN
293 ijobvr = 2
294 ilvr = .true.
295 ELSE
296 ijobvr = -1
297 ilvr = .false.
298 END IF
299 ilv = ilvl .OR. ilvr
300*
301* Test the input arguments
302*
303 info = 0
304 lquery = ( lwork.EQ.-1 )
305 lwkmin = max( 1, 2*n )
306 IF( ijobvl.LE.0 ) THEN
307 info = -1
308 ELSE IF( ijobvr.LE.0 ) THEN
309 info = -2
310 ELSE IF( n.LT.0 ) THEN
311 info = -3
312 ELSE IF( lda.LT.max( 1, n ) ) THEN
313 info = -5
314 ELSE IF( ldb.LT.max( 1, n ) ) THEN
315 info = -7
316 ELSE IF( ldvl.LT.1 .OR. ( ilvl .AND. ldvl.LT.n ) ) THEN
317 info = -11
318 ELSE IF( ldvr.LT.1 .OR. ( ilvr .AND. ldvr.LT.n ) ) THEN
319 info = -13
320 ELSE IF( lwork.LT.lwkmin .AND. .NOT.lquery ) THEN
321 info = -15
322 END IF
323*
324* Compute workspace
325*
326 IF( info.EQ.0 ) THEN
327 CALL cgeqrf( n, n, b, ldb, work, work, -1, ierr )
328 lwkopt = max( lwkmin, n+int( work( 1 ) ) )
329 CALL cunmqr( 'L', 'C', n, n, n, b, ldb, work, a, lda, work,
330 $ -1, ierr )
331 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
332 IF( ilvl ) THEN
333 CALL cungqr( n, n, n, vl, ldvl, work, work, -1, ierr )
334 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
335 END IF
336 IF( ilv ) THEN
337 CALL cgghd3( jobvl, jobvr, n, 1, n, a, lda, b, ldb, vl,
338 $ ldvl, vr, ldvr, work, -1, ierr )
339 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
340 CALL claqz0( 'S', jobvl, jobvr, n, 1, n, a, lda, b, ldb,
341 $ alpha, beta, vl, ldvl, vr, ldvr, work, -1,
342 $ rwork, 0, ierr )
343 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
344 ELSE
345 CALL cgghd3( 'N', 'N', n, 1, n, a, lda, b, ldb, vl, ldvl,
346 $ vr, ldvr, work, -1, ierr )
347 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
348 CALL claqz0( 'E', jobvl, jobvr, n, 1, n, a, lda, b, ldb,
349 $ alpha, beta, vl, ldvl, vr, ldvr, work, -1,
350 $ rwork, 0, ierr )
351 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
352 END IF
353 IF( n.EQ.0 ) THEN
354 work( 1 ) = 1
355 ELSE
356 work( 1 ) = sroundup_lwork( lwkopt )
357 END IF
358 END IF
359*
360 IF( info.NE.0 ) THEN
361 CALL xerbla( 'CGGEV3 ', -info )
362 RETURN
363 ELSE IF( lquery ) THEN
364 RETURN
365 END IF
366*
367* Quick return if possible
368*
369 IF( n.EQ.0 )
370 $ RETURN
371*
372* Get machine constants
373*
374 eps = slamch( 'E' )*slamch( 'B' )
375 smlnum = slamch( 'S' )
376 bignum = one / smlnum
377 smlnum = sqrt( smlnum ) / eps
378 bignum = one / smlnum
379*
380* Scale A if max element outside range [SMLNUM,BIGNUM]
381*
382 anrm = clange( 'M', n, n, a, lda, rwork )
383 ilascl = .false.
384 IF( anrm.GT.zero .AND. anrm.LT.smlnum ) THEN
385 anrmto = smlnum
386 ilascl = .true.
387 ELSE IF( anrm.GT.bignum ) THEN
388 anrmto = bignum
389 ilascl = .true.
390 END IF
391 IF( ilascl )
392 $ CALL clascl( 'G', 0, 0, anrm, anrmto, n, n, a, lda, ierr )
393*
394* Scale B if max element outside range [SMLNUM,BIGNUM]
395*
396 bnrm = clange( 'M', n, n, b, ldb, rwork )
397 ilbscl = .false.
398 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum ) THEN
399 bnrmto = smlnum
400 ilbscl = .true.
401 ELSE IF( bnrm.GT.bignum ) THEN
402 bnrmto = bignum
403 ilbscl = .true.
404 END IF
405 IF( ilbscl )
406 $ CALL clascl( 'G', 0, 0, bnrm, bnrmto, n, n, b, ldb, ierr )
407*
408* Permute the matrices A, B to isolate eigenvalues if possible
409*
410 ileft = 1
411 iright = n + 1
412 irwrk = iright + n
413 CALL cggbal( 'P', n, a, lda, b, ldb, ilo, ihi, rwork( ileft ),
414 $ rwork( iright ), rwork( irwrk ), ierr )
415*
416* Reduce B to triangular form (QR decomposition of B)
417*
418 irows = ihi + 1 - ilo
419 IF( ilv ) THEN
420 icols = n + 1 - ilo
421 ELSE
422 icols = irows
423 END IF
424 itau = 1
425 iwrk = itau + irows
426 CALL cgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
427 $ work( iwrk ), lwork+1-iwrk, ierr )
428*
429* Apply the orthogonal transformation to matrix A
430*
431 CALL cunmqr( 'L', 'C', irows, icols, irows, b( ilo, ilo ), ldb,
432 $ work( itau ), a( ilo, ilo ), lda, work( iwrk ),
433 $ lwork+1-iwrk, ierr )
434*
435* Initialize VL
436*
437 IF( ilvl ) THEN
438 CALL claset( 'Full', n, n, czero, cone, vl, ldvl )
439 IF( irows.GT.1 ) THEN
440 CALL clacpy( 'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
441 $ vl( ilo+1, ilo ), ldvl )
442 END IF
443 CALL cungqr( irows, irows, irows, vl( ilo, ilo ), ldvl,
444 $ work( itau ), work( iwrk ), lwork+1-iwrk, ierr )
445 END IF
446*
447* Initialize VR
448*
449 IF( ilvr )
450 $ CALL claset( 'Full', n, n, czero, cone, vr, ldvr )
451*
452* Reduce to generalized Hessenberg form
453*
454 IF( ilv ) THEN
455*
456* Eigenvectors requested -- work on whole matrix.
457*
458 CALL cgghd3( jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb, vl,
459 $ ldvl, vr, ldvr, work( iwrk ), lwork+1-iwrk,
460 $ ierr )
461 ELSE
462 CALL cgghd3( 'N', 'N', irows, 1, irows, a( ilo, ilo ), lda,
463 $ b( ilo, ilo ), ldb, vl, ldvl, vr, ldvr,
464 $ work( iwrk ), lwork+1-iwrk, ierr )
465 END IF
466*
467* Perform QZ algorithm (Compute eigenvalues, and optionally, the
468* Schur form and Schur vectors)
469*
470 iwrk = itau
471 IF( ilv ) THEN
472 chtemp = 'S'
473 ELSE
474 chtemp = 'E'
475 END IF
476 CALL claqz0( chtemp, jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb,
477 $ alpha, beta, vl, ldvl, vr, ldvr, work( iwrk ),
478 $ lwork+1-iwrk, rwork( irwrk ), 0, ierr )
479 IF( ierr.NE.0 ) THEN
480 IF( ierr.GT.0 .AND. ierr.LE.n ) THEN
481 info = ierr
482 ELSE IF( ierr.GT.n .AND. ierr.LE.2*n ) THEN
483 info = ierr - n
484 ELSE
485 info = n + 1
486 END IF
487 GO TO 70
488 END IF
489*
490* Compute Eigenvectors
491*
492 IF( ilv ) THEN
493 IF( ilvl ) THEN
494 IF( ilvr ) THEN
495 chtemp = 'B'
496 ELSE
497 chtemp = 'L'
498 END IF
499 ELSE
500 chtemp = 'R'
501 END IF
502*
503 CALL ctgevc( chtemp, 'B', ldumma, n, a, lda, b, ldb, vl,
504 $ ldvl,
505 $ vr, ldvr, n, in, work( iwrk ), rwork( irwrk ),
506 $ ierr )
507 IF( ierr.NE.0 ) THEN
508 info = n + 2
509 GO TO 70
510 END IF
511*
512* Undo balancing on VL and VR and normalization
513*
514 IF( ilvl ) THEN
515 CALL cggbak( 'P', 'L', n, ilo, ihi, rwork( ileft ),
516 $ rwork( iright ), n, vl, ldvl, ierr )
517 DO 30 jc = 1, n
518 temp = zero
519 DO 10 jr = 1, n
520 temp = max( temp, abs1( vl( jr, jc ) ) )
521 10 CONTINUE
522 IF( temp.LT.smlnum )
523 $ GO TO 30
524 temp = one / temp
525 DO 20 jr = 1, n
526 vl( jr, jc ) = vl( jr, jc )*temp
527 20 CONTINUE
528 30 CONTINUE
529 END IF
530 IF( ilvr ) THEN
531 CALL cggbak( 'P', 'R', n, ilo, ihi, rwork( ileft ),
532 $ rwork( iright ), n, vr, ldvr, ierr )
533 DO 60 jc = 1, n
534 temp = zero
535 DO 40 jr = 1, n
536 temp = max( temp, abs1( vr( jr, jc ) ) )
537 40 CONTINUE
538 IF( temp.LT.smlnum )
539 $ GO TO 60
540 temp = one / temp
541 DO 50 jr = 1, n
542 vr( jr, jc ) = vr( jr, jc )*temp
543 50 CONTINUE
544 60 CONTINUE
545 END IF
546 END IF
547*
548* Undo scaling if necessary
549*
550 70 CONTINUE
551*
552 IF( ilascl )
553 $ CALL clascl( 'G', 0, 0, anrmto, anrm, n, 1, alpha, n, ierr )
554*
555 IF( ilbscl )
556 $ CALL clascl( 'G', 0, 0, bnrmto, bnrm, n, 1, beta, n, ierr )
557*
558 work( 1 ) = sroundup_lwork( lwkopt )
559 RETURN
560*
561* End of CGGEV3
562*
563 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cgeqrf(m, n, a, lda, tau, work, lwork, info)
CGEQRF
Definition cgeqrf.f:144
subroutine cggbak(job, side, n, ilo, ihi, lscale, rscale, m, v, ldv, info)
CGGBAK
Definition cggbak.f:147
subroutine cggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, info)
CGGBAL
Definition cggbal.f:175
subroutine cggev3(jobvl, jobvr, n, a, lda, b, ldb, alpha, beta, vl, ldvl, vr, ldvr, work, lwork, rwork, info)
CGGEV3 computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices (...
Definition cggev3.f:216
subroutine cgghd3(compq, compz, n, ilo, ihi, a, lda, b, ldb, q, ldq, z, ldz, work, lwork, info)
CGGHD3
Definition cgghd3.f:230
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
recursive subroutine claqz0(wants, wantq, wantz, n, ilo, ihi, a, lda, b, ldb, alpha, beta, q, ldq, z, ldz, work, lwork, rwork, rec, info)
CLAQZ0
Definition claqz0.f:283
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 claset(uplo, m, n, alpha, beta, a, lda)
CLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition claset.f:104
subroutine ctgevc(side, howmny, select, n, s, lds, p, ldp, vl, ldvl, vr, ldvr, mm, m, work, rwork, info)
CTGEVC
Definition ctgevc.f:217
subroutine cungqr(m, n, k, a, lda, tau, work, lwork, info)
CUNGQR
Definition cungqr.f:126
subroutine cunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMQR
Definition cunmqr.f:166