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.

chbevd.f 13 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. *> \brief <b> CHBEVD computes the eigenvalues and, optionally, the left and/or right eigenvectors for OTHER 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 CHBEVD + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chbevd.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chbevd.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chbevd.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHBEVD( JOBZ, UPLO, N, KD, AB, LDAB, W, Z, LDZ, WORK,
  22. * LWORK, RWORK, LRWORK, IWORK, LIWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER JOBZ, UPLO
  26. * INTEGER INFO, KD, LDAB, LDZ, LIWORK, LRWORK, LWORK, N
  27. * ..
  28. * .. Array Arguments ..
  29. * INTEGER IWORK( * )
  30. * REAL RWORK( * ), W( * )
  31. * COMPLEX AB( LDAB, * ), WORK( * ), Z( LDZ, * )
  32. * ..
  33. *
  34. *
  35. *> \par Purpose:
  36. * =============
  37. *>
  38. *> \verbatim
  39. *>
  40. *> CHBEVD computes all the eigenvalues and, optionally, eigenvectors of
  41. *> a complex Hermitian band matrix A. If eigenvectors are desired, it
  42. *> uses a divide and conquer algorithm.
  43. *>
  44. *> \endverbatim
  45. *
  46. * Arguments:
  47. * ==========
  48. *
  49. *> \param[in] JOBZ
  50. *> \verbatim
  51. *> JOBZ is CHARACTER*1
  52. *> = 'N': Compute eigenvalues only;
  53. *> = 'V': Compute eigenvalues and eigenvectors.
  54. *> \endverbatim
  55. *>
  56. *> \param[in] UPLO
  57. *> \verbatim
  58. *> UPLO is CHARACTER*1
  59. *> = 'U': Upper triangle of A is stored;
  60. *> = 'L': Lower triangle of A is stored.
  61. *> \endverbatim
  62. *>
  63. *> \param[in] N
  64. *> \verbatim
  65. *> N is INTEGER
  66. *> The order of the matrix A. N >= 0.
  67. *> \endverbatim
  68. *>
  69. *> \param[in] KD
  70. *> \verbatim
  71. *> KD is INTEGER
  72. *> The number of superdiagonals of the matrix A if UPLO = 'U',
  73. *> or the number of subdiagonals if UPLO = 'L'. KD >= 0.
  74. *> \endverbatim
  75. *>
  76. *> \param[in,out] AB
  77. *> \verbatim
  78. *> AB is COMPLEX array, dimension (LDAB, N)
  79. *> On entry, the upper or lower triangle of the Hermitian band
  80. *> matrix A, stored in the first KD+1 rows of the array. The
  81. *> j-th column of A is stored in the j-th column of the array AB
  82. *> as follows:
  83. *> if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
  84. *> if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd).
  85. *>
  86. *> On exit, AB is overwritten by values generated during the
  87. *> reduction to tridiagonal form. If UPLO = 'U', the first
  88. *> superdiagonal and the diagonal of the tridiagonal matrix T
  89. *> are returned in rows KD and KD+1 of AB, and if UPLO = 'L',
  90. *> the diagonal and first subdiagonal of T are returned in the
  91. *> first two rows of AB.
  92. *> \endverbatim
  93. *>
  94. *> \param[in] LDAB
  95. *> \verbatim
  96. *> LDAB is INTEGER
  97. *> The leading dimension of the array AB. LDAB >= KD + 1.
  98. *> \endverbatim
  99. *>
  100. *> \param[out] W
  101. *> \verbatim
  102. *> W is REAL array, dimension (N)
  103. *> If INFO = 0, the eigenvalues in ascending order.
  104. *> \endverbatim
  105. *>
  106. *> \param[out] Z
  107. *> \verbatim
  108. *> Z is COMPLEX array, dimension (LDZ, N)
  109. *> If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal
  110. *> eigenvectors of the matrix A, with the i-th column of Z
  111. *> holding the eigenvector associated with W(i).
  112. *> If JOBZ = 'N', then Z is not referenced.
  113. *> \endverbatim
  114. *>
  115. *> \param[in] LDZ
  116. *> \verbatim
  117. *> LDZ is INTEGER
  118. *> The leading dimension of the array Z. LDZ >= 1, and if
  119. *> JOBZ = 'V', LDZ >= max(1,N).
  120. *> \endverbatim
  121. *>
  122. *> \param[out] WORK
  123. *> \verbatim
  124. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  125. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  126. *> \endverbatim
  127. *>
  128. *> \param[in] LWORK
  129. *> \verbatim
  130. *> LWORK is INTEGER
  131. *> The dimension of the array WORK.
  132. *> If N <= 1, LWORK must be at least 1.
  133. *> If JOBZ = 'N' and N > 1, LWORK must be at least N.
  134. *> If JOBZ = 'V' and N > 1, LWORK must be at least 2*N**2.
  135. *>
  136. *> If LWORK = -1, then a workspace query is assumed; the routine
  137. *> only calculates the optimal sizes of the WORK, RWORK and
  138. *> IWORK arrays, returns these values as the first entries of
  139. *> the WORK, RWORK and IWORK arrays, and no error message
  140. *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
  141. *> \endverbatim
  142. *>
  143. *> \param[out] RWORK
  144. *> \verbatim
  145. *> RWORK is REAL array,
  146. *> dimension (LRWORK)
  147. *> On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK.
  148. *> \endverbatim
  149. *>
  150. *> \param[in] LRWORK
  151. *> \verbatim
  152. *> LRWORK is INTEGER
  153. *> The dimension of array RWORK.
  154. *> If N <= 1, LRWORK must be at least 1.
  155. *> If JOBZ = 'N' and N > 1, LRWORK must be at least N.
  156. *> If JOBZ = 'V' and N > 1, LRWORK must be at least
  157. *> 1 + 5*N + 2*N**2.
  158. *>
  159. *> If LRWORK = -1, then a workspace query is assumed; the
  160. *> routine only calculates the optimal sizes of the WORK, RWORK
  161. *> and IWORK arrays, returns these values as the first entries
  162. *> of the WORK, RWORK and IWORK arrays, and no error message
  163. *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
  164. *> \endverbatim
  165. *>
  166. *> \param[out] IWORK
  167. *> \verbatim
  168. *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
  169. *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
  170. *> \endverbatim
  171. *>
  172. *> \param[in] LIWORK
  173. *> \verbatim
  174. *> LIWORK is INTEGER
  175. *> The dimension of array IWORK.
  176. *> If JOBZ = 'N' or N <= 1, LIWORK must be at least 1.
  177. *> If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N .
  178. *>
  179. *> If LIWORK = -1, then a workspace query is assumed; the
  180. *> routine only calculates the optimal sizes of the WORK, RWORK
  181. *> and IWORK arrays, returns these values as the first entries
  182. *> of the WORK, RWORK and IWORK arrays, and no error message
  183. *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
  184. *> \endverbatim
  185. *>
  186. *> \param[out] INFO
  187. *> \verbatim
  188. *> INFO is INTEGER
  189. *> = 0: successful exit.
  190. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  191. *> > 0: if INFO = i, the algorithm failed to converge; i
  192. *> off-diagonal elements of an intermediate tridiagonal
  193. *> form did not converge to zero.
  194. *> \endverbatim
  195. *
  196. * Authors:
  197. * ========
  198. *
  199. *> \author Univ. of Tennessee
  200. *> \author Univ. of California Berkeley
  201. *> \author Univ. of Colorado Denver
  202. *> \author NAG Ltd.
  203. *
  204. *> \ingroup hbevd
  205. *
  206. * =====================================================================
  207. SUBROUTINE CHBEVD( JOBZ, UPLO, N, KD, AB, LDAB, W, Z, LDZ, WORK,
  208. $ LWORK, RWORK, LRWORK, IWORK, LIWORK, INFO )
  209. *
  210. * -- LAPACK driver routine --
  211. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  212. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  213. *
  214. * .. Scalar Arguments ..
  215. CHARACTER JOBZ, UPLO
  216. INTEGER INFO, KD, LDAB, LDZ, LIWORK, LRWORK, LWORK, N
  217. * ..
  218. * .. Array Arguments ..
  219. INTEGER IWORK( * )
  220. REAL RWORK( * ), W( * )
  221. COMPLEX AB( LDAB, * ), WORK( * ), Z( LDZ, * )
  222. * ..
  223. *
  224. * =====================================================================
  225. *
  226. * .. Parameters ..
  227. REAL ZERO, ONE
  228. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
  229. COMPLEX CZERO, CONE
  230. PARAMETER ( CZERO = ( 0.0E0, 0.0E0 ),
  231. $ CONE = ( 1.0E0, 0.0E0 ) )
  232. * ..
  233. * .. Local Scalars ..
  234. LOGICAL LOWER, LQUERY, WANTZ
  235. INTEGER IINFO, IMAX, INDE, INDWK2, INDWRK, ISCALE,
  236. $ LIWMIN, LLRWK, LLWK2, LRWMIN, LWMIN
  237. REAL ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
  238. $ SMLNUM
  239. * ..
  240. * .. External Functions ..
  241. LOGICAL LSAME
  242. REAL CLANHB, SLAMCH, SROUNDUP_LWORK
  243. EXTERNAL LSAME, CLANHB, SLAMCH, SROUNDUP_LWORK
  244. * ..
  245. * .. External Subroutines ..
  246. EXTERNAL CGEMM, CHBTRD, CLACPY, CLASCL, CSTEDC, SSCAL,
  247. $ SSTERF, XERBLA
  248. * ..
  249. * .. Intrinsic Functions ..
  250. INTRINSIC SQRT
  251. * ..
  252. * .. Executable Statements ..
  253. *
  254. * Test the input parameters.
  255. *
  256. WANTZ = LSAME( JOBZ, 'V' )
  257. LOWER = LSAME( UPLO, 'L' )
  258. LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 .OR. LRWORK.EQ.-1 )
  259. *
  260. INFO = 0
  261. IF( N.LE.1 ) THEN
  262. LWMIN = 1
  263. LRWMIN = 1
  264. LIWMIN = 1
  265. ELSE
  266. IF( WANTZ ) THEN
  267. LWMIN = 2*N**2
  268. LRWMIN = 1 + 5*N + 2*N**2
  269. LIWMIN = 3 + 5*N
  270. ELSE
  271. LWMIN = N
  272. LRWMIN = N
  273. LIWMIN = 1
  274. END IF
  275. END IF
  276. IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  277. INFO = -1
  278. ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
  279. INFO = -2
  280. ELSE IF( N.LT.0 ) THEN
  281. INFO = -3
  282. ELSE IF( KD.LT.0 ) THEN
  283. INFO = -4
  284. ELSE IF( LDAB.LT.KD+1 ) THEN
  285. INFO = -6
  286. ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
  287. INFO = -9
  288. END IF
  289. *
  290. IF( INFO.EQ.0 ) THEN
  291. WORK( 1 ) = SROUNDUP_LWORK(LWMIN)
  292. RWORK( 1 ) = LRWMIN
  293. IWORK( 1 ) = LIWMIN
  294. *
  295. IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  296. INFO = -11
  297. ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN
  298. INFO = -13
  299. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  300. INFO = -15
  301. END IF
  302. END IF
  303. *
  304. IF( INFO.NE.0 ) THEN
  305. CALL XERBLA( 'CHBEVD', -INFO )
  306. RETURN
  307. ELSE IF( LQUERY ) THEN
  308. RETURN
  309. END IF
  310. *
  311. * Quick return if possible
  312. *
  313. IF( N.EQ.0 )
  314. $ RETURN
  315. *
  316. IF( N.EQ.1 ) THEN
  317. W( 1 ) = REAL( AB( 1, 1 ) )
  318. IF( WANTZ )
  319. $ Z( 1, 1 ) = CONE
  320. RETURN
  321. END IF
  322. *
  323. * Get machine constants.
  324. *
  325. SAFMIN = SLAMCH( 'Safe minimum' )
  326. EPS = SLAMCH( 'Precision' )
  327. SMLNUM = SAFMIN / EPS
  328. BIGNUM = ONE / SMLNUM
  329. RMIN = SQRT( SMLNUM )
  330. RMAX = SQRT( BIGNUM )
  331. *
  332. * Scale matrix to allowable range, if necessary.
  333. *
  334. ANRM = CLANHB( 'M', UPLO, N, KD, AB, LDAB, RWORK )
  335. ISCALE = 0
  336. IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
  337. ISCALE = 1
  338. SIGMA = RMIN / ANRM
  339. ELSE IF( ANRM.GT.RMAX ) THEN
  340. ISCALE = 1
  341. SIGMA = RMAX / ANRM
  342. END IF
  343. IF( ISCALE.EQ.1 ) THEN
  344. IF( LOWER ) THEN
  345. CALL CLASCL( 'B', KD, KD, ONE, SIGMA, N, N, AB, LDAB, INFO )
  346. ELSE
  347. CALL CLASCL( 'Q', KD, KD, ONE, SIGMA, N, N, AB, LDAB, INFO )
  348. END IF
  349. END IF
  350. *
  351. * Call CHBTRD to reduce Hermitian band matrix to tridiagonal form.
  352. *
  353. INDE = 1
  354. INDWRK = INDE + N
  355. INDWK2 = 1 + N*N
  356. LLWK2 = LWORK - INDWK2 + 1
  357. LLRWK = LRWORK - INDWRK + 1
  358. CALL CHBTRD( JOBZ, UPLO, N, KD, AB, LDAB, W, RWORK( INDE ), Z,
  359. $ LDZ, WORK, IINFO )
  360. *
  361. * For eigenvalues only, call SSTERF. For eigenvectors, call CSTEDC.
  362. *
  363. IF( .NOT.WANTZ ) THEN
  364. CALL SSTERF( N, W, RWORK( INDE ), INFO )
  365. ELSE
  366. CALL CSTEDC( 'I', N, W, RWORK( INDE ), WORK, N, WORK( INDWK2 ),
  367. $ LLWK2, RWORK( INDWRK ), LLRWK, IWORK, LIWORK,
  368. $ INFO )
  369. CALL CGEMM( 'N', 'N', N, N, N, CONE, Z, LDZ, WORK, N, CZERO,
  370. $ WORK( INDWK2 ), N )
  371. CALL CLACPY( 'A', N, N, WORK( INDWK2 ), N, Z, LDZ )
  372. END IF
  373. *
  374. * If matrix was scaled, then rescale eigenvalues appropriately.
  375. *
  376. IF( ISCALE.EQ.1 ) THEN
  377. IF( INFO.EQ.0 ) THEN
  378. IMAX = N
  379. ELSE
  380. IMAX = INFO - 1
  381. END IF
  382. CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
  383. END IF
  384. *
  385. WORK( 1 ) = SROUNDUP_LWORK(LWMIN)
  386. RWORK( 1 ) = LRWMIN
  387. IWORK( 1 ) = LIWMIN
  388. RETURN
  389. *
  390. * End of CHBEVD
  391. *
  392. END