3 /* Subroutine */ int dlaed6_(integer *kniter, logical *orgati, doublereal *
4 rho, doublereal *d__, doublereal *z__, doublereal *finit, doublereal *
7 /* System generated locals */
9 doublereal d__1, d__2, d__3, d__4;
11 /* Builtin functions */
12 double sqrt(doublereal), log(doublereal), pow_di(doublereal *, integer *);
15 doublereal a, b, c__, f;
17 doublereal fc, df, ddf, lbd, eta, ubd, eps, base;
19 doublereal temp, temp1, temp2, temp3, temp4;
22 doublereal small1, small2, sminv1, sminv2;
23 extern doublereal dlamch_(char *);
24 doublereal dscale[3], sclfac, zscale[3], erretm, sclinv;
27 /* -- LAPACK routine (version 3.1.1) -- */
28 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
31 /* .. Scalar Arguments .. */
33 /* .. Array Arguments .. */
39 /* DLAED6 computes the positive or negative root (closest to the origin) */
42 /* f(x) = rho + --------- + ---------- + --------- */
43 /* d(1)-x d(2)-x d(3)-x */
45 /* It is assumed that */
47 /* if ORGATI = .true. the root is between d(2) and d(3); */
48 /* otherwise it is between d(1) and d(2) */
50 /* This routine will be called by DLAED4 when necessary. In most cases, */
51 /* the root sought is the smallest in magnitude, though it might not be */
52 /* in some extremely rare situations. */
57 /* KNITER (input) INTEGER */
58 /* Refer to DLAED4 for its significance. */
60 /* ORGATI (input) LOGICAL */
61 /* If ORGATI is true, the needed root is between d(2) and */
62 /* d(3); otherwise it is between d(1) and d(2). See */
63 /* DLAED4 for further details. */
65 /* RHO (input) DOUBLE PRECISION */
66 /* Refer to the equation f(x) above. */
68 /* D (input) DOUBLE PRECISION array, dimension (3) */
69 /* D satisfies d(1) < d(2) < d(3). */
71 /* Z (input) DOUBLE PRECISION array, dimension (3) */
72 /* Each of the elements in z must be positive. */
74 /* FINIT (input) DOUBLE PRECISION */
75 /* The value of f at 0. It is more accurate than the one */
76 /* evaluated inside this routine (if someone wants to do */
79 /* TAU (output) DOUBLE PRECISION */
80 /* The root of the equation f(x). */
82 /* INFO (output) INTEGER */
83 /* = 0: successful exit */
84 /* > 0: if INFO = 1, failure to converge */
89 /* 30/06/99: Based on contributions by */
90 /* Ren-Cang Li, Computer Science Division, University of California */
91 /* at Berkeley, USA */
93 /* 10/02/03: This version has a few statements commented out for thread */
94 /* safety (machine parameters are computed on each entry). SJH. */
96 /* 05/10/06: Modified from a new version of Ren-Cang Li, use */
97 /* Gragg-Thornton-Warner cubic convergent scheme for better stability. */
99 /* ===================================================================== */
101 /* .. Parameters .. */
103 /* .. External Functions .. */
105 /* .. Local Arrays .. */
107 /* .. Local Scalars .. */
109 /* .. Intrinsic Functions .. */
111 /* .. Executable Statements .. */
113 /* Parameter adjustments */
137 temp = (d__[3] - d__[2]) / 2.;
138 c__ = *rho + z__[1] / (d__[1] - d__[2] - temp);
139 a = c__ * (d__[2] + d__[3]) + z__[2] + z__[3];
140 b = c__ * d__[2] * d__[3] + z__[2] * d__[3] + z__[3] * d__[2];
142 temp = (d__[1] - d__[2]) / 2.;
143 c__ = *rho + z__[3] / (d__[3] - d__[2] - temp);
144 a = c__ * (d__[1] + d__[2]) + z__[1] + z__[2];
145 b = c__ * d__[1] * d__[2] + z__[1] * d__[2] + z__[2] * d__[1];
148 d__1 = abs(a), d__2 = abs(b), d__1 = max(d__1,d__2), d__2 = abs(c__);
149 temp = max(d__1,d__2);
155 } else if (a <= 0.) {
156 *tau = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
159 *tau = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))
162 if (*tau < lbd || *tau > ubd) {
163 *tau = (lbd + ubd) / 2.;
165 if (d__[1] == *tau || d__[2] == *tau || d__[3] == *tau) {
168 temp = *finit + *tau * z__[1] / (d__[1] * (d__[1] - *tau)) + *tau
169 * z__[2] / (d__[2] * (d__[2] - *tau)) + *tau * z__[3] / (
170 d__[3] * (d__[3] - *tau));
176 if (abs(*finit) <= abs(temp)) {
182 /* get machine parameters for possible scaling to avoid overflow */
184 /* modified by Sven: parameters SMALL1, SMINV1, SMALL2, */
185 /* SMINV2, EPS are not SAVEd anymore between one call to the */
186 /* others but recomputed at each call */
188 eps = dlamch_("Epsilon");
189 base = dlamch_("Base");
190 i__1 = (integer) (log(dlamch_("SafMin")) / log(base) / 3.);
191 small1 = pow_di(&base, &i__1);
192 sminv1 = 1. / small1;
193 small2 = small1 * small1;
194 sminv2 = sminv1 * sminv1;
196 /* Determine if scaling of inputs necessary to avoid overflow */
197 /* when computing 1/TEMP**3 */
201 d__3 = (d__1 = d__[2] - *tau, abs(d__1)), d__4 = (d__2 = d__[3] - *
203 temp = min(d__3,d__4);
206 d__3 = (d__1 = d__[1] - *tau, abs(d__1)), d__4 = (d__2 = d__[2] - *
208 temp = min(d__3,d__4);
211 if (temp <= small1) {
213 if (temp <= small2) {
215 /* Scale up by power of radix nearest 1/SAFMIN**(2/3) */
221 /* Scale up by power of radix nearest 1/SAFMIN**(1/3) */
227 /* Scaling up safe because D, Z, TAU scaled elsewhere to be O(1) */
229 for (i__ = 1; i__ <= 3; ++i__) {
230 dscale[i__ - 1] = d__[i__] * sclfac;
231 zscale[i__ - 1] = z__[i__] * sclfac;
239 /* Copy D and Z to DSCALE and ZSCALE */
241 for (i__ = 1; i__ <= 3; ++i__) {
242 dscale[i__ - 1] = d__[i__];
243 zscale[i__ - 1] = z__[i__];
251 for (i__ = 1; i__ <= 3; ++i__) {
252 temp = 1. / (dscale[i__ - 1] - *tau);
253 temp1 = zscale[i__ - 1] * temp;
254 temp2 = temp1 * temp;
255 temp3 = temp2 * temp;
256 fc += temp1 / dscale[i__ - 1];
261 f = *finit + *tau * fc;
272 /* Iteration begins -- Use Gragg-Thornton-Warner cubic convergent */
275 /* It is not hard to see that */
277 /* 1) Iterations will go up monotonically */
280 /* 2) Iterations will go down monotonically */
285 for (niter = iter; niter <= 40; ++niter) {
288 temp1 = dscale[1] - *tau;
289 temp2 = dscale[2] - *tau;
291 temp1 = dscale[0] - *tau;
292 temp2 = dscale[1] - *tau;
294 a = (temp1 + temp2) * f - temp1 * temp2 * df;
295 b = temp1 * temp2 * f;
296 c__ = f - (temp1 + temp2) * df + temp1 * temp2 * ddf;
298 d__1 = abs(a), d__2 = abs(b), d__1 = max(d__1,d__2), d__2 = abs(c__);
299 temp = max(d__1,d__2);
305 } else if (a <= 0.) {
306 eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (c__
309 eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))
317 if (*tau < lbd || *tau > ubd) {
318 *tau = (lbd + ubd) / 2.;
325 for (i__ = 1; i__ <= 3; ++i__) {
326 temp = 1. / (dscale[i__ - 1] - *tau);
327 temp1 = zscale[i__ - 1] * temp;
328 temp2 = temp1 * temp;
329 temp3 = temp2 * temp;
330 temp4 = temp1 / dscale[i__ - 1];
332 erretm += abs(temp4);
337 f = *finit + *tau * fc;
338 erretm = (abs(*finit) + abs(*tau) * erretm) * 8. + abs(*tau) * df;
339 if (abs(f) <= eps * erretm) {