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.

sstevd.f 8.7 kB

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