00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016 int dlasd4_(integer *n, integer *i__, doublereal *d__,
00017 doublereal *z__, doublereal *delta, doublereal *rho, doublereal *
00018 sigma, doublereal *work, integer *info)
00019 {
00020
00021 integer i__1;
00022 doublereal d__1;
00023
00024
00025 double sqrt(doublereal);
00026
00027
00028 doublereal a, b, c__;
00029 integer j;
00030 doublereal w, dd[3];
00031 integer ii;
00032 doublereal dw, zz[3];
00033 integer ip1;
00034 doublereal eta, phi, eps, tau, psi;
00035 integer iim1, iip1;
00036 doublereal dphi, dpsi;
00037 integer iter;
00038 doublereal temp, prew, sg2lb, sg2ub, temp1, temp2, dtiim, delsq, dtiip;
00039 integer niter;
00040 doublereal dtisq;
00041 logical swtch;
00042 doublereal dtnsq;
00043 extern int dlaed6_(integer *, logical *, doublereal *,
00044 doublereal *, doublereal *, doublereal *, doublereal *, integer *)
00045 , dlasd5_(integer *, doublereal *, doublereal *, doublereal *,
00046 doublereal *, doublereal *, doublereal *);
00047 doublereal delsq2, dtnsq1;
00048 logical swtch3;
00049 extern doublereal dlamch_(char *);
00050 logical orgati;
00051 doublereal erretm, dtipsq, rhoinv;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 --work;
00164 --delta;
00165 --z__;
00166 --d__;
00167
00168
00169 *info = 0;
00170 if (*n == 1) {
00171
00172
00173
00174 *sigma = sqrt(d__[1] * d__[1] + *rho * z__[1] * z__[1]);
00175 delta[1] = 1.;
00176 work[1] = 1.;
00177 return 0;
00178 }
00179 if (*n == 2) {
00180 dlasd5_(i__, &d__[1], &z__[1], &delta[1], rho, sigma, &work[1]);
00181 return 0;
00182 }
00183
00184
00185
00186 eps = dlamch_("Epsilon");
00187 rhoinv = 1. / *rho;
00188
00189
00190
00191 if (*i__ == *n) {
00192
00193
00194
00195 ii = *n - 1;
00196 niter = 1;
00197
00198
00199
00200 temp = *rho / 2.;
00201
00202
00203
00204
00205 temp1 = temp / (d__[*n] + sqrt(d__[*n] * d__[*n] + temp));
00206 i__1 = *n;
00207 for (j = 1; j <= i__1; ++j) {
00208 work[j] = d__[j] + d__[*n] + temp1;
00209 delta[j] = d__[j] - d__[*n] - temp1;
00210
00211 }
00212
00213 psi = 0.;
00214 i__1 = *n - 2;
00215 for (j = 1; j <= i__1; ++j) {
00216 psi += z__[j] * z__[j] / (delta[j] * work[j]);
00217
00218 }
00219
00220 c__ = rhoinv + psi;
00221 w = c__ + z__[ii] * z__[ii] / (delta[ii] * work[ii]) + z__[*n] * z__[*
00222 n] / (delta[*n] * work[*n]);
00223
00224 if (w <= 0.) {
00225 temp1 = sqrt(d__[*n] * d__[*n] + *rho);
00226 temp = z__[*n - 1] * z__[*n - 1] / ((d__[*n - 1] + temp1) * (d__[*
00227 n] - d__[*n - 1] + *rho / (d__[*n] + temp1))) + z__[*n] *
00228 z__[*n] / *rho;
00229
00230
00231
00232
00233 if (c__ <= temp) {
00234 tau = *rho;
00235 } else {
00236 delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
00237 a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*
00238 n];
00239 b = z__[*n] * z__[*n] * delsq;
00240 if (a < 0.) {
00241 tau = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
00242 } else {
00243 tau = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
00244 }
00245 }
00246
00247
00248
00249
00250 } else {
00251 delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
00252 a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*n];
00253 b = z__[*n] * z__[*n] * delsq;
00254
00255
00256
00257
00258 if (a < 0.) {
00259 tau = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
00260 } else {
00261 tau = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
00262 }
00263
00264
00265
00266
00267 }
00268
00269
00270
00271 eta = tau / (d__[*n] + sqrt(d__[*n] * d__[*n] + tau));
00272
00273 *sigma = d__[*n] + eta;
00274 i__1 = *n;
00275 for (j = 1; j <= i__1; ++j) {
00276 delta[j] = d__[j] - d__[*i__] - eta;
00277 work[j] = d__[j] + d__[*i__] + eta;
00278
00279 }
00280
00281
00282
00283 dpsi = 0.;
00284 psi = 0.;
00285 erretm = 0.;
00286 i__1 = ii;
00287 for (j = 1; j <= i__1; ++j) {
00288 temp = z__[j] / (delta[j] * work[j]);
00289 psi += z__[j] * temp;
00290 dpsi += temp * temp;
00291 erretm += psi;
00292
00293 }
00294 erretm = abs(erretm);
00295
00296
00297
00298 temp = z__[*n] / (delta[*n] * work[*n]);
00299 phi = z__[*n] * temp;
00300 dphi = temp * temp;
00301 erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (dpsi
00302 + dphi);
00303
00304 w = rhoinv + phi + psi;
00305
00306
00307
00308 if (abs(w) <= eps * erretm) {
00309 goto L240;
00310 }
00311
00312
00313
00314 ++niter;
00315 dtnsq1 = work[*n - 1] * delta[*n - 1];
00316 dtnsq = work[*n] * delta[*n];
00317 c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
00318 a = (dtnsq + dtnsq1) * w - dtnsq * dtnsq1 * (dpsi + dphi);
00319 b = dtnsq * dtnsq1 * w;
00320 if (c__ < 0.) {
00321 c__ = abs(c__);
00322 }
00323 if (c__ == 0.) {
00324 eta = *rho - *sigma * *sigma;
00325 } else if (a >= 0.) {
00326 eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (c__
00327 * 2.);
00328 } else {
00329 eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))
00330 );
00331 }
00332
00333
00334
00335
00336
00337
00338
00339 if (w * eta > 0.) {
00340 eta = -w / (dpsi + dphi);
00341 }
00342 temp = eta - dtnsq;
00343 if (temp > *rho) {
00344 eta = *rho + dtnsq;
00345 }
00346
00347 tau += eta;
00348 eta /= *sigma + sqrt(eta + *sigma * *sigma);
00349 i__1 = *n;
00350 for (j = 1; j <= i__1; ++j) {
00351 delta[j] -= eta;
00352 work[j] += eta;
00353
00354 }
00355
00356 *sigma += eta;
00357
00358
00359
00360 dpsi = 0.;
00361 psi = 0.;
00362 erretm = 0.;
00363 i__1 = ii;
00364 for (j = 1; j <= i__1; ++j) {
00365 temp = z__[j] / (work[j] * delta[j]);
00366 psi += z__[j] * temp;
00367 dpsi += temp * temp;
00368 erretm += psi;
00369
00370 }
00371 erretm = abs(erretm);
00372
00373
00374
00375 temp = z__[*n] / (work[*n] * delta[*n]);
00376 phi = z__[*n] * temp;
00377 dphi = temp * temp;
00378 erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (dpsi
00379 + dphi);
00380
00381 w = rhoinv + phi + psi;
00382
00383
00384
00385 iter = niter + 1;
00386
00387 for (niter = iter; niter <= 20; ++niter) {
00388
00389
00390
00391 if (abs(w) <= eps * erretm) {
00392 goto L240;
00393 }
00394
00395
00396
00397 dtnsq1 = work[*n - 1] * delta[*n - 1];
00398 dtnsq = work[*n] * delta[*n];
00399 c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
00400 a = (dtnsq + dtnsq1) * w - dtnsq1 * dtnsq * (dpsi + dphi);
00401 b = dtnsq1 * dtnsq * w;
00402 if (a >= 0.) {
00403 eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
00404 c__ * 2.);
00405 } else {
00406 eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(
00407 d__1))));
00408 }
00409
00410
00411
00412
00413
00414
00415
00416 if (w * eta > 0.) {
00417 eta = -w / (dpsi + dphi);
00418 }
00419 temp = eta - dtnsq;
00420 if (temp <= 0.) {
00421 eta /= 2.;
00422 }
00423
00424 tau += eta;
00425 eta /= *sigma + sqrt(eta + *sigma * *sigma);
00426 i__1 = *n;
00427 for (j = 1; j <= i__1; ++j) {
00428 delta[j] -= eta;
00429 work[j] += eta;
00430
00431 }
00432
00433 *sigma += eta;
00434
00435
00436
00437 dpsi = 0.;
00438 psi = 0.;
00439 erretm = 0.;
00440 i__1 = ii;
00441 for (j = 1; j <= i__1; ++j) {
00442 temp = z__[j] / (work[j] * delta[j]);
00443 psi += z__[j] * temp;
00444 dpsi += temp * temp;
00445 erretm += psi;
00446
00447 }
00448 erretm = abs(erretm);
00449
00450
00451
00452 temp = z__[*n] / (work[*n] * delta[*n]);
00453 phi = z__[*n] * temp;
00454 dphi = temp * temp;
00455 erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (
00456 dpsi + dphi);
00457
00458 w = rhoinv + phi + psi;
00459
00460 }
00461
00462
00463
00464 *info = 1;
00465 goto L240;
00466
00467
00468
00469 } else {
00470
00471
00472
00473 niter = 1;
00474 ip1 = *i__ + 1;
00475
00476
00477
00478 delsq = (d__[ip1] - d__[*i__]) * (d__[ip1] + d__[*i__]);
00479 delsq2 = delsq / 2.;
00480 temp = delsq2 / (d__[*i__] + sqrt(d__[*i__] * d__[*i__] + delsq2));
00481 i__1 = *n;
00482 for (j = 1; j <= i__1; ++j) {
00483 work[j] = d__[j] + d__[*i__] + temp;
00484 delta[j] = d__[j] - d__[*i__] - temp;
00485
00486 }
00487
00488 psi = 0.;
00489 i__1 = *i__ - 1;
00490 for (j = 1; j <= i__1; ++j) {
00491 psi += z__[j] * z__[j] / (work[j] * delta[j]);
00492
00493 }
00494
00495 phi = 0.;
00496 i__1 = *i__ + 2;
00497 for (j = *n; j >= i__1; --j) {
00498 phi += z__[j] * z__[j] / (work[j] * delta[j]);
00499
00500 }
00501 c__ = rhoinv + psi + phi;
00502 w = c__ + z__[*i__] * z__[*i__] / (work[*i__] * delta[*i__]) + z__[
00503 ip1] * z__[ip1] / (work[ip1] * delta[ip1]);
00504
00505 if (w > 0.) {
00506
00507
00508
00509
00510
00511 orgati = TRUE_;
00512 sg2lb = 0.;
00513 sg2ub = delsq2;
00514 a = c__ * delsq + z__[*i__] * z__[*i__] + z__[ip1] * z__[ip1];
00515 b = z__[*i__] * z__[*i__] * delsq;
00516 if (a > 0.) {
00517 tau = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
00518 d__1))));
00519 } else {
00520 tau = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
00521 c__ * 2.);
00522 }
00523
00524
00525
00526
00527
00528 eta = tau / (d__[*i__] + sqrt(d__[*i__] * d__[*i__] + tau));
00529 } else {
00530
00531
00532
00533
00534
00535 orgati = FALSE_;
00536 sg2lb = -delsq2;
00537 sg2ub = 0.;
00538 a = c__ * delsq - z__[*i__] * z__[*i__] - z__[ip1] * z__[ip1];
00539 b = z__[ip1] * z__[ip1] * delsq;
00540 if (a < 0.) {
00541 tau = b * 2. / (a - sqrt((d__1 = a * a + b * 4. * c__, abs(
00542 d__1))));
00543 } else {
00544 tau = -(a + sqrt((d__1 = a * a + b * 4. * c__, abs(d__1)))) /
00545 (c__ * 2.);
00546 }
00547
00548
00549
00550
00551
00552 eta = tau / (d__[ip1] + sqrt((d__1 = d__[ip1] * d__[ip1] + tau,
00553 abs(d__1))));
00554 }
00555
00556 if (orgati) {
00557 ii = *i__;
00558 *sigma = d__[*i__] + eta;
00559 i__1 = *n;
00560 for (j = 1; j <= i__1; ++j) {
00561 work[j] = d__[j] + d__[*i__] + eta;
00562 delta[j] = d__[j] - d__[*i__] - eta;
00563
00564 }
00565 } else {
00566 ii = *i__ + 1;
00567 *sigma = d__[ip1] + eta;
00568 i__1 = *n;
00569 for (j = 1; j <= i__1; ++j) {
00570 work[j] = d__[j] + d__[ip1] + eta;
00571 delta[j] = d__[j] - d__[ip1] - eta;
00572
00573 }
00574 }
00575 iim1 = ii - 1;
00576 iip1 = ii + 1;
00577
00578
00579
00580 dpsi = 0.;
00581 psi = 0.;
00582 erretm = 0.;
00583 i__1 = iim1;
00584 for (j = 1; j <= i__1; ++j) {
00585 temp = z__[j] / (work[j] * delta[j]);
00586 psi += z__[j] * temp;
00587 dpsi += temp * temp;
00588 erretm += psi;
00589
00590 }
00591 erretm = abs(erretm);
00592
00593
00594
00595 dphi = 0.;
00596 phi = 0.;
00597 i__1 = iip1;
00598 for (j = *n; j >= i__1; --j) {
00599 temp = z__[j] / (work[j] * delta[j]);
00600 phi += z__[j] * temp;
00601 dphi += temp * temp;
00602 erretm += phi;
00603
00604 }
00605
00606 w = rhoinv + phi + psi;
00607
00608
00609
00610
00611 swtch3 = FALSE_;
00612 if (orgati) {
00613 if (w < 0.) {
00614 swtch3 = TRUE_;
00615 }
00616 } else {
00617 if (w > 0.) {
00618 swtch3 = TRUE_;
00619 }
00620 }
00621 if (ii == 1 || ii == *n) {
00622 swtch3 = FALSE_;
00623 }
00624
00625 temp = z__[ii] / (work[ii] * delta[ii]);
00626 dw = dpsi + dphi + temp * temp;
00627 temp = z__[ii] * temp;
00628 w += temp;
00629 erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3. +
00630 abs(tau) * dw;
00631
00632
00633
00634 if (abs(w) <= eps * erretm) {
00635 goto L240;
00636 }
00637
00638 if (w <= 0.) {
00639 sg2lb = max(sg2lb,tau);
00640 } else {
00641 sg2ub = min(sg2ub,tau);
00642 }
00643
00644
00645
00646 ++niter;
00647 if (! swtch3) {
00648 dtipsq = work[ip1] * delta[ip1];
00649 dtisq = work[*i__] * delta[*i__];
00650 if (orgati) {
00651
00652 d__1 = z__[*i__] / dtisq;
00653 c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
00654 } else {
00655
00656 d__1 = z__[ip1] / dtipsq;
00657 c__ = w - dtisq * dw - delsq * (d__1 * d__1);
00658 }
00659 a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
00660 b = dtipsq * dtisq * w;
00661 if (c__ == 0.) {
00662 if (a == 0.) {
00663 if (orgati) {
00664 a = z__[*i__] * z__[*i__] + dtipsq * dtipsq * (dpsi +
00665 dphi);
00666 } else {
00667 a = z__[ip1] * z__[ip1] + dtisq * dtisq * (dpsi +
00668 dphi);
00669 }
00670 }
00671 eta = b / a;
00672 } else if (a <= 0.) {
00673 eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
00674 c__ * 2.);
00675 } else {
00676 eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
00677 d__1))));
00678 }
00679 } else {
00680
00681
00682
00683 dtiim = work[iim1] * delta[iim1];
00684 dtiip = work[iip1] * delta[iip1];
00685 temp = rhoinv + psi + phi;
00686 if (orgati) {
00687 temp1 = z__[iim1] / dtiim;
00688 temp1 *= temp1;
00689 c__ = temp - dtiip * (dpsi + dphi) - (d__[iim1] - d__[iip1]) *
00690 (d__[iim1] + d__[iip1]) * temp1;
00691 zz[0] = z__[iim1] * z__[iim1];
00692 if (dpsi < temp1) {
00693 zz[2] = dtiip * dtiip * dphi;
00694 } else {
00695 zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
00696 }
00697 } else {
00698 temp1 = z__[iip1] / dtiip;
00699 temp1 *= temp1;
00700 c__ = temp - dtiim * (dpsi + dphi) - (d__[iip1] - d__[iim1]) *
00701 (d__[iim1] + d__[iip1]) * temp1;
00702 if (dphi < temp1) {
00703 zz[0] = dtiim * dtiim * dpsi;
00704 } else {
00705 zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
00706 }
00707 zz[2] = z__[iip1] * z__[iip1];
00708 }
00709 zz[1] = z__[ii] * z__[ii];
00710 dd[0] = dtiim;
00711 dd[1] = delta[ii] * work[ii];
00712 dd[2] = dtiip;
00713 dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
00714 if (*info != 0) {
00715 goto L240;
00716 }
00717 }
00718
00719
00720
00721
00722
00723
00724
00725 if (w * eta >= 0.) {
00726 eta = -w / dw;
00727 }
00728 if (orgati) {
00729 temp1 = work[*i__] * delta[*i__];
00730 temp = eta - temp1;
00731 } else {
00732 temp1 = work[ip1] * delta[ip1];
00733 temp = eta - temp1;
00734 }
00735 if (temp > sg2ub || temp < sg2lb) {
00736 if (w < 0.) {
00737 eta = (sg2ub - tau) / 2.;
00738 } else {
00739 eta = (sg2lb - tau) / 2.;
00740 }
00741 }
00742
00743 tau += eta;
00744 eta /= *sigma + sqrt(*sigma * *sigma + eta);
00745
00746 prew = w;
00747
00748 *sigma += eta;
00749 i__1 = *n;
00750 for (j = 1; j <= i__1; ++j) {
00751 work[j] += eta;
00752 delta[j] -= eta;
00753
00754 }
00755
00756
00757
00758 dpsi = 0.;
00759 psi = 0.;
00760 erretm = 0.;
00761 i__1 = iim1;
00762 for (j = 1; j <= i__1; ++j) {
00763 temp = z__[j] / (work[j] * delta[j]);
00764 psi += z__[j] * temp;
00765 dpsi += temp * temp;
00766 erretm += psi;
00767
00768 }
00769 erretm = abs(erretm);
00770
00771
00772
00773 dphi = 0.;
00774 phi = 0.;
00775 i__1 = iip1;
00776 for (j = *n; j >= i__1; --j) {
00777 temp = z__[j] / (work[j] * delta[j]);
00778 phi += z__[j] * temp;
00779 dphi += temp * temp;
00780 erretm += phi;
00781
00782 }
00783
00784 temp = z__[ii] / (work[ii] * delta[ii]);
00785 dw = dpsi + dphi + temp * temp;
00786 temp = z__[ii] * temp;
00787 w = rhoinv + phi + psi + temp;
00788 erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3. +
00789 abs(tau) * dw;
00790
00791 if (w <= 0.) {
00792 sg2lb = max(sg2lb,tau);
00793 } else {
00794 sg2ub = min(sg2ub,tau);
00795 }
00796
00797 swtch = FALSE_;
00798 if (orgati) {
00799 if (-w > abs(prew) / 10.) {
00800 swtch = TRUE_;
00801 }
00802 } else {
00803 if (w > abs(prew) / 10.) {
00804 swtch = TRUE_;
00805 }
00806 }
00807
00808
00809
00810 iter = niter + 1;
00811
00812 for (niter = iter; niter <= 20; ++niter) {
00813
00814
00815
00816 if (abs(w) <= eps * erretm) {
00817 goto L240;
00818 }
00819
00820
00821
00822 if (! swtch3) {
00823 dtipsq = work[ip1] * delta[ip1];
00824 dtisq = work[*i__] * delta[*i__];
00825 if (! swtch) {
00826 if (orgati) {
00827
00828 d__1 = z__[*i__] / dtisq;
00829 c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
00830 } else {
00831
00832 d__1 = z__[ip1] / dtipsq;
00833 c__ = w - dtisq * dw - delsq * (d__1 * d__1);
00834 }
00835 } else {
00836 temp = z__[ii] / (work[ii] * delta[ii]);
00837 if (orgati) {
00838 dpsi += temp * temp;
00839 } else {
00840 dphi += temp * temp;
00841 }
00842 c__ = w - dtisq * dpsi - dtipsq * dphi;
00843 }
00844 a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
00845 b = dtipsq * dtisq * w;
00846 if (c__ == 0.) {
00847 if (a == 0.) {
00848 if (! swtch) {
00849 if (orgati) {
00850 a = z__[*i__] * z__[*i__] + dtipsq * dtipsq *
00851 (dpsi + dphi);
00852 } else {
00853 a = z__[ip1] * z__[ip1] + dtisq * dtisq * (
00854 dpsi + dphi);
00855 }
00856 } else {
00857 a = dtisq * dtisq * dpsi + dtipsq * dtipsq * dphi;
00858 }
00859 }
00860 eta = b / a;
00861 } else if (a <= 0.) {
00862 eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))))
00863 / (c__ * 2.);
00864 } else {
00865 eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
00866 abs(d__1))));
00867 }
00868 } else {
00869
00870
00871
00872 dtiim = work[iim1] * delta[iim1];
00873 dtiip = work[iip1] * delta[iip1];
00874 temp = rhoinv + psi + phi;
00875 if (swtch) {
00876 c__ = temp - dtiim * dpsi - dtiip * dphi;
00877 zz[0] = dtiim * dtiim * dpsi;
00878 zz[2] = dtiip * dtiip * dphi;
00879 } else {
00880 if (orgati) {
00881 temp1 = z__[iim1] / dtiim;
00882 temp1 *= temp1;
00883 temp2 = (d__[iim1] - d__[iip1]) * (d__[iim1] + d__[
00884 iip1]) * temp1;
00885 c__ = temp - dtiip * (dpsi + dphi) - temp2;
00886 zz[0] = z__[iim1] * z__[iim1];
00887 if (dpsi < temp1) {
00888 zz[2] = dtiip * dtiip * dphi;
00889 } else {
00890 zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
00891 }
00892 } else {
00893 temp1 = z__[iip1] / dtiip;
00894 temp1 *= temp1;
00895 temp2 = (d__[iip1] - d__[iim1]) * (d__[iim1] + d__[
00896 iip1]) * temp1;
00897 c__ = temp - dtiim * (dpsi + dphi) - temp2;
00898 if (dphi < temp1) {
00899 zz[0] = dtiim * dtiim * dpsi;
00900 } else {
00901 zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
00902 }
00903 zz[2] = z__[iip1] * z__[iip1];
00904 }
00905 }
00906 dd[0] = dtiim;
00907 dd[1] = delta[ii] * work[ii];
00908 dd[2] = dtiip;
00909 dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
00910 if (*info != 0) {
00911 goto L240;
00912 }
00913 }
00914
00915
00916
00917
00918
00919
00920
00921 if (w * eta >= 0.) {
00922 eta = -w / dw;
00923 }
00924 if (orgati) {
00925 temp1 = work[*i__] * delta[*i__];
00926 temp = eta - temp1;
00927 } else {
00928 temp1 = work[ip1] * delta[ip1];
00929 temp = eta - temp1;
00930 }
00931 if (temp > sg2ub || temp < sg2lb) {
00932 if (w < 0.) {
00933 eta = (sg2ub - tau) / 2.;
00934 } else {
00935 eta = (sg2lb - tau) / 2.;
00936 }
00937 }
00938
00939 tau += eta;
00940 eta /= *sigma + sqrt(*sigma * *sigma + eta);
00941
00942 *sigma += eta;
00943 i__1 = *n;
00944 for (j = 1; j <= i__1; ++j) {
00945 work[j] += eta;
00946 delta[j] -= eta;
00947
00948 }
00949
00950 prew = w;
00951
00952
00953
00954 dpsi = 0.;
00955 psi = 0.;
00956 erretm = 0.;
00957 i__1 = iim1;
00958 for (j = 1; j <= i__1; ++j) {
00959 temp = z__[j] / (work[j] * delta[j]);
00960 psi += z__[j] * temp;
00961 dpsi += temp * temp;
00962 erretm += psi;
00963
00964 }
00965 erretm = abs(erretm);
00966
00967
00968
00969 dphi = 0.;
00970 phi = 0.;
00971 i__1 = iip1;
00972 for (j = *n; j >= i__1; --j) {
00973 temp = z__[j] / (work[j] * delta[j]);
00974 phi += z__[j] * temp;
00975 dphi += temp * temp;
00976 erretm += phi;
00977
00978 }
00979
00980 temp = z__[ii] / (work[ii] * delta[ii]);
00981 dw = dpsi + dphi + temp * temp;
00982 temp = z__[ii] * temp;
00983 w = rhoinv + phi + psi + temp;
00984 erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.
00985 + abs(tau) * dw;
00986 if (w * prew > 0. && abs(w) > abs(prew) / 10.) {
00987 swtch = ! swtch;
00988 }
00989
00990 if (w <= 0.) {
00991 sg2lb = max(sg2lb,tau);
00992 } else {
00993 sg2ub = min(sg2ub,tau);
00994 }
00995
00996
00997 }
00998
00999
01000
01001 *info = 1;
01002
01003 }
01004
01005 L240:
01006 return 0;
01007
01008
01009
01010 }