You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

zheev.f 8.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. *> \brief <b> ZHEEV 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. *> \htmlonly
  9. *> Download ZHEEV + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zheev.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zheev.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zheev.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZHEEV( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, RWORK,
  22. * INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER JOBZ, UPLO
  26. * INTEGER INFO, LDA, LWORK, N
  27. * ..
  28. * .. Array Arguments ..
  29. * DOUBLE PRECISION RWORK( * ), W( * )
  30. * COMPLEX*16 A( LDA, * ), WORK( * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *> ZHEEV computes all eigenvalues and, optionally, eigenvectors of a
  40. *> complex Hermitian matrix A.
  41. *> \endverbatim
  42. *
  43. * Arguments:
  44. * ==========
  45. *
  46. *> \param[in] JOBZ
  47. *> \verbatim
  48. *> JOBZ is CHARACTER*1
  49. *> = 'N': Compute eigenvalues only;
  50. *> = 'V': Compute eigenvalues and eigenvectors.
  51. *> \endverbatim
  52. *>
  53. *> \param[in] UPLO
  54. *> \verbatim
  55. *> UPLO is CHARACTER*1
  56. *> = 'U': Upper triangle of A is stored;
  57. *> = 'L': Lower triangle of A is stored.
  58. *> \endverbatim
  59. *>
  60. *> \param[in] N
  61. *> \verbatim
  62. *> N is INTEGER
  63. *> The order of the matrix A. N >= 0.
  64. *> \endverbatim
  65. *>
  66. *> \param[in,out] A
  67. *> \verbatim
  68. *> A is COMPLEX*16 array, dimension (LDA, N)
  69. *> On entry, the Hermitian matrix A. If UPLO = 'U', the
  70. *> leading N-by-N upper triangular part of A contains the
  71. *> upper triangular part of the matrix A. If UPLO = 'L',
  72. *> the leading N-by-N lower triangular part of A contains
  73. *> the lower triangular part of the matrix A.
  74. *> On exit, if JOBZ = 'V', then if INFO = 0, A contains the
  75. *> orthonormal eigenvectors of the matrix A.
  76. *> If JOBZ = 'N', then on exit the lower triangle (if UPLO='L')
  77. *> or the upper triangle (if UPLO='U') of A, including the
  78. *> diagonal, is destroyed.
  79. *> \endverbatim
  80. *>
  81. *> \param[in] LDA
  82. *> \verbatim
  83. *> LDA is INTEGER
  84. *> The leading dimension of the array A. LDA >= max(1,N).
  85. *> \endverbatim
  86. *>
  87. *> \param[out] W
  88. *> \verbatim
  89. *> W is DOUBLE PRECISION array, dimension (N)
  90. *> If INFO = 0, the eigenvalues in ascending order.
  91. *> \endverbatim
  92. *>
  93. *> \param[out] WORK
  94. *> \verbatim
  95. *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
  96. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  97. *> \endverbatim
  98. *>
  99. *> \param[in] LWORK
  100. *> \verbatim
  101. *> LWORK is INTEGER
  102. *> The length of the array WORK. LWORK >= max(1,2*N-1).
  103. *> For optimal efficiency, LWORK >= (NB+1)*N,
  104. *> where NB is the blocksize for ZHETRD returned by ILAENV.
  105. *>
  106. *> If LWORK = -1, then a workspace query is assumed; the routine
  107. *> only calculates the optimal size of the WORK array, returns
  108. *> this value as the first entry of the WORK array, and no error
  109. *> message related to LWORK is issued by XERBLA.
  110. *> \endverbatim
  111. *>
  112. *> \param[out] RWORK
  113. *> \verbatim
  114. *> RWORK is DOUBLE PRECISION array, dimension (max(1, 3*N-2))
  115. *> \endverbatim
  116. *>
  117. *> \param[out] INFO
  118. *> \verbatim
  119. *> INFO is INTEGER
  120. *> = 0: successful exit
  121. *> < 0: if INFO = -i, the i-th argument had an illegal value
  122. *> > 0: if INFO = i, the algorithm failed to converge; i
  123. *> off-diagonal elements of an intermediate tridiagonal
  124. *> form did not converge to zero.
  125. *> \endverbatim
  126. *
  127. * Authors:
  128. * ========
  129. *
  130. *> \author Univ. of Tennessee
  131. *> \author Univ. of California Berkeley
  132. *> \author Univ. of Colorado Denver
  133. *> \author NAG Ltd.
  134. *
  135. *> \ingroup complex16HEeigen
  136. *
  137. * =====================================================================
  138. SUBROUTINE ZHEEV( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, RWORK,
  139. $ INFO )
  140. *
  141. * -- LAPACK driver routine --
  142. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  143. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  144. *
  145. * .. Scalar Arguments ..
  146. CHARACTER JOBZ, UPLO
  147. INTEGER INFO, LDA, LWORK, N
  148. * ..
  149. * .. Array Arguments ..
  150. DOUBLE PRECISION RWORK( * ), W( * )
  151. COMPLEX*16 A( LDA, * ), WORK( * )
  152. * ..
  153. *
  154. * =====================================================================
  155. *
  156. * .. Parameters ..
  157. DOUBLE PRECISION ZERO, ONE
  158. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
  159. COMPLEX*16 CONE
  160. PARAMETER ( CONE = ( 1.0D0, 0.0D0 ) )
  161. * ..
  162. * .. Local Scalars ..
  163. LOGICAL LOWER, LQUERY, WANTZ
  164. INTEGER IINFO, IMAX, INDE, INDTAU, INDWRK, ISCALE,
  165. $ LLWORK, LWKOPT, NB
  166. DOUBLE PRECISION ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
  167. $ SMLNUM
  168. * ..
  169. * .. External Functions ..
  170. LOGICAL LSAME
  171. INTEGER ILAENV
  172. DOUBLE PRECISION DLAMCH, ZLANHE
  173. EXTERNAL LSAME, ILAENV, DLAMCH, ZLANHE
  174. * ..
  175. * .. External Subroutines ..
  176. EXTERNAL DSCAL, DSTERF, XERBLA, ZHETRD, ZLASCL, ZSTEQR,
  177. $ ZUNGTR
  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, 'ZHETRD', UPLO, N, -1, -1, -1 )
  203. LWKOPT = MAX( 1, ( NB+1 )*N )
  204. WORK( 1 ) = 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( 'ZHEEV ', -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 ) = DBLE( 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 = DLAMCH( 'Safe minimum' )
  234. EPS = DLAMCH( '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 = ZLANHE( '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 ZLASCL( UPLO, 0, 0, ONE, SIGMA, N, N, A, LDA, INFO )
  253. *
  254. * Call ZHETRD 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 ZHETRD( UPLO, N, A, LDA, W, RWORK( INDE ), WORK( INDTAU ),
  261. $ WORK( INDWRK ), LLWORK, IINFO )
  262. *
  263. * For eigenvalues only, call DSTERF. For eigenvectors, first call
  264. * ZUNGTR to generate the unitary matrix, then call ZSTEQR.
  265. *
  266. IF( .NOT.WANTZ ) THEN
  267. CALL DSTERF( N, W, RWORK( INDE ), INFO )
  268. ELSE
  269. CALL ZUNGTR( UPLO, N, A, LDA, WORK( INDTAU ), WORK( INDWRK ),
  270. $ LLWORK, IINFO )
  271. INDWRK = INDE + N
  272. CALL ZSTEQR( JOBZ, N, W, RWORK( INDE ), A, LDA,
  273. $ RWORK( INDWRK ), INFO )
  274. END IF
  275. *
  276. * If matrix was scaled, then rescale eigenvalues appropriately.
  277. *
  278. IF( ISCALE.EQ.1 ) THEN
  279. IF( INFO.EQ.0 ) THEN
  280. IMAX = N
  281. ELSE
  282. IMAX = INFO - 1
  283. END IF
  284. CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
  285. END IF
  286. *
  287. * Set WORK(1) to optimal complex workspace size.
  288. *
  289. WORK( 1 ) = LWKOPT
  290. *
  291. RETURN
  292. *
  293. * End of ZHEEV
  294. *
  295. END