1 *> \brief \b DLAED4 used by sstedc. Finds a single root of the secular equation.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DLAED4 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaed4.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaed4.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaed4.f">
21 * SUBROUTINE DLAED4( N, I, D, Z, DELTA, RHO, DLAM, INFO )
23 * .. Scalar Arguments ..
25 * DOUBLE PRECISION DLAM, RHO
27 * .. Array Arguments ..
28 * DOUBLE PRECISION D( * ), DELTA( * ), Z( * )
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
41 *> D(i) < D(j) for i < j
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
46 *> diag( D ) + RHO * Z * Z_transpose.
48 *> where we assume the Euclidean norm of Z is 1.
50 *> The method consists of approximating the rational functions in the
51 *> secular equation by simpler interpolating rational functions.
60 *> The length of all arrays.
66 *> The index of the eigenvalue to be computed. 1 <= I <= N.
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.
78 *> Z is DOUBLE PRECISION array, dimension (N)
79 *> The components of the updating vector.
84 *> DELTA is DOUBLE PRECISION array, dimension (N)
85 *> If N .GT. 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.
93 *> RHO is DOUBLE PRECISION
94 *> The scalar in the symmetric updating formula.
99 *> DLAM is DOUBLE PRECISION
100 *> The computed lambda_I, the I-th updated eigenvalue.
106 *> = 0: successful exit
107 *> > 0: if INFO = 1, the updating process failed.
110 *> \par Internal Parameters:
111 * =========================
114 *> Logical variable ORGATI (origin-at-i?) is used for distinguishing
115 *> whether D(i) or D(i+1) is treated as the origin.
117 *> ORGATI = .true. origin at i
118 *> ORGATI = .false. origin at i+1
120 *> Logical variable SWTCH3 (switch-for-3-poles?) is for noting
121 *> if we are working with THREE poles!
123 *> MAXIT is the maximum number of iterations allowed for each
130 *> \author Univ. of Tennessee
131 *> \author Univ. of California Berkeley
132 *> \author Univ. of Colorado Denver
135 *> \date September 2012
137 *> \ingroup auxOTHERcomputational
139 *> \par Contributors:
142 *> Ren-Cang Li, Computer Science Division, University of California
145 * =====================================================================
146 SUBROUTINE DLAED4( N, I, D, Z, DELTA, RHO, DLAM, INFO )
148 * -- LAPACK computational routine (version 3.4.2) --
149 * -- LAPACK is a software package provided by Univ. of Tennessee, --
150 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
153 * .. Scalar Arguments ..
155 DOUBLE PRECISION DLAM, RHO
157 * .. Array Arguments ..
158 DOUBLE PRECISION D( * ), DELTA( * ), Z( * )
161 * =====================================================================
165 PARAMETER ( MAXIT = 30 )
166 DOUBLE PRECISION ZERO, ONE, TWO, THREE, FOUR, EIGHT, TEN
167 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,
168 $ THREE = 3.0D0, FOUR = 4.0D0, EIGHT = 8.0D0,
171 * .. Local Scalars ..
172 LOGICAL ORGATI, SWTCH, SWTCH3
173 INTEGER II, IIM1, IIP1, IP1, ITER, J, NITER
174 DOUBLE PRECISION A, B, C, DEL, DLTLB, DLTUB, DPHI, DPSI, DW,
175 $ EPS, ERRETM, ETA, MIDPT, PHI, PREW, PSI,
176 $ RHOINV, TAU, TEMP, TEMP1, W
179 DOUBLE PRECISION ZZ( 3 )
181 * .. External Functions ..
182 DOUBLE PRECISION DLAMCH
185 * .. External Subroutines ..
186 EXTERNAL DLAED5, DLAED6
188 * .. Intrinsic Functions ..
189 INTRINSIC ABS, MAX, MIN, SQRT
191 * .. Executable Statements ..
193 * Since this routine is called in an inner loop, we do no argument
196 * Quick return for N=1 and 2.
201 * Presumably, I=1 upon entry
203 DLAM = D( 1 ) + RHO*Z( 1 )*Z( 1 )
208 CALL DLAED5( I, D, Z, DELTA, RHO, DLAM )
212 * Compute machine epsilon
214 EPS = DLAMCH( 'Epsilon' )
221 * Initialize some basic variables
226 * Calculate initial guess
230 * If ||Z||_2 is not one, then TEMP should be set to
231 * RHO * ||Z||_2^2 / TWO
234 DELTA( J ) = ( D( J )-D( I ) ) - MIDPT
239 PSI = PSI + Z( J )*Z( J ) / DELTA( J )
243 W = C + Z( II )*Z( II ) / DELTA( II ) +
244 $ Z( N )*Z( N ) / DELTA( N )
247 TEMP = Z( N-1 )*Z( N-1 ) / ( D( N )-D( N-1 )+RHO ) +
248 $ Z( N )*Z( N ) / RHO
252 DEL = D( N ) - D( N-1 )
253 A = -C*DEL + Z( N-1 )*Z( N-1 ) + Z( N )*Z( N )
254 B = Z( N )*Z( N )*DEL
256 TAU = TWO*B / ( SQRT( A*A+FOUR*B*C )-A )
258 TAU = ( A+SQRT( A*A+FOUR*B*C ) ) / ( TWO*C )
262 * It can be proved that
263 * D(N)+RHO/2 <= LAMBDA(N) < D(N)+TAU <= D(N)+RHO
268 DEL = D( N ) - D( N-1 )
269 A = -C*DEL + Z( N-1 )*Z( N-1 ) + Z( N )*Z( N )
270 B = Z( N )*Z( N )*DEL
272 TAU = TWO*B / ( SQRT( A*A+FOUR*B*C )-A )
274 TAU = ( A+SQRT( A*A+FOUR*B*C ) ) / ( TWO*C )
277 * It can be proved that
278 * D(N) < D(N)+TAU < LAMBDA(N) < D(N)+RHO/2
285 DELTA( J ) = ( D( J )-D( I ) ) - TAU
288 * Evaluate PSI and the derivative DPSI
294 TEMP = Z( J ) / DELTA( J )
295 PSI = PSI + Z( J )*TEMP
296 DPSI = DPSI + TEMP*TEMP
297 ERRETM = ERRETM + PSI
299 ERRETM = ABS( ERRETM )
301 * Evaluate PHI and the derivative DPHI
303 TEMP = Z( N ) / DELTA( N )
306 ERRETM = EIGHT*( -PHI-PSI ) + ERRETM - PHI + RHOINV +
307 $ ABS( TAU )*( DPSI+DPHI )
309 W = RHOINV + PHI + PSI
311 * Test for convergence
313 IF( ABS( W ).LE.EPS*ERRETM ) THEN
319 DLTLB = MAX( DLTLB, TAU )
321 DLTUB = MIN( DLTUB, TAU )
324 * Calculate the new step
327 C = W - DELTA( N-1 )*DPSI - DELTA( N )*DPHI
328 A = ( DELTA( N-1 )+DELTA( N ) )*W -
329 $ DELTA( N-1 )*DELTA( N )*( DPSI+DPHI )
330 B = DELTA( N-1 )*DELTA( N )*W
337 ELSE IF( A.GE.ZERO ) THEN
338 ETA = ( A+SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
340 ETA = TWO*B / ( A-SQRT( ABS( A*A-FOUR*B*C ) ) )
343 * Note, eta should be positive if w is negative, and
344 * eta should be negative otherwise. However,
345 * if for some reason caused by roundoff, eta*w > 0,
346 * we simply use one Newton step instead. This way
347 * will guarantee eta*w < 0.
350 $ ETA = -W / ( DPSI+DPHI )
352 IF( TEMP.GT.DLTUB .OR. TEMP.LT.DLTLB ) THEN
354 ETA = ( DLTUB-TAU ) / TWO
356 ETA = ( DLTLB-TAU ) / TWO
360 DELTA( J ) = DELTA( J ) - ETA
365 * Evaluate PSI and the derivative DPSI
371 TEMP = Z( J ) / DELTA( J )
372 PSI = PSI + Z( J )*TEMP
373 DPSI = DPSI + TEMP*TEMP
374 ERRETM = ERRETM + PSI
376 ERRETM = ABS( ERRETM )
378 * Evaluate PHI and the derivative DPHI
380 TEMP = Z( N ) / DELTA( N )
383 ERRETM = EIGHT*( -PHI-PSI ) + ERRETM - PHI + RHOINV +
384 $ ABS( TAU )*( DPSI+DPHI )
386 W = RHOINV + PHI + PSI
388 * Main loop to update the values of the array DELTA
392 DO 90 NITER = ITER, MAXIT
394 * Test for convergence
396 IF( ABS( W ).LE.EPS*ERRETM ) THEN
402 DLTLB = MAX( DLTLB, TAU )
404 DLTUB = MIN( DLTUB, TAU )
407 * Calculate the new step
409 C = W - DELTA( N-1 )*DPSI - DELTA( N )*DPHI
410 A = ( DELTA( N-1 )+DELTA( N ) )*W -
411 $ DELTA( N-1 )*DELTA( N )*( DPSI+DPHI )
412 B = DELTA( N-1 )*DELTA( N )*W
414 ETA = ( A+SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
416 ETA = TWO*B / ( A-SQRT( ABS( A*A-FOUR*B*C ) ) )
419 * Note, eta should be positive if w is negative, and
420 * eta should be negative otherwise. However,
421 * if for some reason caused by roundoff, eta*w > 0,
422 * we simply use one Newton step instead. This way
423 * will guarantee eta*w < 0.
426 $ ETA = -W / ( DPSI+DPHI )
428 IF( TEMP.GT.DLTUB .OR. TEMP.LT.DLTLB ) THEN
430 ETA = ( DLTUB-TAU ) / TWO
432 ETA = ( DLTLB-TAU ) / TWO
436 DELTA( J ) = DELTA( J ) - ETA
441 * Evaluate PSI and the derivative DPSI
447 TEMP = Z( J ) / DELTA( J )
448 PSI = PSI + Z( J )*TEMP
449 DPSI = DPSI + TEMP*TEMP
450 ERRETM = ERRETM + PSI
452 ERRETM = ABS( ERRETM )
454 * Evaluate PHI and the derivative DPHI
456 TEMP = Z( N ) / DELTA( N )
459 ERRETM = EIGHT*( -PHI-PSI ) + ERRETM - PHI + RHOINV +
460 $ ABS( TAU )*( DPSI+DPHI )
462 W = RHOINV + PHI + PSI
465 * Return with INFO = 1, NITER = MAXIT and not converged
471 * End for the case I = N
480 * Calculate initial guess
482 DEL = D( IP1 ) - D( I )
485 DELTA( J ) = ( D( J )-D( I ) ) - MIDPT
490 PSI = PSI + Z( J )*Z( J ) / DELTA( J )
494 DO 120 J = N, I + 2, -1
495 PHI = PHI + Z( J )*Z( J ) / DELTA( J )
497 C = RHOINV + PSI + PHI
498 W = C + Z( I )*Z( I ) / DELTA( I ) +
499 $ Z( IP1 )*Z( IP1 ) / DELTA( IP1 )
503 * d(i)< the ith eigenvalue < (d(i)+d(i+1))/2
505 * We choose d(i) as origin.
508 A = C*DEL + Z( I )*Z( I ) + Z( IP1 )*Z( IP1 )
509 B = Z( I )*Z( I )*DEL
511 TAU = TWO*B / ( A+SQRT( ABS( A*A-FOUR*B*C ) ) )
513 TAU = ( A-SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
519 * (d(i)+d(i+1))/2 <= the ith eigenvalue < d(i+1)
521 * We choose d(i+1) as origin.
524 A = C*DEL - Z( I )*Z( I ) - Z( IP1 )*Z( IP1 )
525 B = Z( IP1 )*Z( IP1 )*DEL
527 TAU = TWO*B / ( A-SQRT( ABS( A*A+FOUR*B*C ) ) )
529 TAU = -( A+SQRT( ABS( A*A+FOUR*B*C ) ) ) / ( TWO*C )
537 DELTA( J ) = ( D( J )-D( I ) ) - TAU
541 DELTA( J ) = ( D( J )-D( IP1 ) ) - TAU
552 * Evaluate PSI and the derivative DPSI
558 TEMP = Z( J ) / DELTA( J )
559 PSI = PSI + Z( J )*TEMP
560 DPSI = DPSI + TEMP*TEMP
561 ERRETM = ERRETM + PSI
563 ERRETM = ABS( ERRETM )
565 * Evaluate PHI and the derivative DPHI
569 DO 160 J = N, IIP1, -1
570 TEMP = Z( J ) / DELTA( J )
571 PHI = PHI + Z( J )*TEMP
572 DPHI = DPHI + TEMP*TEMP
573 ERRETM = ERRETM + PHI
576 W = RHOINV + PHI + PSI
578 * W is the value of the secular function with
579 * its ii-th element removed.
589 IF( II.EQ.1 .OR. II.EQ.N )
592 TEMP = Z( II ) / DELTA( II )
593 DW = DPSI + DPHI + TEMP*TEMP
596 ERRETM = EIGHT*( PHI-PSI ) + ERRETM + TWO*RHOINV +
597 $ THREE*ABS( TEMP ) + ABS( TAU )*DW
599 * Test for convergence
601 IF( ABS( W ).LE.EPS*ERRETM ) THEN
605 DLAM = D( IP1 ) + TAU
611 DLTLB = MAX( DLTLB, TAU )
613 DLTUB = MIN( DLTUB, TAU )
616 * Calculate the new step
619 IF( .NOT.SWTCH3 ) THEN
621 C = W - DELTA( IP1 )*DW - ( D( I )-D( IP1 ) )*
622 $ ( Z( I ) / DELTA( I ) )**2
624 C = W - DELTA( I )*DW - ( D( IP1 )-D( I ) )*
625 $ ( Z( IP1 ) / DELTA( IP1 ) )**2
627 A = ( DELTA( I )+DELTA( IP1 ) )*W -
628 $ DELTA( I )*DELTA( IP1 )*DW
629 B = DELTA( I )*DELTA( IP1 )*W
633 A = Z( I )*Z( I ) + DELTA( IP1 )*DELTA( IP1 )*
636 A = Z( IP1 )*Z( IP1 ) + DELTA( I )*DELTA( I )*
641 ELSE IF( A.LE.ZERO ) THEN
642 ETA = ( A-SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
644 ETA = TWO*B / ( A+SQRT( ABS( A*A-FOUR*B*C ) ) )
648 * Interpolation using THREE most relevant poles
650 TEMP = RHOINV + PSI + PHI
652 TEMP1 = Z( IIM1 ) / DELTA( IIM1 )
654 C = TEMP - DELTA( IIP1 )*( DPSI+DPHI ) -
655 $ ( D( IIM1 )-D( IIP1 ) )*TEMP1
656 ZZ( 1 ) = Z( IIM1 )*Z( IIM1 )
657 ZZ( 3 ) = DELTA( IIP1 )*DELTA( IIP1 )*
658 $ ( ( DPSI-TEMP1 )+DPHI )
660 TEMP1 = Z( IIP1 ) / DELTA( IIP1 )
662 C = TEMP - DELTA( IIM1 )*( DPSI+DPHI ) -
663 $ ( D( IIP1 )-D( IIM1 ) )*TEMP1
664 ZZ( 1 ) = DELTA( IIM1 )*DELTA( IIM1 )*
665 $ ( DPSI+( DPHI-TEMP1 ) )
666 ZZ( 3 ) = Z( IIP1 )*Z( IIP1 )
668 ZZ( 2 ) = Z( II )*Z( II )
669 CALL DLAED6( NITER, ORGATI, C, DELTA( IIM1 ), ZZ, W, ETA,
675 * Note, eta should be positive if w is negative, and
676 * eta should be negative otherwise. However,
677 * if for some reason caused by roundoff, eta*w > 0,
678 * we simply use one Newton step instead. This way
679 * will guarantee eta*w < 0.
684 IF( TEMP.GT.DLTUB .OR. TEMP.LT.DLTLB ) THEN
686 ETA = ( DLTUB-TAU ) / TWO
688 ETA = ( DLTLB-TAU ) / TWO
695 DELTA( J ) = DELTA( J ) - ETA
698 * Evaluate PSI and the derivative DPSI
704 TEMP = Z( J ) / DELTA( J )
705 PSI = PSI + Z( J )*TEMP
706 DPSI = DPSI + TEMP*TEMP
707 ERRETM = ERRETM + PSI
709 ERRETM = ABS( ERRETM )
711 * Evaluate PHI and the derivative DPHI
715 DO 200 J = N, IIP1, -1
716 TEMP = Z( J ) / DELTA( J )
717 PHI = PHI + Z( J )*TEMP
718 DPHI = DPHI + TEMP*TEMP
719 ERRETM = ERRETM + PHI
722 TEMP = Z( II ) / DELTA( II )
723 DW = DPSI + DPHI + TEMP*TEMP
725 W = RHOINV + PHI + PSI + TEMP
726 ERRETM = EIGHT*( PHI-PSI ) + ERRETM + TWO*RHOINV +
727 $ THREE*ABS( TEMP ) + ABS( TAU+ETA )*DW
731 IF( -W.GT.ABS( PREW ) / TEN )
734 IF( W.GT.ABS( PREW ) / TEN )
740 * Main loop to update the values of the array DELTA
744 DO 240 NITER = ITER, MAXIT
746 * Test for convergence
748 IF( ABS( W ).LE.EPS*ERRETM ) THEN
752 DLAM = D( IP1 ) + TAU
758 DLTLB = MAX( DLTLB, TAU )
760 DLTUB = MIN( DLTUB, TAU )
763 * Calculate the new step
765 IF( .NOT.SWTCH3 ) THEN
766 IF( .NOT.SWTCH ) THEN
768 C = W - DELTA( IP1 )*DW -
769 $ ( D( I )-D( IP1 ) )*( Z( I ) / DELTA( I ) )**2
771 C = W - DELTA( I )*DW - ( D( IP1 )-D( I ) )*
772 $ ( Z( IP1 ) / DELTA( IP1 ) )**2
775 TEMP = Z( II ) / DELTA( II )
777 DPSI = DPSI + TEMP*TEMP
779 DPHI = DPHI + TEMP*TEMP
781 C = W - DELTA( I )*DPSI - DELTA( IP1 )*DPHI
783 A = ( DELTA( I )+DELTA( IP1 ) )*W -
784 $ DELTA( I )*DELTA( IP1 )*DW
785 B = DELTA( I )*DELTA( IP1 )*W
788 IF( .NOT.SWTCH ) THEN
790 A = Z( I )*Z( I ) + DELTA( IP1 )*
791 $ DELTA( IP1 )*( DPSI+DPHI )
793 A = Z( IP1 )*Z( IP1 ) +
794 $ DELTA( I )*DELTA( I )*( DPSI+DPHI )
797 A = DELTA( I )*DELTA( I )*DPSI +
798 $ DELTA( IP1 )*DELTA( IP1 )*DPHI
802 ELSE IF( A.LE.ZERO ) THEN
803 ETA = ( A-SQRT( ABS( A*A-FOUR*B*C ) ) ) / ( TWO*C )
805 ETA = TWO*B / ( A+SQRT( ABS( A*A-FOUR*B*C ) ) )
809 * Interpolation using THREE most relevant poles
811 TEMP = RHOINV + PSI + PHI
813 C = TEMP - DELTA( IIM1 )*DPSI - DELTA( IIP1 )*DPHI
814 ZZ( 1 ) = DELTA( IIM1 )*DELTA( IIM1 )*DPSI
815 ZZ( 3 ) = DELTA( IIP1 )*DELTA( IIP1 )*DPHI
818 TEMP1 = Z( IIM1 ) / DELTA( IIM1 )
820 C = TEMP - DELTA( IIP1 )*( DPSI+DPHI ) -
821 $ ( D( IIM1 )-D( IIP1 ) )*TEMP1
822 ZZ( 1 ) = Z( IIM1 )*Z( IIM1 )
823 ZZ( 3 ) = DELTA( IIP1 )*DELTA( IIP1 )*
824 $ ( ( DPSI-TEMP1 )+DPHI )
826 TEMP1 = Z( IIP1 ) / DELTA( IIP1 )
828 C = TEMP - DELTA( IIM1 )*( DPSI+DPHI ) -
829 $ ( D( IIP1 )-D( IIM1 ) )*TEMP1
830 ZZ( 1 ) = DELTA( IIM1 )*DELTA( IIM1 )*
831 $ ( DPSI+( DPHI-TEMP1 ) )
832 ZZ( 3 ) = Z( IIP1 )*Z( IIP1 )
835 CALL DLAED6( NITER, ORGATI, C, DELTA( IIM1 ), ZZ, W, ETA,
841 * Note, eta should be positive if w is negative, and
842 * eta should be negative otherwise. However,
843 * if for some reason caused by roundoff, eta*w > 0,
844 * we simply use one Newton step instead. This way
845 * will guarantee eta*w < 0.
850 IF( TEMP.GT.DLTUB .OR. TEMP.LT.DLTLB ) THEN
852 ETA = ( DLTUB-TAU ) / TWO
854 ETA = ( DLTLB-TAU ) / TWO
859 DELTA( J ) = DELTA( J ) - ETA
865 * Evaluate PSI and the derivative DPSI
871 TEMP = Z( J ) / DELTA( J )
872 PSI = PSI + Z( J )*TEMP
873 DPSI = DPSI + TEMP*TEMP
874 ERRETM = ERRETM + PSI
876 ERRETM = ABS( ERRETM )
878 * Evaluate PHI and the derivative DPHI
882 DO 230 J = N, IIP1, -1
883 TEMP = Z( J ) / DELTA( J )
884 PHI = PHI + Z( J )*TEMP
885 DPHI = DPHI + TEMP*TEMP
886 ERRETM = ERRETM + PHI
889 TEMP = Z( II ) / DELTA( II )
890 DW = DPSI + DPHI + TEMP*TEMP
892 W = RHOINV + PHI + PSI + TEMP
893 ERRETM = EIGHT*( PHI-PSI ) + ERRETM + TWO*RHOINV +
894 $ THREE*ABS( TEMP ) + ABS( TAU )*DW
895 IF( W*PREW.GT.ZERO .AND. ABS( W ).GT.ABS( PREW ) / TEN )
900 * Return with INFO = 1, NITER = MAXIT and not converged
906 DLAM = D( IP1 ) + TAU