LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cheev.f
Go to the documentation of this file.
1*> \brief <b> CHEEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE matrices</b>
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CHEEV + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cheev.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cheev.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cheev.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CHEEV( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, RWORK,
20* INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER JOBZ, UPLO
24* INTEGER INFO, LDA, LWORK, N
25* ..
26* .. Array Arguments ..
27* REAL RWORK( * ), W( * )
28* COMPLEX A( LDA, * ), WORK( * )
29* ..
30*
31*
32*> \par Purpose:
33* =============
34*>
35*> \verbatim
36*>
37*> CHEEV computes all eigenvalues and, optionally, eigenvectors of a
38*> complex Hermitian matrix A.
39*> \endverbatim
40*
41* Arguments:
42* ==========
43*
44*> \param[in] JOBZ
45*> \verbatim
46*> JOBZ is CHARACTER*1
47*> = 'N': Compute eigenvalues only;
48*> = 'V': Compute eigenvalues and eigenvectors.
49*> \endverbatim
50*>
51*> \param[in] UPLO
52*> \verbatim
53*> UPLO is CHARACTER*1
54*> = 'U': Upper triangle of A is stored;
55*> = 'L': Lower triangle of A is stored.
56*> \endverbatim
57*>
58*> \param[in] N
59*> \verbatim
60*> N is INTEGER
61*> The order of the matrix A. N >= 0.
62*> \endverbatim
63*>
64*> \param[in,out] A
65*> \verbatim
66*> A is COMPLEX array, dimension (LDA, N)
67*> On entry, the Hermitian matrix A. If UPLO = 'U', the
68*> leading N-by-N upper triangular part of A contains the
69*> upper triangular part of the matrix A. If UPLO = 'L',
70*> the leading N-by-N lower triangular part of A contains
71*> the lower triangular part of the matrix A.
72*> On exit, if JOBZ = 'V', then if INFO = 0, A contains the
73*> orthonormal eigenvectors of the matrix A.
74*> If JOBZ = 'N', then on exit the lower triangle (if UPLO='L')
75*> or the upper triangle (if UPLO='U') of A, including the
76*> diagonal, is destroyed.
77*> \endverbatim
78*>
79*> \param[in] LDA
80*> \verbatim
81*> LDA is INTEGER
82*> The leading dimension of the array A. LDA >= max(1,N).
83*> \endverbatim
84*>
85*> \param[out] W
86*> \verbatim
87*> W is REAL array, dimension (N)
88*> If INFO = 0, the eigenvalues in ascending order.
89*> \endverbatim
90*>
91*> \param[out] WORK
92*> \verbatim
93*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
94*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
95*> \endverbatim
96*>
97*> \param[in] LWORK
98*> \verbatim
99*> LWORK is INTEGER
100*> The length of the array WORK. LWORK >= max(1,2*N-1).
101*> For optimal efficiency, LWORK >= (NB+1)*N,
102*> where NB is the blocksize for CHETRD returned by ILAENV.
103*>
104*> If LWORK = -1, then a workspace query is assumed; the routine
105*> only calculates the optimal size of the WORK array, returns
106*> this value as the first entry of the WORK array, and no error
107*> message related to LWORK is issued by XERBLA.
108*> \endverbatim
109*>
110*> \param[out] RWORK
111*> \verbatim
112*> RWORK is REAL array, dimension (max(1, 3*N-2))
113*> \endverbatim
114*>
115*> \param[out] INFO
116*> \verbatim
117*> INFO is INTEGER
118*> = 0: successful exit
119*> < 0: if INFO = -i, the i-th argument had an illegal value
120*> > 0: if INFO = i, the algorithm failed to converge; i
121*> off-diagonal elements of an intermediate tridiagonal
122*> form did not converge to zero.
123*> \endverbatim
124*
125* Authors:
126* ========
127*
128*> \author Univ. of Tennessee
129*> \author Univ. of California Berkeley
130*> \author Univ. of Colorado Denver
131*> \author NAG Ltd.
132*
133*> \ingroup heev
134*
135* =====================================================================
136 SUBROUTINE cheev( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, RWORK,
137 $ INFO )
138*
139* -- LAPACK driver routine --
140* -- LAPACK is a software package provided by Univ. of Tennessee, --
141* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
142*
143* .. Scalar Arguments ..
144 CHARACTER JOBZ, UPLO
145 INTEGER INFO, LDA, LWORK, N
146* ..
147* .. Array Arguments ..
148 REAL RWORK( * ), W( * )
149 COMPLEX A( LDA, * ), WORK( * )
150* ..
151*
152* =====================================================================
153*
154* .. Parameters ..
155 REAL ZERO, ONE
156 parameter( zero = 0.0e0, one = 1.0e0 )
157 COMPLEX CONE
158 parameter( cone = ( 1.0e0, 0.0e0 ) )
159* ..
160* .. Local Scalars ..
161 LOGICAL LOWER, LQUERY, WANTZ
162 INTEGER IINFO, IMAX, INDE, INDTAU, INDWRK, ISCALE,
163 $ llwork, lwkopt, nb
164 REAL ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
165 $ smlnum
166* ..
167* .. External Functions ..
168 LOGICAL LSAME
169 INTEGER ILAENV
170 REAL CLANHE, SLAMCH, SROUNDUP_LWORK
171 EXTERNAL ilaenv, lsame, clanhe,
172 $ slamch, sroundup_lwork
173* ..
174* .. External Subroutines ..
175 EXTERNAL chetrd, clascl, csteqr, cungtr, sscal,
176 $ ssterf,
177 $ xerbla
178* ..
179* .. Intrinsic Functions ..
180 INTRINSIC max, sqrt
181* ..
182* .. Executable Statements ..
183*
184* Test the input parameters.
185*
186 wantz = lsame( jobz, 'V' )
187 lower = lsame( uplo, 'L' )
188 lquery = ( lwork.EQ.-1 )
189*
190 info = 0
191 IF( .NOT.( wantz .OR. lsame( jobz, 'N' ) ) ) THEN
192 info = -1
193 ELSE IF( .NOT.( lower .OR. lsame( uplo, 'U' ) ) ) THEN
194 info = -2
195 ELSE IF( n.LT.0 ) THEN
196 info = -3
197 ELSE IF( lda.LT.max( 1, n ) ) THEN
198 info = -5
199 END IF
200*
201 IF( info.EQ.0 ) THEN
202 nb = ilaenv( 1, 'CHETRD', uplo, n, -1, -1, -1 )
203 lwkopt = max( 1, ( nb+1 )*n )
204 work( 1 ) = sroundup_lwork(lwkopt)
205*
206 IF( lwork.LT.max( 1, 2*n-1 ) .AND. .NOT.lquery )
207 $ info = -8
208 END IF
209*
210 IF( info.NE.0 ) THEN
211 CALL xerbla( 'CHEEV ', -info )
212 RETURN
213 ELSE IF( lquery ) THEN
214 RETURN
215 END IF
216*
217* Quick return if possible
218*
219 IF( n.EQ.0 ) THEN
220 RETURN
221 END IF
222*
223 IF( n.EQ.1 ) THEN
224 w( 1 ) = real( a( 1, 1 ) )
225 work( 1 ) = 1
226 IF( wantz )
227 $ a( 1, 1 ) = cone
228 RETURN
229 END IF
230*
231* Get machine constants.
232*
233 safmin = slamch( 'Safe minimum' )
234 eps = slamch( 'Precision' )
235 smlnum = safmin / eps
236 bignum = one / smlnum
237 rmin = sqrt( smlnum )
238 rmax = sqrt( bignum )
239*
240* Scale matrix to allowable range, if necessary.
241*
242 anrm = clanhe( 'M', uplo, n, a, lda, rwork )
243 iscale = 0
244 IF( anrm.GT.zero .AND. anrm.LT.rmin ) THEN
245 iscale = 1
246 sigma = rmin / anrm
247 ELSE IF( anrm.GT.rmax ) THEN
248 iscale = 1
249 sigma = rmax / anrm
250 END IF
251 IF( iscale.EQ.1 )
252 $ CALL clascl( uplo, 0, 0, one, sigma, n, n, a, lda, info )
253*
254* Call CHETRD to reduce Hermitian matrix to tridiagonal form.
255*
256 inde = 1
257 indtau = 1
258 indwrk = indtau + n
259 llwork = lwork - indwrk + 1
260 CALL chetrd( uplo, n, a, lda, w, rwork( inde ), work( indtau ),
261 $ work( indwrk ), llwork, iinfo )
262*
263* For eigenvalues only, call SSTERF. For eigenvectors, first call
264* CUNGTR to generate the unitary matrix, then call CSTEQR.
265*
266 IF( .NOT.wantz ) THEN
267 CALL ssterf( n, w, rwork( inde ), info )
268 ELSE
269 CALL cungtr( uplo, n, a, lda, work( indtau ),
270 $ work( indwrk ),
271 $ llwork, iinfo )
272 indwrk = inde + n
273 CALL csteqr( jobz, n, w, rwork( inde ), a, lda,
274 $ rwork( indwrk ), info )
275 END IF
276*
277* If matrix was scaled, then rescale eigenvalues appropriately.
278*
279 IF( iscale.EQ.1 ) THEN
280 IF( info.EQ.0 ) THEN
281 imax = n
282 ELSE
283 imax = info - 1
284 END IF
285 CALL sscal( imax, one / sigma, w, 1 )
286 END IF
287*
288* Set WORK(1) to optimal complex workspace size.
289*
290 work( 1 ) = sroundup_lwork(lwkopt)
291*
292 RETURN
293*
294* End of CHEEV
295*
296 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cheev(jobz, uplo, n, a, lda, w, work, lwork, rwork, info)
CHEEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE matrices
Definition cheev.f:138
subroutine chetrd(uplo, n, a, lda, d, e, tau, work, lwork, info)
CHETRD
Definition chetrd.f:191
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 sscal(n, sa, sx, incx)
SSCAL
Definition sscal.f:79
subroutine csteqr(compz, n, d, e, z, ldz, work, info)
CSTEQR
Definition csteqr.f:130
subroutine ssterf(n, d, e, info)
SSTERF
Definition ssterf.f:84
subroutine cungtr(uplo, n, a, lda, tau, work, lwork, info)
CUNGTR
Definition cungtr.f:121