Télécharger dsteqr.eso

Retour à la liste

Numérotation des lignes :

dsteqr
  1. C DSTEQR SOURCE FANDEUR 22/05/02 21:15:16 11359
  2. *> \brief \b DSTEQR
  3. *
  4. * =========== DOCUMENTATION ===========
  5. *
  6. * Online html documentation available at
  7. * http://www.netlib.org/lapack/explore-html/
  8. *
  9. *> \htmlonly
  10. *> Download DSTEQR + dependencies
  11. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsteqr.f">
  12. *> [TGZ]</a>
  13. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsteqr.f">
  14. *> [ZIP]</a>
  15. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsteqr.f">
  16. *> [TXT]</a>
  17. *> \endhtmlonly
  18. *
  19. * Definition:
  20. * ===========
  21. *
  22. * SUBROUTINE DSTEQR( COMPZ, N, D, E, Z, LDZ, WORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER COMPZ
  26. * INTEGER INFO, LDZ, N
  27. * ..
  28. * .. Array Arguments ..
  29. * REAL*8 D( * ), E( * ), WORK( * ), Z( LDZ, * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> DSTEQR computes all eigenvalues and, optionally, eigenvectors of a
  39. *> symmetric tridiagonal matrix using the implicit QL or QR method.
  40. *> The eigenvectors of a full or band symmetric matrix can also be found
  41. *> if DSYTRD or DSPTRD or DSBTRD has been used to reduce this matrix to
  42. *> tridiagonal form.
  43. *> \endverbatim
  44. *
  45. * Arguments:
  46. * ==========
  47. *
  48. *> \param[in] COMPZ
  49. *> \verbatim
  50. *> COMPZ is CHARACTER*1
  51. *> = 'N': Compute eigenvalues only.
  52. *> = 'V': Compute eigenvalues and eigenvectors of the original
  53. *> symmetric matrix. On entry, Z must contain the
  54. *> orthogonal matrix used to reduce the original matrix
  55. *> to tridiagonal form.
  56. *> = 'I': Compute eigenvalues and eigenvectors of the
  57. *> tridiagonal matrix. Z is initialized to the identity
  58. *> matrix.
  59. *> \endverbatim
  60. *>
  61. *> \param[in] N
  62. *> \verbatim
  63. *> N is INTEGER
  64. *> The order of the matrix. N >= 0.
  65. *> \endverbatim
  66. *>
  67. *> \param[in,out] D
  68. *> \verbatim
  69. *> D is DOUBLE PRECISION array, dimension (N)
  70. *> On entry, the diagonal elements of the tridiagonal matrix.
  71. *> On exit, if INFO = 0, the eigenvalues in ascending order.
  72. *> \endverbatim
  73. *>
  74. *> \param[in,out] E
  75. *> \verbatim
  76. *> E is DOUBLE PRECISION array, dimension (N-1)
  77. *> On entry, the (n-1) subdiagonal elements of the tridiagonal
  78. *> matrix.
  79. *> On exit, E has been destroyed.
  80. *> \endverbatim
  81. *>
  82. *> \param[in,out] Z
  83. *> \verbatim
  84. *> Z is DOUBLE PRECISION array, dimension (LDZ, N)
  85. *> On entry, if COMPZ = 'V', then Z contains the orthogonal
  86. *> matrix used in the reduction to tridiagonal form.
  87. *> On exit, if INFO = 0, then if COMPZ = 'V', Z contains the
  88. *> orthonormal eigenvectors of the original symmetric matrix,
  89. *> and if COMPZ = 'I', Z contains the orthonormal eigenvectors
  90. *> of the symmetric tridiagonal matrix.
  91. *> If COMPZ = 'N', then Z is not referenced.
  92. *> \endverbatim
  93. *>
  94. *> \param[in] LDZ
  95. *> \verbatim
  96. *> LDZ is INTEGER
  97. *> The leading dimension of the array Z. LDZ >= 1, and if
  98. *> eigenvectors are desired, then LDZ >= max(1,N).
  99. *> \endverbatim
  100. *>
  101. *> \param[out] WORK
  102. *> \verbatim
  103. *> WORK is DOUBLE PRECISION array, dimension (max(1,2*N-2))
  104. *> If COMPZ = 'N', then WORK is not referenced.
  105. *> \endverbatim
  106. *>
  107. *> \param[out] INFO
  108. *> \verbatim
  109. *> INFO is INTEGER
  110. *> = 0: successful exit
  111. *> < 0: if INFO = -i, the i-th argument had an illegal value
  112. *> > 0: the algorithm has failed to find all the eigenvalues in
  113. *> a total of 30*N iterations; if INFO = i, then i
  114. *> elements of E have not converged to zero; on exit, D
  115. *> and E contain the elements of a symmetric tridiagonal
  116. *> matrix which is orthogonally similar to the original
  117. *> matrix.
  118. *> \endverbatim
  119. *
  120. * Authors:
  121. * ========
  122. *
  123. *> \author Univ. of Tennessee
  124. *> \author Univ. of California Berkeley
  125. *> \author Univ. of Colorado Denver
  126. *> \author NAG Ltd.
  127. *
  128. *> \date December 2016
  129. *
  130. *> \ingroup auxOTHERcomputational
  131. *
  132. * =====================================================================
  133. SUBROUTINE DSTEQR( COMPZ, N, D, E, Z, LDZ, WORK, INFO )
  134. *
  135. * -- LAPACK computational routine (version 3.7.0) --
  136. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  137. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  138. * December 2016
  139. *
  140. * .. Scalar Arguments ..
  141. CHARACTER COMPZ
  142. INTEGER INFO, LDZ, N
  143. * ..
  144. * .. Array Arguments ..
  145. REAL*8 D( * ), E( * ), WORK( * ), Z( LDZ, * )
  146. * ..
  147. *
  148. * =====================================================================
  149. *
  150. * .. Parameters ..
  151. REAL*8 ZERO, ONE, TWO, THREE
  152. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,
  153. $ THREE = 3.0D0 )
  154. INTEGER MAXIT
  155. PARAMETER ( MAXIT = 30 )
  156. * ..
  157. * .. Local Scalars ..
  158. INTEGER I, ICOMPZ, II, ISCALE, J, JTOT, K, L, L1, LEND,
  159. $ LENDM1, LENDP1, LENDSV, LM1, LSV, M, MM, MM1,
  160. $ NM1, NMAXIT
  161. REAL*8 ANORM, B, C, EPS, EPS2, F, G, P, R, RT1, RT2,
  162. $ S, SAFMAX, SAFMIN, SSFMAX, SSFMIN, TST
  163. * ..
  164. * .. External Functions ..
  165. LOGICAL LSAME
  166. REAL*8 DLAMCH, DLANST, DLAPY2
  167. EXTERNAL LSAME, DLAMCH, DLANST, DLAPY2
  168. * ..
  169. * .. External Subroutines ..
  170. EXTERNAL DLAE2, DLAEV2, DLARTG,
  171. * ..
  172. ** .. Intrinsic Functions ..
  173. * INTRINSIC ABS, MAX, SIGN, SQRT
  174. ** ..
  175. ** .. Executable Statements ..
  176. *
  177. * Test the input parameters.
  178. *
  179. INFO = 0
  180. *
  181. IF( LSAME( COMPZ, 'N' ) ) THEN
  182. ICOMPZ = 0
  183. ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
  184. ICOMPZ = 1
  185. ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
  186. ICOMPZ = 2
  187. ELSE
  188. ICOMPZ = -1
  189. END IF
  190. IF( ICOMPZ.LT.0 ) THEN
  191. INFO = -1
  192. ELSE IF( N.LT.0 ) THEN
  193. INFO = -2
  194. ELSE IF( ( LDZ.LT.1 ) .OR. ( ICOMPZ.GT.0 .AND. LDZ.LT.MAX( 1,
  195. $ N ) ) ) THEN
  196. INFO = -6
  197. END IF
  198. IF( INFO.NE.0 ) THEN
  199. CALL XERBLA( 'DSTEQR', -INFO )
  200. RETURN
  201. END IF
  202. *
  203. * Quick return if possible
  204. *
  205. IF( N.EQ.0 )
  206. $ RETURN
  207. *
  208. IF( N.EQ.1 ) THEN
  209. IF( ICOMPZ.EQ.2 )
  210. $ Z( 1, 1 ) = ONE
  211. RETURN
  212. END IF
  213. *
  214. * Determine the unit roundoff and over/underflow thresholds.
  215. *
  216. EPS = DLAMCH( 'E' )
  217. EPS2 = EPS**2
  218. SAFMIN = DLAMCH( 'S' )
  219. SAFMAX = ONE / SAFMIN
  220. SSFMAX = SQRT( SAFMAX ) / THREE
  221. SSFMIN = SQRT( SAFMIN ) / EPS2
  222. *
  223. * Compute the eigenvalues and eigenvectors of the tridiagonal
  224. * matrix.
  225. *
  226. IF( ICOMPZ.EQ.2 )
  227. $ CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
  228. *
  229. NMAXIT = N*MAXIT
  230. JTOT = 0
  231. *
  232. * Determine where the matrix splits and choose QL or QR iteration
  233. * for each block, according to whether top or bottom diagonal
  234. * element is smaller.
  235. *
  236. L1 = 1
  237. NM1 = N - 1
  238. *
  239. 10 CONTINUE
  240. IF( L1.GT.N )
  241. $ GO TO 160
  242. IF( L1.GT.1 )
  243. $ E( L1-1 ) = ZERO
  244. IF( L1.LE.NM1 ) THEN
  245. DO 20 M = L1, NM1
  246. TST = ABS( E( M ) )
  247. IF( TST.EQ.ZERO )
  248. $ GO TO 30
  249. IF( TST.LE.( SQRT( ABS( D( M ) ) )*SQRT( ABS( D( M+
  250. $ 1 ) ) ) )*EPS ) THEN
  251. E( M ) = ZERO
  252. GO TO 30
  253. END IF
  254. 20 CONTINUE
  255. END IF
  256. M = N
  257. *
  258. 30 CONTINUE
  259. L = L1
  260. LSV = L
  261. LEND = M
  262. LENDSV = LEND
  263. L1 = M + 1
  264. IF( LEND.EQ.L )
  265. $ GO TO 10
  266. *
  267. * Scale submatrix in rows and columns L to LEND
  268. *
  269. ANORM = DLANST( 'M', LEND-L+1, D( L ), E( L ) )
  270. ISCALE = 0
  271. IF( ANORM.EQ.ZERO )
  272. $ GO TO 10
  273. IF( ANORM.GT.SSFMAX ) THEN
  274. ISCALE = 1
  275. CALL DLASCL( 'G', 0, 0, ANORM, SSFMAX, LEND-L+1, 1, D( L ), N,
  276. $ INFO )
  277. CALL DLASCL( 'G', 0, 0, ANORM, SSFMAX, LEND-L, 1, E( L ), N,
  278. $ INFO )
  279. ELSE IF( ANORM.LT.SSFMIN ) THEN
  280. ISCALE = 2
  281. CALL DLASCL( 'G', 0, 0, ANORM, SSFMIN, LEND-L+1, 1, D( L ), N,
  282. $ INFO )
  283. CALL DLASCL( 'G', 0, 0, ANORM, SSFMIN, LEND-L, 1, E( L ), N,
  284. $ INFO )
  285. END IF
  286. *
  287. * Choose between QL and QR iteration
  288. *
  289. IF( ABS( D( LEND ) ).LT.ABS( D( L ) ) ) THEN
  290. LEND = LSV
  291. L = LENDSV
  292. END IF
  293. *
  294. IF( LEND.GT.L ) THEN
  295. *
  296. * QL Iteration
  297. *
  298. * Look for small subdiagonal element.
  299. *
  300. 40 CONTINUE
  301. IF( L.NE.LEND ) THEN
  302. LENDM1 = LEND - 1
  303. DO 50 M = L, LENDM1
  304. TST = ABS( E( M ) )**2
  305. IF( TST.LE.( EPS2*ABS( D( M ) ) )*ABS( D( M+1 ) )+
  306. $ SAFMIN )GO TO 60
  307. 50 CONTINUE
  308. END IF
  309. *
  310. M = LEND
  311. *
  312. 60 CONTINUE
  313. IF( M.LT.LEND )
  314. $ E( M ) = ZERO
  315. P = D( L )
  316. IF( M.EQ.L )
  317. $ GO TO 80
  318. *
  319. * If remaining matrix is 2-by-2, use DLAE2 or SLAEV2
  320. * to compute its eigensystem.
  321. *
  322. IF( M.EQ.L+1 ) THEN
  323. IF( ICOMPZ.GT.0 ) THEN
  324. CALL DLAEV2( D( L ), E( L ), D( L+1 ), RT1, RT2, C, S )
  325. WORK( L ) = C
  326. WORK( N-1+L ) = S
  327. CALL DLASR( 'R', 'V', 'B', N, 2, WORK( L ),
  328. $ WORK( N-1+L ), Z( 1, L ), LDZ )
  329. ELSE
  330. CALL DLAE2( D( L ), E( L ), D( L+1 ), RT1, RT2 )
  331. END IF
  332. D( L ) = RT1
  333. D( L+1 ) = RT2
  334. E( L ) = ZERO
  335. L = L + 2
  336. IF( L.LE.LEND )
  337. $ GO TO 40
  338. GO TO 140
  339. END IF
  340. *
  341. IF( JTOT.EQ.NMAXIT )
  342. $ GO TO 140
  343. JTOT = JTOT + 1
  344. *
  345. * Form shift.
  346. *
  347. G = ( D( L+1 )-P ) / ( TWO*E( L ) )
  348. R = DLAPY2( G, ONE )
  349. G = D( M ) - P + ( E( L ) / ( G+SIGN( R, G ) ) )
  350. *
  351. S = ONE
  352. C = ONE
  353. P = ZERO
  354. *
  355. * Inner loop
  356. *
  357. MM1 = M - 1
  358. DO 70 I = MM1, L, -1
  359. F = S*E( I )
  360. B = C*E( I )
  361. CALL DLARTG( G, F, C, S, R )
  362. IF( I.NE.M-1 )
  363. $ E( I+1 ) = R
  364. G = D( I+1 ) - P
  365. R = ( D( I )-G )*S + TWO*C*B
  366. P = S*R
  367. D( I+1 ) = G + P
  368. G = C*R - B
  369. *
  370. * If eigenvectors are desired, then save rotations.
  371. *
  372. IF( ICOMPZ.GT.0 ) THEN
  373. WORK( I ) = C
  374. WORK( N-1+I ) = -S
  375. END IF
  376. *
  377. 70 CONTINUE
  378. *
  379. * If eigenvectors are desired, then apply saved rotations.
  380. *
  381. IF( ICOMPZ.GT.0 ) THEN
  382. MM = M - L + 1
  383. CALL DLASR( 'R', 'V', 'B', N, MM, WORK( L ), WORK( N-1+L ),
  384. $ Z( 1, L ), LDZ )
  385. END IF
  386. *
  387. D( L ) = D( L ) - P
  388. E( L ) = G
  389. GO TO 40
  390. *
  391. * Eigenvalue found.
  392. *
  393. 80 CONTINUE
  394. D( L ) = P
  395. *
  396. L = L + 1
  397. IF( L.LE.LEND )
  398. $ GO TO 40
  399. GO TO 140
  400. *
  401. ELSE
  402. *
  403. * QR Iteration
  404. *
  405. * Look for small superdiagonal element.
  406. *
  407. 90 CONTINUE
  408. IF( L.NE.LEND ) THEN
  409. LENDP1 = LEND + 1
  410. DO 100 M = L, LENDP1, -1
  411. TST = ABS( E( M-1 ) )**2
  412. IF( TST.LE.( EPS2*ABS( D( M ) ) )*ABS( D( M-1 ) )+
  413. $ SAFMIN )GO TO 110
  414. 100 CONTINUE
  415. END IF
  416. *
  417. M = LEND
  418. *
  419. 110 CONTINUE
  420. IF( M.GT.LEND )
  421. $ E( M-1 ) = ZERO
  422. P = D( L )
  423. IF( M.EQ.L )
  424. $ GO TO 130
  425. *
  426. * If remaining matrix is 2-by-2, use DLAE2 or SLAEV2
  427. * to compute its eigensystem.
  428. *
  429. IF( M.EQ.L-1 ) THEN
  430. IF( ICOMPZ.GT.0 ) THEN
  431. CALL DLAEV2( D( L-1 ), E( L-1 ), D( L ), RT1, RT2, C, S )
  432. WORK( M ) = C
  433. WORK( N-1+M ) = S
  434. CALL DLASR( 'R', 'V', 'F', N, 2, WORK( M ),
  435. $ WORK( N-1+M ), Z( 1, L-1 ), LDZ )
  436. ELSE
  437. CALL DLAE2( D( L-1 ), E( L-1 ), D( L ), RT1, RT2 )
  438. END IF
  439. D( L-1 ) = RT1
  440. D( L ) = RT2
  441. E( L-1 ) = ZERO
  442. L = L - 2
  443. IF( L.GE.LEND )
  444. $ GO TO 90
  445. GO TO 140
  446. END IF
  447. *
  448. IF( JTOT.EQ.NMAXIT )
  449. $ GO TO 140
  450. JTOT = JTOT + 1
  451. *
  452. * Form shift.
  453. *
  454. G = ( D( L-1 )-P ) / ( TWO*E( L-1 ) )
  455. R = DLAPY2( G, ONE )
  456. G = D( M ) - P + ( E( L-1 ) / ( G+SIGN( R, G ) ) )
  457. *
  458. S = ONE
  459. C = ONE
  460. P = ZERO
  461. *
  462. * Inner loop
  463. *
  464. LM1 = L - 1
  465. DO 120 I = M, LM1
  466. F = S*E( I )
  467. B = C*E( I )
  468. CALL DLARTG( G, F, C, S, R )
  469. IF( I.NE.M )
  470. $ E( I-1 ) = R
  471. G = D( I ) - P
  472. R = ( D( I+1 )-G )*S + TWO*C*B
  473. P = S*R
  474. D( I ) = G + P
  475. G = C*R - B
  476. *
  477. * If eigenvectors are desired, then save rotations.
  478. *
  479. IF( ICOMPZ.GT.0 ) THEN
  480. WORK( I ) = C
  481. WORK( N-1+I ) = S
  482. END IF
  483. *
  484. 120 CONTINUE
  485. *
  486. * If eigenvectors are desired, then apply saved rotations.
  487. *
  488. IF( ICOMPZ.GT.0 ) THEN
  489. MM = L - M + 1
  490. CALL DLASR( 'R', 'V', 'F', N, MM, WORK( M ), WORK( N-1+M ),
  491. $ Z( 1, M ), LDZ )
  492. END IF
  493. *
  494. D( L ) = D( L ) - P
  495. E( LM1 ) = G
  496. GO TO 90
  497. *
  498. * Eigenvalue found.
  499. *
  500. 130 CONTINUE
  501. D( L ) = P
  502. *
  503. L = L - 1
  504. IF( L.GE.LEND )
  505. $ GO TO 90
  506. GO TO 140
  507. *
  508. END IF
  509. *
  510. * Undo scaling if necessary
  511. *
  512. 140 CONTINUE
  513. IF( ISCALE.EQ.1 ) THEN
  514. CALL DLASCL( 'G', 0, 0, SSFMAX, ANORM, LENDSV-LSV+1, 1,
  515. $ D( LSV ), N, INFO )
  516. CALL DLASCL( 'G', 0, 0, SSFMAX, ANORM, LENDSV-LSV, 1, E( LSV ),
  517. $ N, INFO )
  518. ELSE IF( ISCALE.EQ.2 ) THEN
  519. CALL DLASCL( 'G', 0, 0, SSFMIN, ANORM, LENDSV-LSV+1, 1,
  520. $ D( LSV ), N, INFO )
  521. CALL DLASCL( 'G', 0, 0, SSFMIN, ANORM, LENDSV-LSV, 1, E( LSV ),
  522. $ N, INFO )
  523. END IF
  524. *
  525. * Check for no convergence to an eigenvalue after a total
  526. * of N*MAXIT iterations.
  527. *
  528. IF( JTOT.LT.NMAXIT )
  529. $ GO TO 10
  530. DO 150 I = 1, N - 1
  531. IF( E( I ).NE.ZERO )
  532. $ INFO = INFO + 1
  533. 150 CONTINUE
  534. GO TO 190
  535. *
  536. * Order eigenvalues and eigenvectors.
  537. *
  538. 160 CONTINUE
  539. IF( ICOMPZ.EQ.0 ) THEN
  540. *
  541. * Use Quick Sort
  542. *
  543. CALL DLASRT( 'I', N, D, INFO )
  544. *
  545. ELSE
  546. *
  547. * Use Selection Sort to minimize swaps of eigenvectors
  548. *
  549. DO 180 II = 2, N
  550. I = II - 1
  551. K = I
  552. P = D( I )
  553. DO 170 J = II, N
  554. IF( D( J ).LT.P ) THEN
  555. K = J
  556. P = D( J )
  557. END IF
  558. 170 CONTINUE
  559. IF( K.NE.I ) THEN
  560. D( K ) = D( I )
  561. D( I ) = P
  562. CALL DSWAP( N, Z( 1, I ), 1, Z( 1, K ), 1 )
  563. END IF
  564. 180 CONTINUE
  565. END IF
  566. *
  567. 190 CONTINUE
  568. RETURN
  569. *
  570. * End of DSTEQR
  571. *
  572. END
  573.  
  574.  
  575.  
  576.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales