97 for (
int j = 0; j < n; j++) {
103 for (
int i = n - 1; i > 0; i--) {
108 for (
int k = 0; k < i; k++) {
109 scale = scale + abs(d(k));
113 for (
int j = 0; j < i; j++) {
121 for (
int k = 0; k < i; k++) {
127 if (f > 0) { g = -g; }
131 for (
int j = 0; j < i; j++) {
137 for (
int j = 0; j < i; j++) {
140 g = e(j) + V(j, j) * f;
141 for (
int k = j + 1; k <= i - 1; k++) {
148 for (
int j = 0; j < i; j++) {
152 Real hh = f / (h + h);
153 for (
int j = 0; j < i; j++) {
156 for (
int j = 0; j < i; j++) {
159 for (
int k = j; k <= i - 1; k++) {
160 V(k, j) -= (f * e(k) + g * d(k));
171 for (
int i = 0; i < n - 1; i++) {
172 V(n - 1, i) = V(i, i);
176 for (
int k = 0; k <= i; k++) {
177 d(k) = V(k, i + 1) / h;
179 for (
int j = 0; j <= i; j++) {
181 for (
int k = 0; k <= i; k++) {
182 g += V(k, i + 1) * V(k, j);
184 for (
int k = 0; k <= i; k++) {
189 for (
int k = 0; k <= i; k++) {
193 for (
int j = 0; j < n; j++) {
197 V(n - 1, n - 1) = 1.0;
209 for (
int i = 1; i < n; i++) {
216 Real eps = pow(2.0, -52.0);
217 for (
int l = 0; l < n; l++) {
220 tst1 = max(tst1, abs(d(l)) + abs(e(l)));
225 if (abs(e(m)) <= eps * tst1) {
break; }
240 Real p = (d(l + 1) - g) / (2.0 * e(l));
241 Real r = hypot(p, 1.0);
242 if (p < 0) { r = -r; }
243 d(l) = e(l) / (p + r);
244 d(l + 1) = e(l) * (p + r);
247 for (
int i = l + 2; i < n; i++) {
261 for (
int i = m - 1; i >= l; i--) {
271 p = c * d(i) - s * g;
272 d(i + 1) = h + s * (c * g + s * d(i));
276 for (
int k = 0; k < n; k++) {
278 V(k, i + 1) = s * V(k, i) + c * h;
279 V(k, i) = c * V(k, i) - s * h;
282 p = -s * s2 * c3 * el1 * e(l) / dl1;
288 }
while (abs(e(l)) > eps * tst1);
296 for (
int i = 0; i < n - 1; i++) {
299 for (
int j = i + 1; j < n; j++) {
308 for (
int j = 0; j < n; j++) {
328 for (
int m = low + 1; m <= high - 1; m++) {
332 for (
int i = m; i <= high; i++) {
333 scale = scale + abs(H(i, m - 1));
339 for (
int i = high; i >= m; i--) {
340 ort(i) = H(i, m - 1) / scale;
341 h += ort(i) * ort(i);
344 if (ort(m) > 0) { g = -g; }
351 for (
int j = m; j < n; j++) {
353 for (
int i = high; i >= m; i--) {
354 f += ort(i) * H(i, j);
357 for (
int i = m; i <= high; i++) {
358 H(i, j) -= f * ort(i);
362 for (
int i = 0; i <= high; i++) {
364 for (
int j = high; j >= m; j--) {
365 f += ort(j) * H(i, j);
368 for (
int j = m; j <= high; j++) {
369 H(i, j) -= f * ort(j);
372 ort(m) = scale * ort(m);
373 H(m, m - 1) = scale * g;
379 for (
int i = 0; i < n; i++) {
380 for (
int j = 0; j < n; j++) {
381 V(i, j) = (i == j ? 1.0 : 0.0);
385 for (
int m = high - 1; m >= low + 1; m--) {
386 if (H(m, m - 1) != 0.0) {
387 for (
int i = m + 1; i <= high; i++) {
388 ort(i) = H(i, m - 1);
390 for (
int j = m; j <= high; j++) {
392 for (
int i = m; i <= high; i++) {
393 g += ort(i) * V(i, j);
396 g = (g / ort(m)) / H(m, m - 1);
397 for (
int i = m; i <= high; i++) {
398 V(i, j) += g * ort(i);
408 void cdiv(Real xr, Real xi, Real yr, Real yi) {
410 if (abs(yr) > abs(yi)) {
413 cdivr = (xr + r * xi) / d;
414 cdivi = (xi - r * xr) / d;
418 cdivr = (r * xr + xi) / d;
419 cdivi = (r * xi - xr) / d;
437 Real eps = pow(2.0, -52.0);
439 Real p = 0, q = 0, r = 0, s = 0, z = 0, t, w, x, y;
444 for (
int i = 0; i < nn; i++) {
445 if ((i < low) || (i > high)) {
449 for (
int j = max(i - 1, 0); j < nn; j++) {
450 norm = norm + abs(H(i, j));
462 s = abs(H(l - 1, l - 1)) + abs(H(l, l));
463 if (s == 0.0) { s = norm; }
464 if (abs(H(l, l - 1)) < eps * s) {
break; }
472 H(n, n) = H(n, n) + exshift;
480 }
else if (l == n - 1) {
481 w = H(n, n - 1) * H(n - 1, n);
482 p = (H(n - 1, n - 1) - H(n, n)) / 2.0;
485 H(n, n) = H(n, n) + exshift;
486 H(n - 1, n - 1) = H(n - 1, n - 1) + exshift;
499 if (z != 0.0) { d(n) = x - w / z; }
506 r = sqrt(p * p + q * q);
512 for (
int j = n - 1; j < nn; j++) {
514 H(n - 1, j) = q * z + p * H(n, j);
515 H(n, j) = q * H(n, j) - p * z;
520 for (
int i = 0; i <= n; i++) {
522 H(i, n - 1) = q * z + p * H(i, n);
523 H(i, n) = q * H(i, n) - p * z;
528 for (
int i = low; i <= high; i++) {
530 V(i, n - 1) = q * z + p * V(i, n);
531 V(i, n) = q * V(i, n) - p * z;
555 w = H(n, n - 1) * H(n - 1, n);
562 for (
int i = low; i <= n; i++) {
565 s = abs(H(n, n - 1)) + abs(H(n - 1, n - 2));
577 if (y < x) { s = -s; }
578 s = x - w / ((y - x) / 2.0 + s);
579 for (
int i = low; i <= n; i++) {
596 p = (r * s - w) / H(m + 1, m) + H(m, m + 1);
597 q = H(m + 1, m + 1) - z - r - s;
599 s = abs(p) + abs(q) + abs(r);
603 if (m == l) {
break; }
604 if (abs(H(m, m - 1)) * (abs(q) + abs(r)) <
605 eps * (abs(p) * (abs(H(m - 1, m - 1)) + abs(z) +
606 abs(H(m + 1, m + 1))))) {
612 for (
int i = m + 2; i <= n; i++) {
614 if (i > m + 2) { H(i, i - 3) = 0.0; }
619 for (
int k = m; k <= n - 1; k++) {
620 int notlast = (k != n - 1);
624 r = (notlast ? H(k + 2, k - 1) : 0.0);
625 x = abs(p) + abs(q) + abs(r);
632 if (x == 0.0) {
break; }
633 s = sqrt(p * p + q * q + r * r);
634 if (p < 0) { s = -s; }
637 H(k, k - 1) = -s * x;
639 H(k, k - 1) = -H(k, k - 1);
650 for (
int j = k; j < nn; j++) {
651 p = H(k, j) + q * H(k + 1, j);
653 p = p + r * H(k + 2, j);
654 H(k + 2, j) = H(k + 2, j) - p * z;
656 H(k, j) = H(k, j) - p * x;
657 H(k + 1, j) = H(k + 1, j) - p * y;
662 for (
int i = 0; i <= min(n, k + 3); i++) {
663 p = x * H(i, k) + y * H(i, k + 1);
665 p = p + z * H(i, k + 2);
666 H(i, k + 2) = H(i, k + 2) - p * r;
668 H(i, k) = H(i, k) - p;
669 H(i, k + 1) = H(i, k + 1) - p * q;
674 for (
int i = low; i <= high; i++) {
675 p = x * V(i, k) + y * V(i, k + 1);
677 p = p + z * V(i, k + 2);
678 V(i, k + 2) = V(i, k + 2) - p * r;
680 V(i, k) = V(i, k) - p;
681 V(i, k + 1) = V(i, k + 1) - p * q;
690 if (norm == 0.0) {
return; }
692 for (n = nn - 1; n >= 0; n--) {
701 for (
int i = n - 1; i >= 0; i--) {
704 for (
int j = l; j <= n; j++) {
705 r = r + H(i, j) * H(j, n);
716 H(i, n) = -r / (eps * norm);
724 q = (d(i) - p) * (d(i) - p) + e(i) * e(i);
725 t = (x * s - z * r) / q;
727 if (abs(x) > abs(z)) {
728 H(i + 1, n) = (-r - w * t) / x;
730 H(i + 1, n) = (-s - y * t) / z;
737 if ((eps * t) * t > 1) {
738 for (
int j = i; j <= n; j++) {
739 H(j, n) = H(j, n) / t;
752 if (abs(H(n, n - 1)) > abs(H(n - 1, n))) {
753 H(n - 1, n - 1) = q / H(n, n - 1);
754 H(n - 1, n) = -(H(n, n) - p) / H(n, n - 1);
756 cdiv(0.0, -H(n - 1, n), H(n - 1, n - 1) - p, q);
757 H(n - 1, n - 1) = cdivr;
762 for (
int i = n - 2; i >= 0; i--) {
766 for (
int j = l; j <= n; j++) {
767 ra = ra + H(i, j) * H(j, n - 1);
768 sa = sa + H(i, j) * H(j, n);
779 cdiv(-ra, -sa, w, q);
787 vr = (d(i) - p) * (d(i) - p) + e(i) * e(i) - q * q;
788 vi = (d(i) - p) * 2.0 * q;
789 if ((vr == 0.0) && (vi == 0.0)) {
791 eps * norm * (abs(w) + abs(q) + abs(x) + abs(y) + abs(z));
793 cdiv(x * r - z * ra + q * sa, x * s - z * sa - q * ra, vr, vi);
796 if (abs(x) > (abs(z) + abs(q))) {
797 H(i + 1, n - 1) = (-ra - w * H(i, n - 1) + q * H(i, n)) / x;
798 H(i + 1, n) = (-sa - w * H(i, n) - q * H(i, n - 1)) / x;
800 cdiv(-r - y * H(i, n - 1), -s - y * H(i, n), z, q);
801 H(i + 1, n - 1) = cdivr;
808 t = max(abs(H(i, n - 1)), abs(H(i, n)));
809 if ((eps * t) * t > 1) {
810 for (
int j = i; j <= n; j++) {
811 H(j, n - 1) = H(j, n - 1) / t;
812 H(j, n) = H(j, n) / t;
822 for (
int i = 0; i < nn; i++) {
823 if (i < low || i > high) {
824 for (
int j = i; j < nn; j++) {
832 for (
int j = nn - 1; j >= low; j--) {
833 for (
int i = low; i <= high; i++) {
835 for (
int k = low; k <= min(j, high); k++) {
836 z = z + V(i, k) * H(k, j);
854 for (
int j = 0; (j < n) && issymmetric; j++) {
855 for (
int i = 0; (i < n) && issymmetric; i++) {
856 issymmetric = (A(i, j) == A(j, i));
861 for (
int i = 0; i < n; i++) {
862 for (
int j = 0; j < n; j++) {
877 for (
int j = 0; j < n; j++) {
878 for (
int i = 0; i < n; i++) {
903 d_.reserve(d.size());
953 for (
int i = 0; i < n; i++) {
954 for (
int j = 0; j < n; j++) {
960 }
else if (e(i) < 0) {