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.

dlaed4.f 27 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. *> \brief \b DLAED4 used by DSTEDC. Finds a single root of the secular equation.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download DLAED4 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaed4.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaed4.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaed4.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DLAED4( N, I, D, Z, DELTA, RHO, DLAM, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * INTEGER I, INFO, N
  25. * DOUBLE PRECISION DLAM, RHO
  26. * ..
  27. * .. Array Arguments ..
  28. * DOUBLE PRECISION D( * ), DELTA( * ), Z( * )
  29. * ..
  30. *
  31. *
  32. *> \par Purpose:
  33. * =============
  34. *>
  35. *> \verbatim
  36. *>
  37. *> This subroutine computes the I-th updated eigenvalue of a symmetric
  38. *> rank-one modification to a diagonal matrix whose elements are
  39. *> given in the array d, and that
  40. *>
  41. *> D(i) < D(j) for i < j
  42. *>
  43. *> and that RHO > 0. This is arranged by the calling routine, and is
  44. *> no loss in generality. The rank-one modified system is thus
  45. *>
  46. *> diag( D ) + RHO * Z * Z_transpose.
  47. *>
  48. *> where we assume the Euclidean norm of Z is 1.
  49. *>
  50. *> The method consists of approximating the rational functions in the
  51. *> secular equation by simpler interpolating rational functions.
  52. *> \endverbatim
  53. *
  54. * Arguments:
  55. * ==========
  56. *
  57. *> \param[in] N
  58. *> \verbatim
  59. *> N is INTEGER
  60. *> The length of all arrays.
  61. *> \endverbatim
  62. *>
  63. *> \param[in] I
  64. *> \verbatim
  65. *> I is INTEGER
  66. *> The index of the eigenvalue to be computed. 1 <= I <= N.
  67. *> \endverbatim
  68. *>
  69. *> \param[in] D
  70. *> \verbatim
  71. *> D is DOUBLE PRECISION array, dimension (N)
  72. *> The original eigenvalues. It is assumed that they are in
  73. *> order, D(I) < D(J) for I < J.
  74. *> \endverbatim
  75. *>
  76. *> \param[in] Z
  77. *> \verbatim
  78. *> Z is DOUBLE PRECISION array, dimension (N)
  79. *> The components of the updating vector.
  80. *> \endverbatim
  81. *>
  82. *> \param[out] DELTA
  83. *> \verbatim
  84. *> DELTA is DOUBLE PRECISION array, dimension (N)
  85. *> If N > 2, DELTA contains (D(j) - lambda_I) in its j-th
  86. *> component. If N = 1, then DELTA(1) = 1. If N = 2, see DLAED5
  87. *> for detail. The vector DELTA contains the information necessary
  88. *> to construct the eigenvectors by DLAED3 and DLAED9.
  89. *> \endverbatim
  90. *>
  91. *> \param[in] RHO
  92. *> \verbatim
  93. *> RHO is DOUBLE PRECISION
  94. *> The scalar in the symmetric updating formula.
  95. *> \endverbatim
  96. *>
  97. *> \param[out] DLAM
  98. *> \verbatim
  99. *> DLAM is DOUBLE PRECISION
  100. *> The computed lambda_I, the I-th updated eigenvalue.
  101. *> \endverbatim
  102. *>
  103. *> \param[out] INFO
  104. *> \verbatim
  105. *> INFO is INTEGER
  106. *> = 0: successful exit
  107. *> > 0: if INFO = 1, the updating process failed.
  108. *> \endverbatim
  109. *
  110. *> \par Internal Parameters:
  111. * =========================
  112. *>
  113. *> \verbatim
  114. *> Logical variable ORGATI (origin-at-i?) is used for distinguishing
  115. *> whether D(i) or D(i+1) is treated as the origin.
  116. *>
  117. *> ORGATI = .true. origin at i
  118. *> ORGATI = .false. origin at i+1
  119. *>
  120. *> Logical variable SWTCH3 (switch-for-3-poles?) is for noting
  121. *> if we are working with THREE poles!
  122. *>
  123. *> MAXIT is the maximum number of iterations allowed for each
  124. *> eigenvalue.
  125. *> \endverbatim
  126. *
  127. * Authors:
  128. * ========
  129. *
  130. *> \author Univ. of Tennessee
  131. *> \author Univ. of California Berkeley
  132. *> \author Univ. of Colorado Denver
  133. *> \author NAG Ltd.
  134. *
  135. *> \ingroup auxOTHERcomputational
  136. *
  137. *> \par Contributors:
  138. * ==================
  139. *>
  140. *> Ren-Cang Li, Computer Science Division, University of California
  141. *> at Berkeley, USA
  142. *>
  143. * =====================================================================
  144. SUBROUTINE DLAED4( N, I, D, Z, DELTA, RHO, DLAM, INFO )
  145. *
  146. * -- LAPACK computational routine --
  147. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  148. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  149. *
  150. * .. Scalar Arguments ..
  151. INTEGER I, INFO, N
  152. DOUBLE PRECISION DLAM, RHO
  153. * ..
  154. * .. Array Arguments ..
  155. DOUBLE PRECISION D( * ), DELTA( * ), Z( * )
  156. * ..
  157. *
  158. * =====================================================================
  159. *
  160. * .. Parameters ..
  161. INTEGER MAXIT
  162. PARAMETER ( MAXIT = 30 )
  163. DOUBLE PRECISION ZERO, ONE, TWO, THREE, FOUR, EIGHT, TEN
  164. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,
  165. $ THREE = 3.0D0, FOUR = 4.0D0, EIGHT = 8.0D0,
  166. $ TEN = 10.0D0 )
  167. * ..
  168. * .. Local Scalars ..
  169. LOGICAL ORGATI, SWTCH, SWTCH3
  170. INTEGER II, IIM1, IIP1, IP1, ITER, J, NITER
  171. DOUBLE PRECISION A, B, C, DEL, DLTLB, DLTUB, DPHI, DPSI, DW,
  172. $ EPS, ERRETM, ETA, MIDPT, PHI, PREW, PSI,
  173. $ RHOINV, TAU, TEMP, TEMP1, W
  174. * ..
  175. * .. Local Arrays ..
  176. DOUBLE PRECISION ZZ( 3 )
  177. * ..
  178. * .. External Functions ..
  179. DOUBLE PRECISION DLAMCH
  180. EXTERNAL DLAMCH
  181. * ..
  182. * .. External Subroutines ..
  183. EXTERNAL DLAED5, DLAED6
  184. * ..
  185. * .. Intrinsic Functions ..
  186. INTRINSIC ABS, MAX, MIN, SQRT
  187. * ..
  188. * .. Executable Statements ..
  189. *
  190. * Since this routine is called in an inner loop, we do no argument
  191. * checking.
  192. *
  193. * Quick return for N=1 and 2.
  194. *
  195. INFO = 0
  196. IF( N.EQ.1 ) THEN
  197. *
  198. * Presumably, I=1 upon entry
  199. *
  200. DLAM = D( 1 ) + RHO*Z( 1 )*Z( 1 )
  201. DELTA( 1 ) = ONE
  202. RETURN
  203. END IF
  204. IF( N.EQ.2 ) THEN
  205. CALL DLAED5( I, D, Z, DELTA, RHO, DLAM )
  206. RETURN
  207. END IF
  208. *
  209. * Compute machine epsilon
  210. *
  211. EPS = DLAMCH( 'Epsilon' )
  212. RHOINV = ONE / RHO
  213. *
  214. * The case I = N
  215. *
  216. IF( I.EQ.N ) THEN
  217. *
  218. * Initialize some basic variables
  219. *
  220. II = N - 1
  221. NITER = 1
  222. *
  223. * Calculate initial guess
  224. *
  225. MIDPT = RHO / TWO
  226. *
  227. * If ||Z||_2 is not one, then TEMP should be set to
  228. * RHO * ||Z||_2^2 / TWO
  229. *
  230. DO 10 J = 1, N
  231. DELTA( J ) = ( D( J )-D( I ) ) - MIDPT
  232. 10 CONTINUE
  233. *
  234. PSI = ZERO
  235. DO 20 J = 1, N - 2
  236. PSI = PSI + Z( J )*Z( J ) / DELTA( J )
  237. 20 CONTINUE
  238. *
  239. C = RHOINV + PSI
  240. W = C + Z( II )*Z( II ) / DELTA( II ) +
  241. $ Z( N )*Z( N ) / DELTA( N )
  242. *
  243. IF( W.LE.ZERO ) THEN
  244. TEMP = Z( N-1 )*Z( N-1 ) / ( D( N )-D( N-1 )+RHO ) +
  245. $ Z( N )*Z( N ) / RHO
  246. IF( C.LE.TEMP ) THEN
  247. TAU = RHO
  248. ELSE
  249. DEL = D( N ) - D( N-1 )
  250. A = -C*DEL + Z( N-1 )*Z( N-1 ) + Z( N )*Z( N )
  251. B = Z( N )*Z( N )*DEL
  252. IF( A.LT.ZERO ) THEN
  253. TAU = TWO*B / ( SQRT( A*A+FOUR*B*C )-A )
  254. ELSE
  255. TAU = ( A+SQRT( A*A+FOUR*B*C ) ) / ( TWO*C )
  256. END IF
  257. END IF
  258. *
  259. * It can be proved that
  260. * D(N)+RHO/2 <= LAMBDA(N) < D(N)+TAU <= D(N)+RHO
  261. *
  262. DLTLB = MIDPT
  263. DLTUB = RHO
  264. ELSE
  265. DEL = D( N ) - D( N-1 )
  266. A = -C*DEL + Z( N-1 )*Z( N-1 ) + Z( N )*Z( N )
  267. B = Z( N )*Z( N )*DEL
  268. IF( A.LT.ZERO ) THEN
  269. TAU = TWO*B / ( SQRT( A*A+FOUR*B*C )-A )
  270. ELSE
  271. TAU = ( A+SQRT( A*A+FOUR*B*C ) ) / ( TWO*C )
  272. END IF
  273. *
  274. * It can be proved that
  275. * D(N) < D(N)+TAU < LAMBDA(N) < D(N)+RHO/2
  276. *
  277. DLTLB = ZERO
  278. DLTUB = MIDPT
  279. END IF
  280. *
  281. DO 30 J = 1, N
  282. DELTA( J ) = ( D( J )-D( I ) ) - TAU
  283. 30 CONTINUE
  284. *
  285. * Evaluate PSI and the derivative DPSI
  286. *
  287. DPSI = ZERO
  288. PSI = ZERO
  289. ERRETM = ZERO
  290. DO 40 J = 1, II
  291. TEMP = Z( J ) / DELTA( J )
  292. PSI = PSI + Z( J )*TEMP
  293. DPSI = DPSI + TEMP*TEMP
  294. ERRETM = ERRETM + PSI
  295. 40 CONTINUE
  296. ERRETM = ABS( ERRETM )
  297. *
  298. * Evaluate PHI and the derivative DPHI
  299. *
  300. TEMP = Z( N ) / DELTA( N )
  301. PHI = Z( N )*TEMP
  302. DPHI = TEMP*TEMP
  303. ERRETM = EIGHT*( -PHI-PSI ) + ERRETM - PHI + RHOINV +
  304. $ ABS( TAU )*( DPSI+DPHI )
  305. *
  306. W = RHOINV + PHI + PSI
  307. *
  308. * Test for convergence
  309. *
  310. IF( ABS( W ).LE.EPS*ERRETM ) THEN
  311. DLAM = D( I ) + TAU
  312. GO TO 250
  313. END IF
  314. *
  315. IF( W.LE.ZERO ) THEN
  316. DLTLB = MAX( DLTLB, TAU )
  317. ELSE
  318. DLTUB = MIN( DLTUB, TAU )
  319. END IF
  320. *
  321. * Calculate the new step
  322. *
  323. NITER = NITER + 1
  324. C = W - DELTA( N-1 )*DPSI - DELTA( N )*DPHI
  325. A = ( DELTA( N-1 )+DELTA( N ) )*W -
  326. $ DELTA( N-1 )*DELTA( N )*( DPSI+DPHI )
  327. B = DELTA( N-1 )*DELTA( N )*W
  328. IF( C.LT.ZERO )
  329. $ C = ABS( C )
  330. IF( C.EQ.ZERO ) THEN
  331. * ETA = B/A
  332. * ETA = RHO - TAU
  333. ETA = DLTUB - TAU
  334. ELSE IF( A.GE.ZERO ) THEN
  335. ETA = ( A+SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
  336. ELSE
  337. ETA = TWO*B / ( A-SQRT( ABS( A*A-FOUR*B*C ) ) )
  338. END IF
  339. *
  340. * Note, eta should be positive if w is negative, and
  341. * eta should be negative otherwise. However,
  342. * if for some reason caused by roundoff, eta*w > 0,
  343. * we simply use one Newton step instead. This way
  344. * will guarantee eta*w < 0.
  345. *
  346. IF( W*ETA.GT.ZERO )
  347. $ ETA = -W / ( DPSI+DPHI )
  348. TEMP = TAU + ETA
  349. IF( TEMP.GT.DLTUB .OR. TEMP.LT.DLTLB ) THEN
  350. IF( W.LT.ZERO ) THEN
  351. ETA = ( DLTUB-TAU ) / TWO
  352. ELSE
  353. ETA = ( DLTLB-TAU ) / TWO
  354. END IF
  355. END IF
  356. DO 50 J = 1, N
  357. DELTA( J ) = DELTA( J ) - ETA
  358. 50 CONTINUE
  359. *
  360. TAU = TAU + ETA
  361. *
  362. * Evaluate PSI and the derivative DPSI
  363. *
  364. DPSI = ZERO
  365. PSI = ZERO
  366. ERRETM = ZERO
  367. DO 60 J = 1, II
  368. TEMP = Z( J ) / DELTA( J )
  369. PSI = PSI + Z( J )*TEMP
  370. DPSI = DPSI + TEMP*TEMP
  371. ERRETM = ERRETM + PSI
  372. 60 CONTINUE
  373. ERRETM = ABS( ERRETM )
  374. *
  375. * Evaluate PHI and the derivative DPHI
  376. *
  377. TEMP = Z( N ) / DELTA( N )
  378. PHI = Z( N )*TEMP
  379. DPHI = TEMP*TEMP
  380. ERRETM = EIGHT*( -PHI-PSI ) + ERRETM - PHI + RHOINV +
  381. $ ABS( TAU )*( DPSI+DPHI )
  382. *
  383. W = RHOINV + PHI + PSI
  384. *
  385. * Main loop to update the values of the array DELTA
  386. *
  387. ITER = NITER + 1
  388. *
  389. DO 90 NITER = ITER, MAXIT
  390. *
  391. * Test for convergence
  392. *
  393. IF( ABS( W ).LE.EPS*ERRETM ) THEN
  394. DLAM = D( I ) + TAU
  395. GO TO 250
  396. END IF
  397. *
  398. IF( W.LE.ZERO ) THEN
  399. DLTLB = MAX( DLTLB, TAU )
  400. ELSE
  401. DLTUB = MIN( DLTUB, TAU )
  402. END IF
  403. *
  404. * Calculate the new step
  405. *
  406. C = W - DELTA( N-1 )*DPSI - DELTA( N )*DPHI
  407. A = ( DELTA( N-1 )+DELTA( N ) )*W -
  408. $ DELTA( N-1 )*DELTA( N )*( DPSI+DPHI )
  409. B = DELTA( N-1 )*DELTA( N )*W
  410. IF( A.GE.ZERO ) THEN
  411. ETA = ( A+SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
  412. ELSE
  413. ETA = TWO*B / ( A-SQRT( ABS( A*A-FOUR*B*C ) ) )
  414. END IF
  415. *
  416. * Note, eta should be positive if w is negative, and
  417. * eta should be negative otherwise. However,
  418. * if for some reason caused by roundoff, eta*w > 0,
  419. * we simply use one Newton step instead. This way
  420. * will guarantee eta*w < 0.
  421. *
  422. IF( W*ETA.GT.ZERO )
  423. $ ETA = -W / ( DPSI+DPHI )
  424. TEMP = TAU + ETA
  425. IF( TEMP.GT.DLTUB .OR. TEMP.LT.DLTLB ) THEN
  426. IF( W.LT.ZERO ) THEN
  427. ETA = ( DLTUB-TAU ) / TWO
  428. ELSE
  429. ETA = ( DLTLB-TAU ) / TWO
  430. END IF
  431. END IF
  432. DO 70 J = 1, N
  433. DELTA( J ) = DELTA( J ) - ETA
  434. 70 CONTINUE
  435. *
  436. TAU = TAU + ETA
  437. *
  438. * Evaluate PSI and the derivative DPSI
  439. *
  440. DPSI = ZERO
  441. PSI = ZERO
  442. ERRETM = ZERO
  443. DO 80 J = 1, II
  444. TEMP = Z( J ) / DELTA( J )
  445. PSI = PSI + Z( J )*TEMP
  446. DPSI = DPSI + TEMP*TEMP
  447. ERRETM = ERRETM + PSI
  448. 80 CONTINUE
  449. ERRETM = ABS( ERRETM )
  450. *
  451. * Evaluate PHI and the derivative DPHI
  452. *
  453. TEMP = Z( N ) / DELTA( N )
  454. PHI = Z( N )*TEMP
  455. DPHI = TEMP*TEMP
  456. ERRETM = EIGHT*( -PHI-PSI ) + ERRETM - PHI + RHOINV +
  457. $ ABS( TAU )*( DPSI+DPHI )
  458. *
  459. W = RHOINV + PHI + PSI
  460. 90 CONTINUE
  461. *
  462. * Return with INFO = 1, NITER = MAXIT and not converged
  463. *
  464. INFO = 1
  465. DLAM = D( I ) + TAU
  466. GO TO 250
  467. *
  468. * End for the case I = N
  469. *
  470. ELSE
  471. *
  472. * The case for I < N
  473. *
  474. NITER = 1
  475. IP1 = I + 1
  476. *
  477. * Calculate initial guess
  478. *
  479. DEL = D( IP1 ) - D( I )
  480. MIDPT = DEL / TWO
  481. DO 100 J = 1, N
  482. DELTA( J ) = ( D( J )-D( I ) ) - MIDPT
  483. 100 CONTINUE
  484. *
  485. PSI = ZERO
  486. DO 110 J = 1, I - 1
  487. PSI = PSI + Z( J )*Z( J ) / DELTA( J )
  488. 110 CONTINUE
  489. *
  490. PHI = ZERO
  491. DO 120 J = N, I + 2, -1
  492. PHI = PHI + Z( J )*Z( J ) / DELTA( J )
  493. 120 CONTINUE
  494. C = RHOINV + PSI + PHI
  495. W = C + Z( I )*Z( I ) / DELTA( I ) +
  496. $ Z( IP1 )*Z( IP1 ) / DELTA( IP1 )
  497. *
  498. IF( W.GT.ZERO ) THEN
  499. *
  500. * d(i)< the ith eigenvalue < (d(i)+d(i+1))/2
  501. *
  502. * We choose d(i) as origin.
  503. *
  504. ORGATI = .TRUE.
  505. A = C*DEL + Z( I )*Z( I ) + Z( IP1 )*Z( IP1 )
  506. B = Z( I )*Z( I )*DEL
  507. IF( A.GT.ZERO ) THEN
  508. TAU = TWO*B / ( A+SQRT( ABS( A*A-FOUR*B*C ) ) )
  509. ELSE
  510. TAU = ( A-SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
  511. END IF
  512. DLTLB = ZERO
  513. DLTUB = MIDPT
  514. ELSE
  515. *
  516. * (d(i)+d(i+1))/2 <= the ith eigenvalue < d(i+1)
  517. *
  518. * We choose d(i+1) as origin.
  519. *
  520. ORGATI = .FALSE.
  521. A = C*DEL - Z( I )*Z( I ) - Z( IP1 )*Z( IP1 )
  522. B = Z( IP1 )*Z( IP1 )*DEL
  523. IF( A.LT.ZERO ) THEN
  524. TAU = TWO*B / ( A-SQRT( ABS( A*A+FOUR*B*C ) ) )
  525. ELSE
  526. TAU = -( A+SQRT( ABS( A*A+FOUR*B*C ) ) ) / ( TWO*C )
  527. END IF
  528. DLTLB = -MIDPT
  529. DLTUB = ZERO
  530. END IF
  531. *
  532. IF( ORGATI ) THEN
  533. DO 130 J = 1, N
  534. DELTA( J ) = ( D( J )-D( I ) ) - TAU
  535. 130 CONTINUE
  536. ELSE
  537. DO 140 J = 1, N
  538. DELTA( J ) = ( D( J )-D( IP1 ) ) - TAU
  539. 140 CONTINUE
  540. END IF
  541. IF( ORGATI ) THEN
  542. II = I
  543. ELSE
  544. II = I + 1
  545. END IF
  546. IIM1 = II - 1
  547. IIP1 = II + 1
  548. *
  549. * Evaluate PSI and the derivative DPSI
  550. *
  551. DPSI = ZERO
  552. PSI = ZERO
  553. ERRETM = ZERO
  554. DO 150 J = 1, IIM1
  555. TEMP = Z( J ) / DELTA( J )
  556. PSI = PSI + Z( J )*TEMP
  557. DPSI = DPSI + TEMP*TEMP
  558. ERRETM = ERRETM + PSI
  559. 150 CONTINUE
  560. ERRETM = ABS( ERRETM )
  561. *
  562. * Evaluate PHI and the derivative DPHI
  563. *
  564. DPHI = ZERO
  565. PHI = ZERO
  566. DO 160 J = N, IIP1, -1
  567. TEMP = Z( J ) / DELTA( J )
  568. PHI = PHI + Z( J )*TEMP
  569. DPHI = DPHI + TEMP*TEMP
  570. ERRETM = ERRETM + PHI
  571. 160 CONTINUE
  572. *
  573. W = RHOINV + PHI + PSI
  574. *
  575. * W is the value of the secular function with
  576. * its ii-th element removed.
  577. *
  578. SWTCH3 = .FALSE.
  579. IF( ORGATI ) THEN
  580. IF( W.LT.ZERO )
  581. $ SWTCH3 = .TRUE.
  582. ELSE
  583. IF( W.GT.ZERO )
  584. $ SWTCH3 = .TRUE.
  585. END IF
  586. IF( II.EQ.1 .OR. II.EQ.N )
  587. $ SWTCH3 = .FALSE.
  588. *
  589. TEMP = Z( II ) / DELTA( II )
  590. DW = DPSI + DPHI + TEMP*TEMP
  591. TEMP = Z( II )*TEMP
  592. W = W + TEMP
  593. ERRETM = EIGHT*( PHI-PSI ) + ERRETM + TWO*RHOINV +
  594. $ THREE*ABS( TEMP ) + ABS( TAU )*DW
  595. *
  596. * Test for convergence
  597. *
  598. IF( ABS( W ).LE.EPS*ERRETM ) THEN
  599. IF( ORGATI ) THEN
  600. DLAM = D( I ) + TAU
  601. ELSE
  602. DLAM = D( IP1 ) + TAU
  603. END IF
  604. GO TO 250
  605. END IF
  606. *
  607. IF( W.LE.ZERO ) THEN
  608. DLTLB = MAX( DLTLB, TAU )
  609. ELSE
  610. DLTUB = MIN( DLTUB, TAU )
  611. END IF
  612. *
  613. * Calculate the new step
  614. *
  615. NITER = NITER + 1
  616. IF( .NOT.SWTCH3 ) THEN
  617. IF( ORGATI ) THEN
  618. C = W - DELTA( IP1 )*DW - ( D( I )-D( IP1 ) )*
  619. $ ( Z( I ) / DELTA( I ) )**2
  620. ELSE
  621. C = W - DELTA( I )*DW - ( D( IP1 )-D( I ) )*
  622. $ ( Z( IP1 ) / DELTA( IP1 ) )**2
  623. END IF
  624. A = ( DELTA( I )+DELTA( IP1 ) )*W -
  625. $ DELTA( I )*DELTA( IP1 )*DW
  626. B = DELTA( I )*DELTA( IP1 )*W
  627. IF( C.EQ.ZERO ) THEN
  628. IF( A.EQ.ZERO ) THEN
  629. IF( ORGATI ) THEN
  630. A = Z( I )*Z( I ) + DELTA( IP1 )*DELTA( IP1 )*
  631. $ ( DPSI+DPHI )
  632. ELSE
  633. A = Z( IP1 )*Z( IP1 ) + DELTA( I )*DELTA( I )*
  634. $ ( DPSI+DPHI )
  635. END IF
  636. END IF
  637. ETA = B / A
  638. ELSE IF( A.LE.ZERO ) THEN
  639. ETA = ( A-SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
  640. ELSE
  641. ETA = TWO*B / ( A+SQRT( ABS( A*A-FOUR*B*C ) ) )
  642. END IF
  643. ELSE
  644. *
  645. * Interpolation using THREE most relevant poles
  646. *
  647. TEMP = RHOINV + PSI + PHI
  648. IF( ORGATI ) THEN
  649. TEMP1 = Z( IIM1 ) / DELTA( IIM1 )
  650. TEMP1 = TEMP1*TEMP1
  651. C = TEMP - DELTA( IIP1 )*( DPSI+DPHI ) -
  652. $ ( D( IIM1 )-D( IIP1 ) )*TEMP1
  653. ZZ( 1 ) = Z( IIM1 )*Z( IIM1 )
  654. ZZ( 3 ) = DELTA( IIP1 )*DELTA( IIP1 )*
  655. $ ( ( DPSI-TEMP1 )+DPHI )
  656. ELSE
  657. TEMP1 = Z( IIP1 ) / DELTA( IIP1 )
  658. TEMP1 = TEMP1*TEMP1
  659. C = TEMP - DELTA( IIM1 )*( DPSI+DPHI ) -
  660. $ ( D( IIP1 )-D( IIM1 ) )*TEMP1
  661. ZZ( 1 ) = DELTA( IIM1 )*DELTA( IIM1 )*
  662. $ ( DPSI+( DPHI-TEMP1 ) )
  663. ZZ( 3 ) = Z( IIP1 )*Z( IIP1 )
  664. END IF
  665. ZZ( 2 ) = Z( II )*Z( II )
  666. CALL DLAED6( NITER, ORGATI, C, DELTA( IIM1 ), ZZ, W, ETA,
  667. $ INFO )
  668. IF( INFO.NE.0 )
  669. $ GO TO 250
  670. END IF
  671. *
  672. * Note, eta should be positive if w is negative, and
  673. * eta should be negative otherwise. However,
  674. * if for some reason caused by roundoff, eta*w > 0,
  675. * we simply use one Newton step instead. This way
  676. * will guarantee eta*w < 0.
  677. *
  678. IF( W*ETA.GE.ZERO )
  679. $ ETA = -W / DW
  680. TEMP = TAU + ETA
  681. IF( TEMP.GT.DLTUB .OR. TEMP.LT.DLTLB ) THEN
  682. IF( W.LT.ZERO ) THEN
  683. ETA = ( DLTUB-TAU ) / TWO
  684. ELSE
  685. ETA = ( DLTLB-TAU ) / TWO
  686. END IF
  687. END IF
  688. *
  689. PREW = W
  690. *
  691. DO 180 J = 1, N
  692. DELTA( J ) = DELTA( J ) - ETA
  693. 180 CONTINUE
  694. *
  695. * Evaluate PSI and the derivative DPSI
  696. *
  697. DPSI = ZERO
  698. PSI = ZERO
  699. ERRETM = ZERO
  700. DO 190 J = 1, IIM1
  701. TEMP = Z( J ) / DELTA( J )
  702. PSI = PSI + Z( J )*TEMP
  703. DPSI = DPSI + TEMP*TEMP
  704. ERRETM = ERRETM + PSI
  705. 190 CONTINUE
  706. ERRETM = ABS( ERRETM )
  707. *
  708. * Evaluate PHI and the derivative DPHI
  709. *
  710. DPHI = ZERO
  711. PHI = ZERO
  712. DO 200 J = N, IIP1, -1
  713. TEMP = Z( J ) / DELTA( J )
  714. PHI = PHI + Z( J )*TEMP
  715. DPHI = DPHI + TEMP*TEMP
  716. ERRETM = ERRETM + PHI
  717. 200 CONTINUE
  718. *
  719. TEMP = Z( II ) / DELTA( II )
  720. DW = DPSI + DPHI + TEMP*TEMP
  721. TEMP = Z( II )*TEMP
  722. W = RHOINV + PHI + PSI + TEMP
  723. ERRETM = EIGHT*( PHI-PSI ) + ERRETM + TWO*RHOINV +
  724. $ THREE*ABS( TEMP ) + ABS( TAU+ETA )*DW
  725. *
  726. SWTCH = .FALSE.
  727. IF( ORGATI ) THEN
  728. IF( -W.GT.ABS( PREW ) / TEN )
  729. $ SWTCH = .TRUE.
  730. ELSE
  731. IF( W.GT.ABS( PREW ) / TEN )
  732. $ SWTCH = .TRUE.
  733. END IF
  734. *
  735. TAU = TAU + ETA
  736. *
  737. * Main loop to update the values of the array DELTA
  738. *
  739. ITER = NITER + 1
  740. *
  741. DO 240 NITER = ITER, MAXIT
  742. *
  743. * Test for convergence
  744. *
  745. IF( ABS( W ).LE.EPS*ERRETM ) THEN
  746. IF( ORGATI ) THEN
  747. DLAM = D( I ) + TAU
  748. ELSE
  749. DLAM = D( IP1 ) + TAU
  750. END IF
  751. GO TO 250
  752. END IF
  753. *
  754. IF( W.LE.ZERO ) THEN
  755. DLTLB = MAX( DLTLB, TAU )
  756. ELSE
  757. DLTUB = MIN( DLTUB, TAU )
  758. END IF
  759. *
  760. * Calculate the new step
  761. *
  762. IF( .NOT.SWTCH3 ) THEN
  763. IF( .NOT.SWTCH ) THEN
  764. IF( ORGATI ) THEN
  765. C = W - DELTA( IP1 )*DW -
  766. $ ( D( I )-D( IP1 ) )*( Z( I ) / DELTA( I ) )**2
  767. ELSE
  768. C = W - DELTA( I )*DW - ( D( IP1 )-D( I ) )*
  769. $ ( Z( IP1 ) / DELTA( IP1 ) )**2
  770. END IF
  771. ELSE
  772. TEMP = Z( II ) / DELTA( II )
  773. IF( ORGATI ) THEN
  774. DPSI = DPSI + TEMP*TEMP
  775. ELSE
  776. DPHI = DPHI + TEMP*TEMP
  777. END IF
  778. C = W - DELTA( I )*DPSI - DELTA( IP1 )*DPHI
  779. END IF
  780. A = ( DELTA( I )+DELTA( IP1 ) )*W -
  781. $ DELTA( I )*DELTA( IP1 )*DW
  782. B = DELTA( I )*DELTA( IP1 )*W
  783. IF( C.EQ.ZERO ) THEN
  784. IF( A.EQ.ZERO ) THEN
  785. IF( .NOT.SWTCH ) THEN
  786. IF( ORGATI ) THEN
  787. A = Z( I )*Z( I ) + DELTA( IP1 )*
  788. $ DELTA( IP1 )*( DPSI+DPHI )
  789. ELSE
  790. A = Z( IP1 )*Z( IP1 ) +
  791. $ DELTA( I )*DELTA( I )*( DPSI+DPHI )
  792. END IF
  793. ELSE
  794. A = DELTA( I )*DELTA( I )*DPSI +
  795. $ DELTA( IP1 )*DELTA( IP1 )*DPHI
  796. END IF
  797. END IF
  798. ETA = B / A
  799. ELSE IF( A.LE.ZERO ) THEN
  800. ETA = ( A-SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
  801. ELSE
  802. ETA = TWO*B / ( A+SQRT( ABS( A*A-FOUR*B*C ) ) )
  803. END IF
  804. ELSE
  805. *
  806. * Interpolation using THREE most relevant poles
  807. *
  808. TEMP = RHOINV + PSI + PHI
  809. IF( SWTCH ) THEN
  810. C = TEMP - DELTA( IIM1 )*DPSI - DELTA( IIP1 )*DPHI
  811. ZZ( 1 ) = DELTA( IIM1 )*DELTA( IIM1 )*DPSI
  812. ZZ( 3 ) = DELTA( IIP1 )*DELTA( IIP1 )*DPHI
  813. ELSE
  814. IF( ORGATI ) THEN
  815. TEMP1 = Z( IIM1 ) / DELTA( IIM1 )
  816. TEMP1 = TEMP1*TEMP1
  817. C = TEMP - DELTA( IIP1 )*( DPSI+DPHI ) -
  818. $ ( D( IIM1 )-D( IIP1 ) )*TEMP1
  819. ZZ( 1 ) = Z( IIM1 )*Z( IIM1 )
  820. ZZ( 3 ) = DELTA( IIP1 )*DELTA( IIP1 )*
  821. $ ( ( DPSI-TEMP1 )+DPHI )
  822. ELSE
  823. TEMP1 = Z( IIP1 ) / DELTA( IIP1 )
  824. TEMP1 = TEMP1*TEMP1
  825. C = TEMP - DELTA( IIM1 )*( DPSI+DPHI ) -
  826. $ ( D( IIP1 )-D( IIM1 ) )*TEMP1
  827. ZZ( 1 ) = DELTA( IIM1 )*DELTA( IIM1 )*
  828. $ ( DPSI+( DPHI-TEMP1 ) )
  829. ZZ( 3 ) = Z( IIP1 )*Z( IIP1 )
  830. END IF
  831. END IF
  832. CALL DLAED6( NITER, ORGATI, C, DELTA( IIM1 ), ZZ, W, ETA,
  833. $ INFO )
  834. IF( INFO.NE.0 )
  835. $ GO TO 250
  836. END IF
  837. *
  838. * Note, eta should be positive if w is negative, and
  839. * eta should be negative otherwise. However,
  840. * if for some reason caused by roundoff, eta*w > 0,
  841. * we simply use one Newton step instead. This way
  842. * will guarantee eta*w < 0.
  843. *
  844. IF( W*ETA.GE.ZERO )
  845. $ ETA = -W / DW
  846. TEMP = TAU + ETA
  847. IF( TEMP.GT.DLTUB .OR. TEMP.LT.DLTLB ) THEN
  848. IF( W.LT.ZERO ) THEN
  849. ETA = ( DLTUB-TAU ) / TWO
  850. ELSE
  851. ETA = ( DLTLB-TAU ) / TWO
  852. END IF
  853. END IF
  854. *
  855. DO 210 J = 1, N
  856. DELTA( J ) = DELTA( J ) - ETA
  857. 210 CONTINUE
  858. *
  859. TAU = TAU + ETA
  860. PREW = W
  861. *
  862. * Evaluate PSI and the derivative DPSI
  863. *
  864. DPSI = ZERO
  865. PSI = ZERO
  866. ERRETM = ZERO
  867. DO 220 J = 1, IIM1
  868. TEMP = Z( J ) / DELTA( J )
  869. PSI = PSI + Z( J )*TEMP
  870. DPSI = DPSI + TEMP*TEMP
  871. ERRETM = ERRETM + PSI
  872. 220 CONTINUE
  873. ERRETM = ABS( ERRETM )
  874. *
  875. * Evaluate PHI and the derivative DPHI
  876. *
  877. DPHI = ZERO
  878. PHI = ZERO
  879. DO 230 J = N, IIP1, -1
  880. TEMP = Z( J ) / DELTA( J )
  881. PHI = PHI + Z( J )*TEMP
  882. DPHI = DPHI + TEMP*TEMP
  883. ERRETM = ERRETM + PHI
  884. 230 CONTINUE
  885. *
  886. TEMP = Z( II ) / DELTA( II )
  887. DW = DPSI + DPHI + TEMP*TEMP
  888. TEMP = Z( II )*TEMP
  889. W = RHOINV + PHI + PSI + TEMP
  890. ERRETM = EIGHT*( PHI-PSI ) + ERRETM + TWO*RHOINV +
  891. $ THREE*ABS( TEMP ) + ABS( TAU )*DW
  892. IF( W*PREW.GT.ZERO .AND. ABS( W ).GT.ABS( PREW ) / TEN )
  893. $ SWTCH = .NOT.SWTCH
  894. *
  895. 240 CONTINUE
  896. *
  897. * Return with INFO = 1, NITER = MAXIT and not converged
  898. *
  899. INFO = 1
  900. IF( ORGATI ) THEN
  901. DLAM = D( I ) + TAU
  902. ELSE
  903. DLAM = D( IP1 ) + TAU
  904. END IF
  905. *
  906. END IF
  907. *
  908. 250 CONTINUE
  909. *
  910. RETURN
  911. *
  912. * End of DLAED4
  913. *
  914. END