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.

ssterf.f 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. *> \brief \b SSTERF
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SSTERF + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssterf.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssterf.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssterf.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SSTERF( N, D, E, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * INTEGER INFO, N
  25. * ..
  26. * .. Array Arguments ..
  27. * REAL D( * ), E( * )
  28. * ..
  29. *
  30. *
  31. *> \par Purpose:
  32. * =============
  33. *>
  34. *> \verbatim
  35. *>
  36. *> SSTERF computes all eigenvalues of a symmetric tridiagonal matrix
  37. *> using the Pal-Walker-Kahan variant of the QL or QR algorithm.
  38. *> \endverbatim
  39. *
  40. * Arguments:
  41. * ==========
  42. *
  43. *> \param[in] N
  44. *> \verbatim
  45. *> N is INTEGER
  46. *> The order of the matrix. N >= 0.
  47. *> \endverbatim
  48. *>
  49. *> \param[in,out] D
  50. *> \verbatim
  51. *> D is REAL array, dimension (N)
  52. *> On entry, the n diagonal elements of the tridiagonal matrix.
  53. *> On exit, if INFO = 0, the eigenvalues in ascending order.
  54. *> \endverbatim
  55. *>
  56. *> \param[in,out] E
  57. *> \verbatim
  58. *> E is REAL array, dimension (N-1)
  59. *> On entry, the (n-1) subdiagonal elements of the tridiagonal
  60. *> matrix.
  61. *> On exit, E has been destroyed.
  62. *> \endverbatim
  63. *>
  64. *> \param[out] INFO
  65. *> \verbatim
  66. *> INFO is INTEGER
  67. *> = 0: successful exit
  68. *> < 0: if INFO = -i, the i-th argument had an illegal value
  69. *> > 0: the algorithm failed to find all of the eigenvalues in
  70. *> a total of 30*N iterations; if INFO = i, then i
  71. *> elements of E have not converged to zero.
  72. *> \endverbatim
  73. *
  74. * Authors:
  75. * ========
  76. *
  77. *> \author Univ. of Tennessee
  78. *> \author Univ. of California Berkeley
  79. *> \author Univ. of Colorado Denver
  80. *> \author NAG Ltd.
  81. *
  82. *> \ingroup auxOTHERcomputational
  83. *
  84. * =====================================================================
  85. SUBROUTINE SSTERF( N, D, E, INFO )
  86. *
  87. * -- LAPACK computational routine --
  88. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  89. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  90. *
  91. * .. Scalar Arguments ..
  92. INTEGER INFO, N
  93. * ..
  94. * .. Array Arguments ..
  95. REAL D( * ), E( * )
  96. * ..
  97. *
  98. * =====================================================================
  99. *
  100. * .. Parameters ..
  101. REAL ZERO, ONE, TWO, THREE
  102. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0, TWO = 2.0E0,
  103. $ THREE = 3.0E0 )
  104. INTEGER MAXIT
  105. PARAMETER ( MAXIT = 30 )
  106. * ..
  107. * .. Local Scalars ..
  108. INTEGER I, ISCALE, JTOT, L, L1, LEND, LENDSV, LSV, M,
  109. $ NMAXIT
  110. REAL ALPHA, ANORM, BB, C, EPS, EPS2, GAMMA, OLDC,
  111. $ OLDGAM, P, R, RT1, RT2, RTE, S, SAFMAX, SAFMIN,
  112. $ SIGMA, SSFMAX, SSFMIN
  113. * ..
  114. * .. External Functions ..
  115. REAL SLAMCH, SLANST, SLAPY2
  116. EXTERNAL SLAMCH, SLANST, SLAPY2
  117. * ..
  118. * .. External Subroutines ..
  119. EXTERNAL SLAE2, SLASCL, SLASRT, XERBLA
  120. * ..
  121. * .. Intrinsic Functions ..
  122. INTRINSIC ABS, SIGN, SQRT
  123. * ..
  124. * .. Executable Statements ..
  125. *
  126. * Test the input parameters.
  127. *
  128. INFO = 0
  129. *
  130. * Quick return if possible
  131. *
  132. IF( N.LT.0 ) THEN
  133. INFO = -1
  134. CALL XERBLA( 'SSTERF', -INFO )
  135. RETURN
  136. END IF
  137. IF( N.LE.1 )
  138. $ RETURN
  139. *
  140. * Determine the unit roundoff for this environment.
  141. *
  142. EPS = SLAMCH( 'E' )
  143. EPS2 = EPS**2
  144. SAFMIN = SLAMCH( 'S' )
  145. SAFMAX = ONE / SAFMIN
  146. SSFMAX = SQRT( SAFMAX ) / THREE
  147. SSFMIN = SQRT( SAFMIN ) / EPS2
  148. *
  149. * Compute the eigenvalues of the tridiagonal matrix.
  150. *
  151. NMAXIT = N*MAXIT
  152. SIGMA = ZERO
  153. JTOT = 0
  154. *
  155. * Determine where the matrix splits and choose QL or QR iteration
  156. * for each block, according to whether top or bottom diagonal
  157. * element is smaller.
  158. *
  159. L1 = 1
  160. *
  161. 10 CONTINUE
  162. IF( L1.GT.N )
  163. $ GO TO 170
  164. IF( L1.GT.1 )
  165. $ E( L1-1 ) = ZERO
  166. DO 20 M = L1, N - 1
  167. IF( ABS( E( M ) ).LE.( SQRT( ABS( D( M ) ) )*
  168. $ SQRT( ABS( D( M+1 ) ) ) )*EPS ) THEN
  169. E( M ) = ZERO
  170. GO TO 30
  171. END IF
  172. 20 CONTINUE
  173. M = N
  174. *
  175. 30 CONTINUE
  176. L = L1
  177. LSV = L
  178. LEND = M
  179. LENDSV = LEND
  180. L1 = M + 1
  181. IF( LEND.EQ.L )
  182. $ GO TO 10
  183. *
  184. * Scale submatrix in rows and columns L to LEND
  185. *
  186. ANORM = SLANST( 'M', LEND-L+1, D( L ), E( L ) )
  187. ISCALE = 0
  188. IF( ANORM.EQ.ZERO )
  189. $ GO TO 10
  190. IF( ANORM.GT.SSFMAX ) THEN
  191. ISCALE = 1
  192. CALL SLASCL( 'G', 0, 0, ANORM, SSFMAX, LEND-L+1, 1, D( L ), N,
  193. $ INFO )
  194. CALL SLASCL( 'G', 0, 0, ANORM, SSFMAX, LEND-L, 1, E( L ), N,
  195. $ INFO )
  196. ELSE IF( ANORM.LT.SSFMIN ) THEN
  197. ISCALE = 2
  198. CALL SLASCL( 'G', 0, 0, ANORM, SSFMIN, LEND-L+1, 1, D( L ), N,
  199. $ INFO )
  200. CALL SLASCL( 'G', 0, 0, ANORM, SSFMIN, LEND-L, 1, E( L ), N,
  201. $ INFO )
  202. END IF
  203. *
  204. DO 40 I = L, LEND - 1
  205. E( I ) = E( I )**2
  206. 40 CONTINUE
  207. *
  208. * Choose between QL and QR iteration
  209. *
  210. IF( ABS( D( LEND ) ).LT.ABS( D( L ) ) ) THEN
  211. LEND = LSV
  212. L = LENDSV
  213. END IF
  214. *
  215. IF( LEND.GE.L ) THEN
  216. *
  217. * QL Iteration
  218. *
  219. * Look for small subdiagonal element.
  220. *
  221. 50 CONTINUE
  222. IF( L.NE.LEND ) THEN
  223. DO 60 M = L, LEND - 1
  224. IF( ABS( E( M ) ).LE.EPS2*ABS( D( M )*D( M+1 ) ) )
  225. $ GO TO 70
  226. 60 CONTINUE
  227. END IF
  228. M = LEND
  229. *
  230. 70 CONTINUE
  231. IF( M.LT.LEND )
  232. $ E( M ) = ZERO
  233. P = D( L )
  234. IF( M.EQ.L )
  235. $ GO TO 90
  236. *
  237. * If remaining matrix is 2 by 2, use SLAE2 to compute its
  238. * eigenvalues.
  239. *
  240. IF( M.EQ.L+1 ) THEN
  241. RTE = SQRT( E( L ) )
  242. CALL SLAE2( D( L ), RTE, D( L+1 ), RT1, RT2 )
  243. D( L ) = RT1
  244. D( L+1 ) = RT2
  245. E( L ) = ZERO
  246. L = L + 2
  247. IF( L.LE.LEND )
  248. $ GO TO 50
  249. GO TO 150
  250. END IF
  251. *
  252. IF( JTOT.EQ.NMAXIT )
  253. $ GO TO 150
  254. JTOT = JTOT + 1
  255. *
  256. * Form shift.
  257. *
  258. RTE = SQRT( E( L ) )
  259. SIGMA = ( D( L+1 )-P ) / ( TWO*RTE )
  260. R = SLAPY2( SIGMA, ONE )
  261. SIGMA = P - ( RTE / ( SIGMA+SIGN( R, SIGMA ) ) )
  262. *
  263. C = ONE
  264. S = ZERO
  265. GAMMA = D( M ) - SIGMA
  266. P = GAMMA*GAMMA
  267. *
  268. * Inner loop
  269. *
  270. DO 80 I = M - 1, L, -1
  271. BB = E( I )
  272. R = P + BB
  273. IF( I.NE.M-1 )
  274. $ E( I+1 ) = S*R
  275. OLDC = C
  276. C = P / R
  277. S = BB / R
  278. OLDGAM = GAMMA
  279. ALPHA = D( I )
  280. GAMMA = C*( ALPHA-SIGMA ) - S*OLDGAM
  281. D( I+1 ) = OLDGAM + ( ALPHA-GAMMA )
  282. IF( C.NE.ZERO ) THEN
  283. P = ( GAMMA*GAMMA ) / C
  284. ELSE
  285. P = OLDC*BB
  286. END IF
  287. 80 CONTINUE
  288. *
  289. E( L ) = S*P
  290. D( L ) = SIGMA + GAMMA
  291. GO TO 50
  292. *
  293. * Eigenvalue found.
  294. *
  295. 90 CONTINUE
  296. D( L ) = P
  297. *
  298. L = L + 1
  299. IF( L.LE.LEND )
  300. $ GO TO 50
  301. GO TO 150
  302. *
  303. ELSE
  304. *
  305. * QR Iteration
  306. *
  307. * Look for small superdiagonal element.
  308. *
  309. 100 CONTINUE
  310. DO 110 M = L, LEND + 1, -1
  311. IF( ABS( E( M-1 ) ).LE.EPS2*ABS( D( M )*D( M-1 ) ) )
  312. $ GO TO 120
  313. 110 CONTINUE
  314. M = LEND
  315. *
  316. 120 CONTINUE
  317. IF( M.GT.LEND )
  318. $ E( M-1 ) = ZERO
  319. P = D( L )
  320. IF( M.EQ.L )
  321. $ GO TO 140
  322. *
  323. * If remaining matrix is 2 by 2, use SLAE2 to compute its
  324. * eigenvalues.
  325. *
  326. IF( M.EQ.L-1 ) THEN
  327. RTE = SQRT( E( L-1 ) )
  328. CALL SLAE2( D( L ), RTE, D( L-1 ), RT1, RT2 )
  329. D( L ) = RT1
  330. D( L-1 ) = RT2
  331. E( L-1 ) = ZERO
  332. L = L - 2
  333. IF( L.GE.LEND )
  334. $ GO TO 100
  335. GO TO 150
  336. END IF
  337. *
  338. IF( JTOT.EQ.NMAXIT )
  339. $ GO TO 150
  340. JTOT = JTOT + 1
  341. *
  342. * Form shift.
  343. *
  344. RTE = SQRT( E( L-1 ) )
  345. SIGMA = ( D( L-1 )-P ) / ( TWO*RTE )
  346. R = SLAPY2( SIGMA, ONE )
  347. SIGMA = P - ( RTE / ( SIGMA+SIGN( R, SIGMA ) ) )
  348. *
  349. C = ONE
  350. S = ZERO
  351. GAMMA = D( M ) - SIGMA
  352. P = GAMMA*GAMMA
  353. *
  354. * Inner loop
  355. *
  356. DO 130 I = M, L - 1
  357. BB = E( I )
  358. R = P + BB
  359. IF( I.NE.M )
  360. $ E( I-1 ) = S*R
  361. OLDC = C
  362. C = P / R
  363. S = BB / R
  364. OLDGAM = GAMMA
  365. ALPHA = D( I+1 )
  366. GAMMA = C*( ALPHA-SIGMA ) - S*OLDGAM
  367. D( I ) = OLDGAM + ( ALPHA-GAMMA )
  368. IF( C.NE.ZERO ) THEN
  369. P = ( GAMMA*GAMMA ) / C
  370. ELSE
  371. P = OLDC*BB
  372. END IF
  373. 130 CONTINUE
  374. *
  375. E( L-1 ) = S*P
  376. D( L ) = SIGMA + GAMMA
  377. GO TO 100
  378. *
  379. * Eigenvalue found.
  380. *
  381. 140 CONTINUE
  382. D( L ) = P
  383. *
  384. L = L - 1
  385. IF( L.GE.LEND )
  386. $ GO TO 100
  387. GO TO 150
  388. *
  389. END IF
  390. *
  391. * Undo scaling if necessary
  392. *
  393. 150 CONTINUE
  394. IF( ISCALE.EQ.1 )
  395. $ CALL SLASCL( 'G', 0, 0, SSFMAX, ANORM, LENDSV-LSV+1, 1,
  396. $ D( LSV ), N, INFO )
  397. IF( ISCALE.EQ.2 )
  398. $ CALL SLASCL( 'G', 0, 0, SSFMIN, ANORM, LENDSV-LSV+1, 1,
  399. $ D( LSV ), N, INFO )
  400. *
  401. * Check for no convergence to an eigenvalue after a total
  402. * of N*MAXIT iterations.
  403. *
  404. IF( JTOT.LT.NMAXIT )
  405. $ GO TO 10
  406. DO 160 I = 1, N - 1
  407. IF( E( I ).NE.ZERO )
  408. $ INFO = INFO + 1
  409. 160 CONTINUE
  410. GO TO 180
  411. *
  412. * Sort eigenvalues in increasing order.
  413. *
  414. 170 CONTINUE
  415. CALL SLASRT( 'I', N, D, INFO )
  416. *
  417. 180 CONTINUE
  418. RETURN
  419. *
  420. * End of SSTERF
  421. *
  422. END