3 /* Subroutine */ int dlasd4_(integer *n, integer *i__, doublereal *d__,
4 doublereal *z__, doublereal *delta, doublereal *rho, doublereal *
5 sigma, doublereal *work, integer *info)
7 /* System generated locals */
11 /* Builtin functions */
12 double sqrt(doublereal);
21 doublereal eta, phi, eps, tau, psi;
23 doublereal dphi, dpsi;
25 doublereal temp, prew, sg2lb, sg2ub, temp1, temp2, dtiim, delsq, dtiip;
30 extern /* Subroutine */ int dlaed6_(integer *, logical *, doublereal *,
31 doublereal *, doublereal *, doublereal *, doublereal *, integer *)
32 , dlasd5_(integer *, doublereal *, doublereal *, doublereal *,
33 doublereal *, doublereal *, doublereal *);
34 doublereal delsq2, dtnsq1;
36 extern doublereal dlamch_(char *);
38 doublereal erretm, dtipsq, rhoinv;
41 /* -- LAPACK auxiliary routine (version 3.1) -- */
42 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
45 /* .. Scalar Arguments .. */
47 /* .. Array Arguments .. */
53 /* This subroutine computes the square root of the I-th updated */
54 /* eigenvalue of a positive symmetric rank-one modification to */
55 /* a positive diagonal matrix whose entries are given as the squares */
56 /* of the corresponding entries in the array d, and that */
58 /* 0 <= D(i) < D(j) for i < j */
60 /* and that RHO > 0. This is arranged by the calling routine, and is */
61 /* no loss in generality. The rank-one modified system is thus */
63 /* diag( D ) * diag( D ) + RHO * Z * Z_transpose. */
65 /* where we assume the Euclidean norm of Z is 1. */
67 /* The method consists of approximating the rational functions in the */
68 /* secular equation by simpler interpolating rational functions. */
73 /* N (input) INTEGER */
74 /* The length of all arrays. */
76 /* I (input) INTEGER */
77 /* The index of the eigenvalue to be computed. 1 <= I <= N. */
79 /* D (input) DOUBLE PRECISION array, dimension ( N ) */
80 /* The original eigenvalues. It is assumed that they are in */
81 /* order, 0 <= D(I) < D(J) for I < J. */
83 /* Z (input) DOUBLE PRECISION array, dimension ( N ) */
84 /* The components of the updating vector. */
86 /* DELTA (output) DOUBLE PRECISION array, dimension ( N ) */
87 /* If N .ne. 1, DELTA contains (D(j) - sigma_I) in its j-th */
88 /* component. If N = 1, then DELTA(1) = 1. The vector DELTA */
89 /* contains the information necessary to construct the */
90 /* (singular) eigenvectors. */
92 /* RHO (input) DOUBLE PRECISION */
93 /* The scalar in the symmetric updating formula. */
95 /* SIGMA (output) DOUBLE PRECISION */
96 /* The computed sigma_I, the I-th updated eigenvalue. */
98 /* WORK (workspace) DOUBLE PRECISION array, dimension ( N ) */
99 /* If N .ne. 1, WORK contains (D(j) + sigma_I) in its j-th */
100 /* component. If N = 1, then WORK( 1 ) = 1. */
102 /* INFO (output) INTEGER */
103 /* = 0: successful exit */
104 /* > 0: if INFO = 1, the updating process failed. */
106 /* Internal Parameters */
107 /* =================== */
109 /* Logical variable ORGATI (origin-at-i?) is used for distinguishing */
110 /* whether D(i) or D(i+1) is treated as the origin. */
112 /* ORGATI = .true. origin at i */
113 /* ORGATI = .false. origin at i+1 */
115 /* Logical variable SWTCH3 (switch-for-3-poles?) is for noting */
116 /* if we are working with THREE poles! */
118 /* MAXIT is the maximum number of iterations allowed for each */
121 /* Further Details */
122 /* =============== */
124 /* Based on contributions by */
125 /* Ren-Cang Li, Computer Science Division, University of California */
126 /* at Berkeley, USA */
128 /* ===================================================================== */
130 /* .. Parameters .. */
132 /* .. Local Scalars .. */
134 /* .. Local Arrays .. */
136 /* .. External Subroutines .. */
138 /* .. External Functions .. */
140 /* .. Intrinsic Functions .. */
142 /* .. Executable Statements .. */
144 /* Since this routine is called in an inner loop, we do no argument */
147 /* Quick return for N=1 and 2. */
149 /* Parameter adjustments */
159 /* Presumably, I=1 upon entry */
161 *sigma = sqrt(d__[1] * d__[1] + *rho * z__[1] * z__[1]);
167 dlasd5_(i__, &d__[1], &z__[1], &delta[1], rho, sigma, &work[1]);
171 /* Compute machine epsilon */
173 eps = dlamch_("Epsilon");
180 /* Initialize some basic variables */
185 /* Calculate initial guess */
189 /* If ||Z||_2 is not one, then TEMP should be set to */
190 /* RHO * ||Z||_2^2 / TWO */
192 temp1 = temp / (d__[*n] + sqrt(d__[*n] * d__[*n] + temp));
194 for (j = 1; j <= i__1; ++j) {
195 work[j] = d__[j] + d__[*n] + temp1;
196 delta[j] = d__[j] - d__[*n] - temp1;
202 for (j = 1; j <= i__1; ++j) {
203 psi += z__[j] * z__[j] / (delta[j] * work[j]);
208 w = c__ + z__[ii] * z__[ii] / (delta[ii] * work[ii]) + z__[*n] * z__[*
209 n] / (delta[*n] * work[*n]);
212 temp1 = sqrt(d__[*n] * d__[*n] + *rho);
213 temp = z__[*n - 1] * z__[*n - 1] / ((d__[*n - 1] + temp1) * (d__[*
214 n] - d__[*n - 1] + *rho / (d__[*n] + temp1))) + z__[*n] *
217 /* The following TAU is to approximate */
218 /* SIGMA_n^2 - D( N )*D( N ) */
223 delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
224 a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*
226 b = z__[*n] * z__[*n] * delsq;
228 tau = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
230 tau = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
234 /* It can be proved that */
235 /* D(N)^2+RHO/2 <= SIGMA_n^2 < D(N)^2+TAU <= D(N)^2+RHO */
238 delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
239 a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*n];
240 b = z__[*n] * z__[*n] * delsq;
242 /* The following TAU is to approximate */
243 /* SIGMA_n^2 - D( N )*D( N ) */
246 tau = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
248 tau = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
251 /* It can be proved that */
252 /* D(N)^2 < D(N)^2+TAU < SIGMA(N)^2 < D(N)^2+RHO/2 */
256 /* The following ETA is to approximate SIGMA_n - D( N ) */
258 eta = tau / (d__[*n] + sqrt(d__[*n] * d__[*n] + tau));
260 *sigma = d__[*n] + eta;
262 for (j = 1; j <= i__1; ++j) {
263 delta[j] = d__[j] - d__[*i__] - eta;
264 work[j] = d__[j] + d__[*i__] + eta;
268 /* Evaluate PSI and the derivative DPSI */
274 for (j = 1; j <= i__1; ++j) {
275 temp = z__[j] / (delta[j] * work[j]);
276 psi += z__[j] * temp;
281 erretm = abs(erretm);
283 /* Evaluate PHI and the derivative DPHI */
285 temp = z__[*n] / (delta[*n] * work[*n]);
286 phi = z__[*n] * temp;
288 erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (dpsi
291 w = rhoinv + phi + psi;
293 /* Test for convergence */
295 if (abs(w) <= eps * erretm) {
299 /* Calculate the new step */
302 dtnsq1 = work[*n - 1] * delta[*n - 1];
303 dtnsq = work[*n] * delta[*n];
304 c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
305 a = (dtnsq + dtnsq1) * w - dtnsq * dtnsq1 * (dpsi + dphi);
306 b = dtnsq * dtnsq1 * w;
311 eta = *rho - *sigma * *sigma;
312 } else if (a >= 0.) {
313 eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (c__
316 eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))
320 /* Note, eta should be positive if w is negative, and */
321 /* eta should be negative otherwise. However, */
322 /* if for some reason caused by roundoff, eta*w > 0, */
323 /* we simply use one Newton step instead. This way */
324 /* will guarantee eta*w < 0. */
327 eta = -w / (dpsi + dphi);
335 eta /= *sigma + sqrt(eta + *sigma * *sigma);
337 for (j = 1; j <= i__1; ++j) {
345 /* Evaluate PSI and the derivative DPSI */
351 for (j = 1; j <= i__1; ++j) {
352 temp = z__[j] / (work[j] * delta[j]);
353 psi += z__[j] * temp;
358 erretm = abs(erretm);
360 /* Evaluate PHI and the derivative DPHI */
362 temp = z__[*n] / (work[*n] * delta[*n]);
363 phi = z__[*n] * temp;
365 erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (dpsi
368 w = rhoinv + phi + psi;
370 /* Main loop to update the values of the array DELTA */
374 for (niter = iter; niter <= 20; ++niter) {
376 /* Test for convergence */
378 if (abs(w) <= eps * erretm) {
382 /* Calculate the new step */
384 dtnsq1 = work[*n - 1] * delta[*n - 1];
385 dtnsq = work[*n] * delta[*n];
386 c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
387 a = (dtnsq + dtnsq1) * w - dtnsq1 * dtnsq * (dpsi + dphi);
388 b = dtnsq1 * dtnsq * w;
390 eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
393 eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(
397 /* Note, eta should be positive if w is negative, and */
398 /* eta should be negative otherwise. However, */
399 /* if for some reason caused by roundoff, eta*w > 0, */
400 /* we simply use one Newton step instead. This way */
401 /* will guarantee eta*w < 0. */
404 eta = -w / (dpsi + dphi);
412 eta /= *sigma + sqrt(eta + *sigma * *sigma);
414 for (j = 1; j <= i__1; ++j) {
422 /* Evaluate PSI and the derivative DPSI */
428 for (j = 1; j <= i__1; ++j) {
429 temp = z__[j] / (work[j] * delta[j]);
430 psi += z__[j] * temp;
435 erretm = abs(erretm);
437 /* Evaluate PHI and the derivative DPHI */
439 temp = z__[*n] / (work[*n] * delta[*n]);
440 phi = z__[*n] * temp;
442 erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (
445 w = rhoinv + phi + psi;
449 /* Return with INFO = 1, NITER = MAXIT and not converged */
454 /* End for the case I = N */
458 /* The case for I < N */
463 /* Calculate initial guess */
465 delsq = (d__[ip1] - d__[*i__]) * (d__[ip1] + d__[*i__]);
467 temp = delsq2 / (d__[*i__] + sqrt(d__[*i__] * d__[*i__] + delsq2));
469 for (j = 1; j <= i__1; ++j) {
470 work[j] = d__[j] + d__[*i__] + temp;
471 delta[j] = d__[j] - d__[*i__] - temp;
477 for (j = 1; j <= i__1; ++j) {
478 psi += z__[j] * z__[j] / (work[j] * delta[j]);
484 for (j = *n; j >= i__1; --j) {
485 phi += z__[j] * z__[j] / (work[j] * delta[j]);
488 c__ = rhoinv + psi + phi;
489 w = c__ + z__[*i__] * z__[*i__] / (work[*i__] * delta[*i__]) + z__[
490 ip1] * z__[ip1] / (work[ip1] * delta[ip1]);
494 /* d(i)^2 < the ith sigma^2 < (d(i)^2+d(i+1)^2)/2 */
496 /* We choose d(i) as origin. */
501 a = c__ * delsq + z__[*i__] * z__[*i__] + z__[ip1] * z__[ip1];
502 b = z__[*i__] * z__[*i__] * delsq;
504 tau = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
507 tau = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
511 /* TAU now is an estimation of SIGMA^2 - D( I )^2. The */
512 /* following, however, is the corresponding estimation of */
513 /* SIGMA - D( I ). */
515 eta = tau / (d__[*i__] + sqrt(d__[*i__] * d__[*i__] + tau));
518 /* (d(i)^2+d(i+1)^2)/2 <= the ith sigma^2 < d(i+1)^2/2 */
520 /* We choose d(i+1) as origin. */
525 a = c__ * delsq - z__[*i__] * z__[*i__] - z__[ip1] * z__[ip1];
526 b = z__[ip1] * z__[ip1] * delsq;
528 tau = b * 2. / (a - sqrt((d__1 = a * a + b * 4. * c__, abs(
531 tau = -(a + sqrt((d__1 = a * a + b * 4. * c__, abs(d__1)))) /
535 /* TAU now is an estimation of SIGMA^2 - D( IP1 )^2. The */
536 /* following, however, is the corresponding estimation of */
537 /* SIGMA - D( IP1 ). */
539 eta = tau / (d__[ip1] + sqrt((d__1 = d__[ip1] * d__[ip1] + tau,
545 *sigma = d__[*i__] + eta;
547 for (j = 1; j <= i__1; ++j) {
548 work[j] = d__[j] + d__[*i__] + eta;
549 delta[j] = d__[j] - d__[*i__] - eta;
554 *sigma = d__[ip1] + eta;
556 for (j = 1; j <= i__1; ++j) {
557 work[j] = d__[j] + d__[ip1] + eta;
558 delta[j] = d__[j] - d__[ip1] - eta;
565 /* Evaluate PSI and the derivative DPSI */
571 for (j = 1; j <= i__1; ++j) {
572 temp = z__[j] / (work[j] * delta[j]);
573 psi += z__[j] * temp;
578 erretm = abs(erretm);
580 /* Evaluate PHI and the derivative DPHI */
585 for (j = *n; j >= i__1; --j) {
586 temp = z__[j] / (work[j] * delta[j]);
587 phi += z__[j] * temp;
593 w = rhoinv + phi + psi;
595 /* W is the value of the secular function with */
596 /* its ii-th element removed. */
608 if (ii == 1 || ii == *n) {
612 temp = z__[ii] / (work[ii] * delta[ii]);
613 dw = dpsi + dphi + temp * temp;
614 temp = z__[ii] * temp;
616 erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3. +
619 /* Test for convergence */
621 if (abs(w) <= eps * erretm) {
626 sg2lb = max(sg2lb,tau);
628 sg2ub = min(sg2ub,tau);
631 /* Calculate the new step */
635 dtipsq = work[ip1] * delta[ip1];
636 dtisq = work[*i__] * delta[*i__];
638 /* Computing 2nd power */
639 d__1 = z__[*i__] / dtisq;
640 c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
642 /* Computing 2nd power */
643 d__1 = z__[ip1] / dtipsq;
644 c__ = w - dtisq * dw - delsq * (d__1 * d__1);
646 a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
647 b = dtipsq * dtisq * w;
651 a = z__[*i__] * z__[*i__] + dtipsq * dtipsq * (dpsi +
654 a = z__[ip1] * z__[ip1] + dtisq * dtisq * (dpsi +
659 } else if (a <= 0.) {
660 eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
663 eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
668 /* Interpolation using THREE most relevant poles */
670 dtiim = work[iim1] * delta[iim1];
671 dtiip = work[iip1] * delta[iip1];
672 temp = rhoinv + psi + phi;
674 temp1 = z__[iim1] / dtiim;
676 c__ = temp - dtiip * (dpsi + dphi) - (d__[iim1] - d__[iip1]) *
677 (d__[iim1] + d__[iip1]) * temp1;
678 zz[0] = z__[iim1] * z__[iim1];
680 zz[2] = dtiip * dtiip * dphi;
682 zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
685 temp1 = z__[iip1] / dtiip;
687 c__ = temp - dtiim * (dpsi + dphi) - (d__[iip1] - d__[iim1]) *
688 (d__[iim1] + d__[iip1]) * temp1;
690 zz[0] = dtiim * dtiim * dpsi;
692 zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
694 zz[2] = z__[iip1] * z__[iip1];
696 zz[1] = z__[ii] * z__[ii];
698 dd[1] = delta[ii] * work[ii];
700 dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
706 /* Note, eta should be positive if w is negative, and */
707 /* eta should be negative otherwise. However, */
708 /* if for some reason caused by roundoff, eta*w > 0, */
709 /* we simply use one Newton step instead. This way */
710 /* will guarantee eta*w < 0. */
716 temp1 = work[*i__] * delta[*i__];
719 temp1 = work[ip1] * delta[ip1];
722 if (temp > sg2ub || temp < sg2lb) {
724 eta = (sg2ub - tau) / 2.;
726 eta = (sg2lb - tau) / 2.;
731 eta /= *sigma + sqrt(*sigma * *sigma + eta);
737 for (j = 1; j <= i__1; ++j) {
743 /* Evaluate PSI and the derivative DPSI */
749 for (j = 1; j <= i__1; ++j) {
750 temp = z__[j] / (work[j] * delta[j]);
751 psi += z__[j] * temp;
756 erretm = abs(erretm);
758 /* Evaluate PHI and the derivative DPHI */
763 for (j = *n; j >= i__1; --j) {
764 temp = z__[j] / (work[j] * delta[j]);
765 phi += z__[j] * temp;
771 temp = z__[ii] / (work[ii] * delta[ii]);
772 dw = dpsi + dphi + temp * temp;
773 temp = z__[ii] * temp;
774 w = rhoinv + phi + psi + temp;
775 erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3. +
779 sg2lb = max(sg2lb,tau);
781 sg2ub = min(sg2ub,tau);
786 if (-w > abs(prew) / 10.) {
790 if (w > abs(prew) / 10.) {
795 /* Main loop to update the values of the array DELTA and WORK */
799 for (niter = iter; niter <= 20; ++niter) {
801 /* Test for convergence */
803 if (abs(w) <= eps * erretm) {
807 /* Calculate the new step */
810 dtipsq = work[ip1] * delta[ip1];
811 dtisq = work[*i__] * delta[*i__];
814 /* Computing 2nd power */
815 d__1 = z__[*i__] / dtisq;
816 c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
818 /* Computing 2nd power */
819 d__1 = z__[ip1] / dtipsq;
820 c__ = w - dtisq * dw - delsq * (d__1 * d__1);
823 temp = z__[ii] / (work[ii] * delta[ii]);
829 c__ = w - dtisq * dpsi - dtipsq * dphi;
831 a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
832 b = dtipsq * dtisq * w;
837 a = z__[*i__] * z__[*i__] + dtipsq * dtipsq *
840 a = z__[ip1] * z__[ip1] + dtisq * dtisq * (
844 a = dtisq * dtisq * dpsi + dtipsq * dtipsq * dphi;
848 } else if (a <= 0.) {
849 eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))))
852 eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
857 /* Interpolation using THREE most relevant poles */
859 dtiim = work[iim1] * delta[iim1];
860 dtiip = work[iip1] * delta[iip1];
861 temp = rhoinv + psi + phi;
863 c__ = temp - dtiim * dpsi - dtiip * dphi;
864 zz[0] = dtiim * dtiim * dpsi;
865 zz[2] = dtiip * dtiip * dphi;
868 temp1 = z__[iim1] / dtiim;
870 temp2 = (d__[iim1] - d__[iip1]) * (d__[iim1] + d__[
872 c__ = temp - dtiip * (dpsi + dphi) - temp2;
873 zz[0] = z__[iim1] * z__[iim1];
875 zz[2] = dtiip * dtiip * dphi;
877 zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
880 temp1 = z__[iip1] / dtiip;
882 temp2 = (d__[iip1] - d__[iim1]) * (d__[iim1] + d__[
884 c__ = temp - dtiim * (dpsi + dphi) - temp2;
886 zz[0] = dtiim * dtiim * dpsi;
888 zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
890 zz[2] = z__[iip1] * z__[iip1];
894 dd[1] = delta[ii] * work[ii];
896 dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
902 /* Note, eta should be positive if w is negative, and */
903 /* eta should be negative otherwise. However, */
904 /* if for some reason caused by roundoff, eta*w > 0, */
905 /* we simply use one Newton step instead. This way */
906 /* will guarantee eta*w < 0. */
912 temp1 = work[*i__] * delta[*i__];
915 temp1 = work[ip1] * delta[ip1];
918 if (temp > sg2ub || temp < sg2lb) {
920 eta = (sg2ub - tau) / 2.;
922 eta = (sg2lb - tau) / 2.;
927 eta /= *sigma + sqrt(*sigma * *sigma + eta);
931 for (j = 1; j <= i__1; ++j) {
939 /* Evaluate PSI and the derivative DPSI */
945 for (j = 1; j <= i__1; ++j) {
946 temp = z__[j] / (work[j] * delta[j]);
947 psi += z__[j] * temp;
952 erretm = abs(erretm);
954 /* Evaluate PHI and the derivative DPHI */
959 for (j = *n; j >= i__1; --j) {
960 temp = z__[j] / (work[j] * delta[j]);
961 phi += z__[j] * temp;
967 temp = z__[ii] / (work[ii] * delta[ii]);
968 dw = dpsi + dphi + temp * temp;
969 temp = z__[ii] * temp;
970 w = rhoinv + phi + psi + temp;
971 erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.
973 if (w * prew > 0. && abs(w) > abs(prew) / 10.) {
978 sg2lb = max(sg2lb,tau);
980 sg2ub = min(sg2ub,tau);
986 /* Return with INFO = 1, NITER = MAXIT and not converged */