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.

sspevd.f 10 kB

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