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.

chegvx.f 15 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. *> \brief \b CHEGST
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CHEGVX + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chegvx.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chegvx.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chegvx.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHEGVX( ITYPE, JOBZ, RANGE, UPLO, N, A, LDA, B, LDB,
  22. * VL, VU, IL, IU, ABSTOL, M, W, Z, LDZ, WORK,
  23. * LWORK, RWORK, IWORK, IFAIL, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER JOBZ, RANGE, UPLO
  27. * INTEGER IL, INFO, ITYPE, IU, LDA, LDB, LDZ, LWORK, M, N
  28. * REAL ABSTOL, VL, VU
  29. * ..
  30. * .. Array Arguments ..
  31. * INTEGER IFAIL( * ), IWORK( * )
  32. * REAL RWORK( * ), W( * )
  33. * COMPLEX A( LDA, * ), B( LDB, * ), WORK( * ),
  34. * $ Z( LDZ, * )
  35. * ..
  36. *
  37. *
  38. *> \par Purpose:
  39. * =============
  40. *>
  41. *> \verbatim
  42. *>
  43. *> CHEGVX computes selected eigenvalues, and optionally, eigenvectors
  44. *> of a complex generalized Hermitian-definite eigenproblem, of the form
  45. *> A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A and
  46. *> B are assumed to be Hermitian and B is also positive definite.
  47. *> Eigenvalues and eigenvectors can be selected by specifying either a
  48. *> range of values or a range of indices for the desired eigenvalues.
  49. *> \endverbatim
  50. *
  51. * Arguments:
  52. * ==========
  53. *
  54. *> \param[in] ITYPE
  55. *> \verbatim
  56. *> ITYPE is INTEGER
  57. *> Specifies the problem type to be solved:
  58. *> = 1: A*x = (lambda)*B*x
  59. *> = 2: A*B*x = (lambda)*x
  60. *> = 3: B*A*x = (lambda)*x
  61. *> \endverbatim
  62. *>
  63. *> \param[in] JOBZ
  64. *> \verbatim
  65. *> JOBZ is CHARACTER*1
  66. *> = 'N': Compute eigenvalues only;
  67. *> = 'V': Compute eigenvalues and eigenvectors.
  68. *> \endverbatim
  69. *>
  70. *> \param[in] RANGE
  71. *> \verbatim
  72. *> RANGE is CHARACTER*1
  73. *> = 'A': all eigenvalues will be found.
  74. *> = 'V': all eigenvalues in the half-open interval (VL,VU]
  75. *> will be found.
  76. *> = 'I': the IL-th through IU-th eigenvalues will be found.
  77. *> \endverbatim
  78. *>
  79. *> \param[in] UPLO
  80. *> \verbatim
  81. *> UPLO is CHARACTER*1
  82. *> = 'U': Upper triangles of A and B are stored;
  83. *> = 'L': Lower triangles of A and B are stored.
  84. *> \endverbatim
  85. *>
  86. *> \param[in] N
  87. *> \verbatim
  88. *> N is INTEGER
  89. *> The order of the matrices A and B. N >= 0.
  90. *> \endverbatim
  91. *>
  92. *> \param[in,out] A
  93. *> \verbatim
  94. *> A is COMPLEX array, dimension (LDA, N)
  95. *> On entry, the Hermitian matrix A. If UPLO = 'U', the
  96. *> leading N-by-N upper triangular part of A contains the
  97. *> upper triangular part of the matrix A. If UPLO = 'L',
  98. *> the leading N-by-N lower triangular part of A contains
  99. *> the lower triangular part of the matrix A.
  100. *>
  101. *> On exit, the lower triangle (if UPLO='L') or the upper
  102. *> triangle (if UPLO='U') of A, including the diagonal, is
  103. *> destroyed.
  104. *> \endverbatim
  105. *>
  106. *> \param[in] LDA
  107. *> \verbatim
  108. *> LDA is INTEGER
  109. *> The leading dimension of the array A. LDA >= max(1,N).
  110. *> \endverbatim
  111. *>
  112. *> \param[in,out] B
  113. *> \verbatim
  114. *> B is COMPLEX array, dimension (LDB, N)
  115. *> On entry, the Hermitian matrix B. If UPLO = 'U', the
  116. *> leading N-by-N upper triangular part of B contains the
  117. *> upper triangular part of the matrix B. If UPLO = 'L',
  118. *> the leading N-by-N lower triangular part of B contains
  119. *> the lower triangular part of the matrix B.
  120. *>
  121. *> On exit, if INFO <= N, the part of B containing the matrix is
  122. *> overwritten by the triangular factor U or L from the Cholesky
  123. *> factorization B = U**H*U or B = L*L**H.
  124. *> \endverbatim
  125. *>
  126. *> \param[in] LDB
  127. *> \verbatim
  128. *> LDB is INTEGER
  129. *> The leading dimension of the array B. LDB >= max(1,N).
  130. *> \endverbatim
  131. *>
  132. *> \param[in] VL
  133. *> \verbatim
  134. *> VL is REAL
  135. *> \endverbatim
  136. *>
  137. *> \param[in] VU
  138. *> \verbatim
  139. *> VU is REAL
  140. *>
  141. *> If RANGE='V', the lower and upper bounds of the interval to
  142. *> be searched for eigenvalues. VL < VU.
  143. *> Not referenced if RANGE = 'A' or 'I'.
  144. *> \endverbatim
  145. *>
  146. *> \param[in] IL
  147. *> \verbatim
  148. *> IL is INTEGER
  149. *> \endverbatim
  150. *>
  151. *> \param[in] IU
  152. *> \verbatim
  153. *> IU is INTEGER
  154. *>
  155. *> If RANGE='I', the indices (in ascending order) of the
  156. *> smallest and largest eigenvalues to be returned.
  157. *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
  158. *> Not referenced if RANGE = 'A' or 'V'.
  159. *> \endverbatim
  160. *>
  161. *> \param[in] ABSTOL
  162. *> \verbatim
  163. *> ABSTOL is REAL
  164. *> The absolute error tolerance for the eigenvalues.
  165. *> An approximate eigenvalue is accepted as converged
  166. *> when it is determined to lie in an interval [a,b]
  167. *> of width less than or equal to
  168. *>
  169. *> ABSTOL + EPS * max( |a|,|b| ) ,
  170. *>
  171. *> where EPS is the machine precision. If ABSTOL is less than
  172. *> or equal to zero, then EPS*|T| will be used in its place,
  173. *> where |T| is the 1-norm of the tridiagonal matrix obtained
  174. *> by reducing C to tridiagonal form, where C is the symmetric
  175. *> matrix of the standard symmetric problem to which the
  176. *> generalized problem is transformed.
  177. *>
  178. *> Eigenvalues will be computed most accurately when ABSTOL is
  179. *> set to twice the underflow threshold 2*SLAMCH('S'), not zero.
  180. *> If this routine returns with INFO>0, indicating that some
  181. *> eigenvectors did not converge, try setting ABSTOL to
  182. *> 2*SLAMCH('S').
  183. *> \endverbatim
  184. *>
  185. *> \param[out] M
  186. *> \verbatim
  187. *> M is INTEGER
  188. *> The total number of eigenvalues found. 0 <= M <= N.
  189. *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
  190. *> \endverbatim
  191. *>
  192. *> \param[out] W
  193. *> \verbatim
  194. *> W is REAL array, dimension (N)
  195. *> The first M elements contain the selected
  196. *> eigenvalues in ascending order.
  197. *> \endverbatim
  198. *>
  199. *> \param[out] Z
  200. *> \verbatim
  201. *> Z is COMPLEX array, dimension (LDZ, max(1,M))
  202. *> If JOBZ = 'N', then Z is not referenced.
  203. *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z
  204. *> contain the orthonormal eigenvectors of the matrix A
  205. *> corresponding to the selected eigenvalues, with the i-th
  206. *> column of Z holding the eigenvector associated with W(i).
  207. *> The eigenvectors are normalized as follows:
  208. *> if ITYPE = 1 or 2, Z**T*B*Z = I;
  209. *> if ITYPE = 3, Z**T*inv(B)*Z = I.
  210. *>
  211. *> If an eigenvector fails to converge, then that column of Z
  212. *> contains the latest approximation to the eigenvector, and the
  213. *> index of the eigenvector is returned in IFAIL.
  214. *> Note: the user must ensure that at least max(1,M) columns are
  215. *> supplied in the array Z; if RANGE = 'V', the exact value of M
  216. *> is not known in advance and an upper bound must be used.
  217. *> \endverbatim
  218. *>
  219. *> \param[in] LDZ
  220. *> \verbatim
  221. *> LDZ is INTEGER
  222. *> The leading dimension of the array Z. LDZ >= 1, and if
  223. *> JOBZ = 'V', LDZ >= max(1,N).
  224. *> \endverbatim
  225. *>
  226. *> \param[out] WORK
  227. *> \verbatim
  228. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  229. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  230. *> \endverbatim
  231. *>
  232. *> \param[in] LWORK
  233. *> \verbatim
  234. *> LWORK is INTEGER
  235. *> The length of the array WORK. LWORK >= max(1,2*N).
  236. *> For optimal efficiency, LWORK >= (NB+1)*N,
  237. *> where NB is the blocksize for CHETRD returned by ILAENV.
  238. *>
  239. *> If LWORK = -1, then a workspace query is assumed; the routine
  240. *> only calculates the optimal size of the WORK array, returns
  241. *> this value as the first entry of the WORK array, and no error
  242. *> message related to LWORK is issued by XERBLA.
  243. *> \endverbatim
  244. *>
  245. *> \param[out] RWORK
  246. *> \verbatim
  247. *> RWORK is REAL array, dimension (7*N)
  248. *> \endverbatim
  249. *>
  250. *> \param[out] IWORK
  251. *> \verbatim
  252. *> IWORK is INTEGER array, dimension (5*N)
  253. *> \endverbatim
  254. *>
  255. *> \param[out] IFAIL
  256. *> \verbatim
  257. *> IFAIL is INTEGER array, dimension (N)
  258. *> If JOBZ = 'V', then if INFO = 0, the first M elements of
  259. *> IFAIL are zero. If INFO > 0, then IFAIL contains the
  260. *> indices of the eigenvectors that failed to converge.
  261. *> If JOBZ = 'N', then IFAIL is not referenced.
  262. *> \endverbatim
  263. *>
  264. *> \param[out] INFO
  265. *> \verbatim
  266. *> INFO is INTEGER
  267. *> = 0: successful exit
  268. *> < 0: if INFO = -i, the i-th argument had an illegal value
  269. *> > 0: CPOTRF or CHEEVX returned an error code:
  270. *> <= N: if INFO = i, CHEEVX failed to converge;
  271. *> i eigenvectors failed to converge. Their indices
  272. *> are stored in array IFAIL.
  273. *> > N: if INFO = N + i, for 1 <= i <= N, then the leading
  274. *> minor of order i of B is not positive definite.
  275. *> The factorization of B could not be completed and
  276. *> no eigenvalues or eigenvectors were computed.
  277. *> \endverbatim
  278. *
  279. * Authors:
  280. * ========
  281. *
  282. *> \author Univ. of Tennessee
  283. *> \author Univ. of California Berkeley
  284. *> \author Univ. of Colorado Denver
  285. *> \author NAG Ltd.
  286. *
  287. *> \date November 2011
  288. *
  289. *> \ingroup complexHEeigen
  290. *
  291. *> \par Contributors:
  292. * ==================
  293. *>
  294. *> Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA
  295. *
  296. * =====================================================================
  297. SUBROUTINE CHEGVX( ITYPE, JOBZ, RANGE, UPLO, N, A, LDA, B, LDB,
  298. $ VL, VU, IL, IU, ABSTOL, M, W, Z, LDZ, WORK,
  299. $ LWORK, RWORK, IWORK, IFAIL, INFO )
  300. *
  301. * -- LAPACK driver routine (version 3.4.0) --
  302. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  303. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  304. * November 2011
  305. *
  306. * .. Scalar Arguments ..
  307. CHARACTER JOBZ, RANGE, UPLO
  308. INTEGER IL, INFO, ITYPE, IU, LDA, LDB, LDZ, LWORK, M, N
  309. REAL ABSTOL, VL, VU
  310. * ..
  311. * .. Array Arguments ..
  312. INTEGER IFAIL( * ), IWORK( * )
  313. REAL RWORK( * ), W( * )
  314. COMPLEX A( LDA, * ), B( LDB, * ), WORK( * ),
  315. $ Z( LDZ, * )
  316. * ..
  317. *
  318. * =====================================================================
  319. *
  320. * .. Parameters ..
  321. COMPLEX CONE
  322. PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
  323. * ..
  324. * .. Local Scalars ..
  325. LOGICAL ALLEIG, INDEIG, LQUERY, UPPER, VALEIG, WANTZ
  326. CHARACTER TRANS
  327. INTEGER LWKOPT, NB
  328. * ..
  329. * .. External Functions ..
  330. LOGICAL LSAME
  331. INTEGER ILAENV
  332. EXTERNAL ILAENV, LSAME
  333. * ..
  334. * .. External Subroutines ..
  335. EXTERNAL CHEEVX, CHEGST, CPOTRF, CTRMM, CTRSM, XERBLA
  336. * ..
  337. * .. Intrinsic Functions ..
  338. INTRINSIC MAX, MIN
  339. * ..
  340. * .. Executable Statements ..
  341. *
  342. * Test the input parameters.
  343. *
  344. WANTZ = LSAME( JOBZ, 'V' )
  345. UPPER = LSAME( UPLO, 'U' )
  346. ALLEIG = LSAME( RANGE, 'A' )
  347. VALEIG = LSAME( RANGE, 'V' )
  348. INDEIG = LSAME( RANGE, 'I' )
  349. LQUERY = ( LWORK.EQ.-1 )
  350. *
  351. INFO = 0
  352. IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
  353. INFO = -1
  354. ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  355. INFO = -2
  356. ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
  357. INFO = -3
  358. ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
  359. INFO = -4
  360. ELSE IF( N.LT.0 ) THEN
  361. INFO = -5
  362. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  363. INFO = -7
  364. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  365. INFO = -9
  366. ELSE
  367. IF( VALEIG ) THEN
  368. IF( N.GT.0 .AND. VU.LE.VL )
  369. $ INFO = -11
  370. ELSE IF( INDEIG ) THEN
  371. IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
  372. INFO = -12
  373. ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
  374. INFO = -13
  375. END IF
  376. END IF
  377. END IF
  378. IF (INFO.EQ.0) THEN
  379. IF (LDZ.LT.1 .OR. (WANTZ .AND. LDZ.LT.N)) THEN
  380. INFO = -18
  381. END IF
  382. END IF
  383. *
  384. IF( INFO.EQ.0 ) THEN
  385. NB = ILAENV( 1, 'CHETRD', UPLO, N, -1, -1, -1 )
  386. LWKOPT = MAX( 1, ( NB + 1 )*N )
  387. WORK( 1 ) = LWKOPT
  388. *
  389. IF( LWORK.LT.MAX( 1, 2*N ) .AND. .NOT.LQUERY ) THEN
  390. INFO = -20
  391. END IF
  392. END IF
  393. *
  394. IF( INFO.NE.0 ) THEN
  395. CALL XERBLA( 'CHEGVX', -INFO )
  396. RETURN
  397. ELSE IF( LQUERY ) THEN
  398. RETURN
  399. END IF
  400. *
  401. * Quick return if possible
  402. *
  403. M = 0
  404. IF( N.EQ.0 ) THEN
  405. RETURN
  406. END IF
  407. *
  408. * Form a Cholesky factorization of B.
  409. *
  410. CALL CPOTRF( UPLO, N, B, LDB, INFO )
  411. IF( INFO.NE.0 ) THEN
  412. INFO = N + INFO
  413. RETURN
  414. END IF
  415. *
  416. * Transform problem to standard eigenvalue problem and solve.
  417. *
  418. CALL CHEGST( ITYPE, UPLO, N, A, LDA, B, LDB, INFO )
  419. CALL CHEEVX( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU, ABSTOL,
  420. $ M, W, Z, LDZ, WORK, LWORK, RWORK, IWORK, IFAIL,
  421. $ INFO )
  422. *
  423. IF( WANTZ ) THEN
  424. *
  425. * Backtransform eigenvectors to the original problem.
  426. *
  427. IF( INFO.GT.0 )
  428. $ M = INFO - 1
  429. IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
  430. *
  431. * For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
  432. * backtransform eigenvectors: x = inv(L)**H*y or inv(U)*y
  433. *
  434. IF( UPPER ) THEN
  435. TRANS = 'N'
  436. ELSE
  437. TRANS = 'C'
  438. END IF
  439. *
  440. CALL CTRSM( 'Left', UPLO, TRANS, 'Non-unit', N, M, CONE, B,
  441. $ LDB, Z, LDZ )
  442. *
  443. ELSE IF( ITYPE.EQ.3 ) THEN
  444. *
  445. * For B*A*x=(lambda)*x;
  446. * backtransform eigenvectors: x = L*y or U**H*y
  447. *
  448. IF( UPPER ) THEN
  449. TRANS = 'C'
  450. ELSE
  451. TRANS = 'N'
  452. END IF
  453. *
  454. CALL CTRMM( 'Left', UPLO, TRANS, 'Non-unit', N, M, CONE, B,
  455. $ LDB, Z, LDZ )
  456. END IF
  457. END IF
  458. *
  459. * Set WORK(1) to optimal complex workspace size.
  460. *
  461. WORK( 1 ) = LWKOPT
  462. *
  463. RETURN
  464. *
  465. * End of CHEGVX
  466. *
  467. END