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.

dsbevd.f 11 kB

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