1
*> \brief <b> SGEEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices</b>
3
* =========== DOCUMENTATION ===========
5
* Online html documentation available at
6
* http://www.netlib.org/lapack/explore-html/
9
*> Download SGEEV + dependencies
10
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgeev.f">
12
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgeev.f">
14
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgeev.f">
21
* SUBROUTINE SGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR,
22
* LDVR, WORK, LWORK, INFO )
24
* .. Scalar Arguments ..
25
* CHARACTER JOBVL, JOBVR
26
* INTEGER INFO, LDA, LDVL, LDVR, LWORK, N
28
* .. Array Arguments ..
29
* REAL A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
30
* $ WI( * ), WORK( * ), WR( * )
39
*> SGEEV computes for an N-by-N real nonsymmetric matrix A, the
40
*> eigenvalues and, optionally, the left and/or right eigenvectors.
42
*> The right eigenvector v(j) of A satisfies
43
*> A * v(j) = lambda(j) * v(j)
44
*> where lambda(j) is its eigenvalue.
45
*> The left eigenvector u(j) of A satisfies
46
*> u(j)**H * A = lambda(j) * u(j)**H
47
*> where u(j)**H denotes the conjugate-transpose of u(j).
49
*> The computed eigenvectors are normalized to have Euclidean norm
50
*> equal to 1 and largest component real.
58
*> JOBVL is CHARACTER*1
59
*> = 'N': left eigenvectors of A are not computed;
60
*> = 'V': left eigenvectors of A are computed.
65
*> JOBVR is CHARACTER*1
66
*> = 'N': right eigenvectors of A are not computed;
67
*> = 'V': right eigenvectors of A are computed.
73
*> The order of the matrix A. N >= 0.
78
*> A is REAL array, dimension (LDA,N)
79
*> On entry, the N-by-N matrix A.
80
*> On exit, A has been overwritten.
86
*> The leading dimension of the array A. LDA >= max(1,N).
91
*> WR is REAL array, dimension (N)
96
*> WI is REAL array, dimension (N)
97
*> WR and WI contain the real and imaginary parts,
98
*> respectively, of the computed eigenvalues. Complex
99
*> conjugate pairs of eigenvalues appear consecutively
100
*> with the eigenvalue having the positive imaginary part
106
*> VL is REAL array, dimension (LDVL,N)
107
*> If JOBVL = 'V', the left eigenvectors u(j) are stored one
108
*> after another in the columns of VL, in the same order
109
*> as their eigenvalues.
110
*> If JOBVL = 'N', VL is not referenced.
111
*> If the j-th eigenvalue is real, then u(j) = VL(:,j),
112
*> the j-th column of VL.
113
*> If the j-th and (j+1)-st eigenvalues form a complex
114
*> conjugate pair, then u(j) = VL(:,j) + i*VL(:,j+1) and
115
*> u(j+1) = VL(:,j) - i*VL(:,j+1).
121
*> The leading dimension of the array VL. LDVL >= 1; if
122
*> JOBVL = 'V', LDVL >= N.
127
*> VR is REAL array, dimension (LDVR,N)
128
*> If JOBVR = 'V', the right eigenvectors v(j) are stored one
129
*> after another in the columns of VR, in the same order
130
*> as their eigenvalues.
131
*> If JOBVR = 'N', VR is not referenced.
132
*> If the j-th eigenvalue is real, then v(j) = VR(:,j),
133
*> the j-th column of VR.
134
*> If the j-th and (j+1)-st eigenvalues form a complex
135
*> conjugate pair, then v(j) = VR(:,j) + i*VR(:,j+1) and
136
*> v(j+1) = VR(:,j) - i*VR(:,j+1).
142
*> The leading dimension of the array VR. LDVR >= 1; if
143
*> JOBVR = 'V', LDVR >= N.
148
*> WORK is REAL array, dimension (MAX(1,LWORK))
149
*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
155
*> The dimension of the array WORK. LWORK >= max(1,3*N), and
156
*> if JOBVL = 'V' or JOBVR = 'V', LWORK >= 4*N. For good
157
*> performance, LWORK must generally be larger.
159
*> If LWORK = -1, then a workspace query is assumed; the routine
160
*> only calculates the optimal size of the WORK array, returns
161
*> this value as the first entry of the WORK array, and no error
162
*> message related to LWORK is issued by XERBLA.
168
*> = 0: successful exit
169
*> < 0: if INFO = -i, the i-th argument had an illegal value.
170
*> > 0: if INFO = i, the QR algorithm failed to compute all the
171
*> eigenvalues, and no eigenvectors have been computed;
172
*> elements i+1:N of WR and WI contain eigenvalues which
179
*> \author Univ. of Tennessee
180
*> \author Univ. of California Berkeley
181
*> \author Univ. of Colorado Denver
184
*> \date September 2012
186
*> \ingroup realGEeigen
188
* =====================================================================
189
SUBROUTINE SGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR,
190
$ LDVR, WORK, LWORK, INFO )
192
* -- LAPACK driver routine (version 3.4.2) --
193
* -- LAPACK is a software package provided by Univ. of Tennessee, --
194
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
197
* .. Scalar Arguments ..
198
CHARACTER JOBVL, JOBVR
199
INTEGER INFO, LDA, LDVL, LDVR, LWORK, N
201
* .. Array Arguments ..
202
REAL A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
203
$ WI( * ), WORK( * ), WR( * )
206
* =====================================================================
210
PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
212
* .. Local Scalars ..
213
LOGICAL LQUERY, SCALEA, WANTVL, WANTVR
215
INTEGER HSWORK, I, IBAL, IERR, IHI, ILO, ITAU, IWRK, K,
216
$ MAXWRK, MINWRK, NOUT
217
REAL ANRM, BIGNUM, CS, CSCALE, EPS, R, SCL, SMLNUM,
224
* .. External Subroutines ..
225
EXTERNAL SGEBAK, SGEBAL, SGEHRD, SHSEQR, SLABAD, SLACPY,
226
$ SLARTG, SLASCL, SORGHR, SROT, SSCAL, STREVC,
229
* .. External Functions ..
231
INTEGER ILAENV, ISAMAX
232
REAL SLAMCH, SLANGE, SLAPY2, SNRM2
233
EXTERNAL LSAME, ILAENV, ISAMAX, SLAMCH, SLANGE, SLAPY2,
236
* .. Intrinsic Functions ..
239
* .. Executable Statements ..
241
* Test the input arguments
244
LQUERY = ( LWORK.EQ.-1 )
245
WANTVL = LSAME( JOBVL, 'V' )
246
WANTVR = LSAME( JOBVR, 'V' )
247
IF( ( .NOT.WANTVL ) .AND. ( .NOT.LSAME( JOBVL, 'N' ) ) ) THEN
249
ELSE IF( ( .NOT.WANTVR ) .AND. ( .NOT.LSAME( JOBVR, 'N' ) ) ) THEN
251
ELSE IF( N.LT.0 ) THEN
253
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
255
ELSE IF( LDVL.LT.1 .OR. ( WANTVL .AND. LDVL.LT.N ) ) THEN
257
ELSE IF( LDVR.LT.1 .OR. ( WANTVR .AND. LDVR.LT.N ) ) THEN
262
* (Note: Comments in the code beginning "Workspace:" describe the
263
* minimal amount of workspace needed at that point in the code,
264
* as well as the preferred amount for good performance.
265
* NB refers to the optimal block size for the immediately
266
* following subroutine, as returned by ILAENV.
267
* HSWORK refers to the workspace preferred by SHSEQR, as
268
* calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
276
MAXWRK = 2*N + N*ILAENV( 1, 'SGEHRD', ' ', N, 1, N, 0 )
279
MAXWRK = MAX( MAXWRK, 2*N + ( N - 1 )*ILAENV( 1,
280
$ 'SORGHR', ' ', N, 1, N, -1 ) )
281
CALL SHSEQR( 'S', 'V', N, 1, N, A, LDA, WR, WI, VL, LDVL,
284
MAXWRK = MAX( MAXWRK, N + 1, N + HSWORK )
285
MAXWRK = MAX( MAXWRK, 4*N )
286
ELSE IF( WANTVR ) THEN
288
MAXWRK = MAX( MAXWRK, 2*N + ( N - 1 )*ILAENV( 1,
289
$ 'SORGHR', ' ', N, 1, N, -1 ) )
290
CALL SHSEQR( 'S', 'V', N, 1, N, A, LDA, WR, WI, VR, LDVR,
293
MAXWRK = MAX( MAXWRK, N + 1, N + HSWORK )
294
MAXWRK = MAX( MAXWRK, 4*N )
297
CALL SHSEQR( 'E', 'N', N, 1, N, A, LDA, WR, WI, VR, LDVR,
300
MAXWRK = MAX( MAXWRK, N + 1, N + HSWORK )
302
MAXWRK = MAX( MAXWRK, MINWRK )
306
IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
312
CALL XERBLA( 'SGEEV ', -INFO )
314
ELSE IF( LQUERY ) THEN
318
* Quick return if possible
323
* Get machine constants
326
SMLNUM = SLAMCH( 'S' )
327
BIGNUM = ONE / SMLNUM
328
CALL SLABAD( SMLNUM, BIGNUM )
329
SMLNUM = SQRT( SMLNUM ) / EPS
330
BIGNUM = ONE / SMLNUM
332
* Scale A if max element outside range [SMLNUM,BIGNUM]
334
ANRM = SLANGE( 'M', N, N, A, LDA, DUM )
336
IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
339
ELSE IF( ANRM.GT.BIGNUM ) THEN
344
$ CALL SLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )
347
* (Workspace: need N)
350
CALL SGEBAL( 'B', N, A, LDA, ILO, IHI, WORK( IBAL ), IERR )
352
* Reduce to upper Hessenberg form
353
* (Workspace: need 3*N, prefer 2*N+N*NB)
357
CALL SGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),
358
$ LWORK-IWRK+1, IERR )
362
* Want left eigenvectors
363
* Copy Householder vectors to VL
366
CALL SLACPY( 'L', N, N, A, LDA, VL, LDVL )
368
* Generate orthogonal matrix in VL
369
* (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)
371
CALL SORGHR( N, ILO, IHI, VL, LDVL, WORK( ITAU ), WORK( IWRK ),
372
$ LWORK-IWRK+1, IERR )
374
* Perform QR iteration, accumulating Schur vectors in VL
375
* (Workspace: need N+1, prefer N+HSWORK (see comments) )
378
CALL SHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, WR, WI, VL, LDVL,
379
$ WORK( IWRK ), LWORK-IWRK+1, INFO )
383
* Want left and right eigenvectors
384
* Copy Schur vectors to VR
387
CALL SLACPY( 'F', N, N, VL, LDVL, VR, LDVR )
390
ELSE IF( WANTVR ) THEN
392
* Want right eigenvectors
393
* Copy Householder vectors to VR
396
CALL SLACPY( 'L', N, N, A, LDA, VR, LDVR )
398
* Generate orthogonal matrix in VR
399
* (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)
401
CALL SORGHR( N, ILO, IHI, VR, LDVR, WORK( ITAU ), WORK( IWRK ),
402
$ LWORK-IWRK+1, IERR )
404
* Perform QR iteration, accumulating Schur vectors in VR
405
* (Workspace: need N+1, prefer N+HSWORK (see comments) )
408
CALL SHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, WR, WI, VR, LDVR,
409
$ WORK( IWRK ), LWORK-IWRK+1, INFO )
413
* Compute eigenvalues only
414
* (Workspace: need N+1, prefer N+HSWORK (see comments) )
417
CALL SHSEQR( 'E', 'N', N, ILO, IHI, A, LDA, WR, WI, VR, LDVR,
418
$ WORK( IWRK ), LWORK-IWRK+1, INFO )
421
* If INFO > 0 from SHSEQR, then quit
426
IF( WANTVL .OR. WANTVR ) THEN
428
* Compute left and/or right eigenvectors
429
* (Workspace: need 4*N)
431
CALL STREVC( SIDE, 'B', SELECT, N, A, LDA, VL, LDVL, VR, LDVR,
432
$ N, NOUT, WORK( IWRK ), IERR )
437
* Undo balancing of left eigenvectors
438
* (Workspace: need N)
440
CALL SGEBAK( 'B', 'L', N, ILO, IHI, WORK( IBAL ), N, VL, LDVL,
443
* Normalize left eigenvectors and make largest component real
446
IF( WI( I ).EQ.ZERO ) THEN
447
SCL = ONE / SNRM2( N, VL( 1, I ), 1 )
448
CALL SSCAL( N, SCL, VL( 1, I ), 1 )
449
ELSE IF( WI( I ).GT.ZERO ) THEN
450
SCL = ONE / SLAPY2( SNRM2( N, VL( 1, I ), 1 ),
451
$ SNRM2( N, VL( 1, I+1 ), 1 ) )
452
CALL SSCAL( N, SCL, VL( 1, I ), 1 )
453
CALL SSCAL( N, SCL, VL( 1, I+1 ), 1 )
455
WORK( IWRK+K-1 ) = VL( K, I )**2 + VL( K, I+1 )**2
457
K = ISAMAX( N, WORK( IWRK ), 1 )
458
CALL SLARTG( VL( K, I ), VL( K, I+1 ), CS, SN, R )
459
CALL SROT( N, VL( 1, I ), 1, VL( 1, I+1 ), 1, CS, SN )
467
* Undo balancing of right eigenvectors
468
* (Workspace: need N)
470
CALL SGEBAK( 'B', 'R', N, ILO, IHI, WORK( IBAL ), N, VR, LDVR,
473
* Normalize right eigenvectors and make largest component real
476
IF( WI( I ).EQ.ZERO ) THEN
477
SCL = ONE / SNRM2( N, VR( 1, I ), 1 )
478
CALL SSCAL( N, SCL, VR( 1, I ), 1 )
479
ELSE IF( WI( I ).GT.ZERO ) THEN
480
SCL = ONE / SLAPY2( SNRM2( N, VR( 1, I ), 1 ),
481
$ SNRM2( N, VR( 1, I+1 ), 1 ) )
482
CALL SSCAL( N, SCL, VR( 1, I ), 1 )
483
CALL SSCAL( N, SCL, VR( 1, I+1 ), 1 )
485
WORK( IWRK+K-1 ) = VR( K, I )**2 + VR( K, I+1 )**2
487
K = ISAMAX( N, WORK( IWRK ), 1 )
488
CALL SLARTG( VR( K, I ), VR( K, I+1 ), CS, SN, R )
489
CALL SROT( N, VR( 1, I ), 1, VR( 1, I+1 ), 1, CS, SN )
495
* Undo scaling if necessary
499
CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, WR( INFO+1 ),
500
$ MAX( N-INFO, 1 ), IERR )
501
CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, WI( INFO+1 ),
502
$ MAX( N-INFO, 1 ), IERR )
504
CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WR, N,
506
CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WI, N,