PLaSK library
Loading...
Searching...
No Matches
jama_eig.h
Go to the documentation of this file.
1#ifndef JAMA_EIG_H
2#define JAMA_EIG_H
3
4
5#include "../tnt/tnt_array1d.h"
6#include "../tnt/tnt_array2d.h"
7#include "../tnt/tnt_math_utils.h"
8
9#include <algorithm>
10// for min(), max() below
11
12#include <cmath>
13// for abs() below
14#if(defined(_MSC_VER) && _MSC_VER < 1600)
15#define abs fabs
16#endif
17
18using namespace TNT;
19//using namespace std;
20
21namespace JAMA
22{
23
74template <class Real>
76{
77
78
80 int n;
81
82 int issymmetric; /* boolean*/
83
86 TNT::Array1D<Real> d; /* real part */
87 TNT::Array1D<Real> e; /* img part */
88
91
96
97
102
103
104 // Symmetric Householder reduction to tridiagonal form.
105
106 void tred2() {
107
108 // This is derived from the Algol procedures tred2 by
109 // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
110 // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
111 // Fortran subroutine in EISPACK.
112
113 for (int j = 0; j < n; j++) {
114 d[j] = V[n-1][j];
115 }
116
117 // Householder reduction to tridiagonal form.
118
119 for (int i = n-1; i > 0; i--) {
120
121 // Scale to avoid under/overflow.
122
123 Real scale = 0.0;
124 Real h = 0.0;
125 for (int k = 0; k < i; k++) {
126 scale = scale + abs(d[k]);
127 }
128 if (scale == 0.0) {
129 e[i] = d[i-1];
130 for (int j = 0; j < i; j++) {
131 d[j] = V[i-1][j];
132 V[i][j] = 0.0;
133 V[j][i] = 0.0;
134 }
135 } else {
136
137 // Generate Householder vector.
138
139 for (int k = 0; k < i; k++) {
140 d[k] /= scale;
141 h += d[k] * d[k];
142 }
143 Real f = d[i-1];
144 Real g = sqrt(h);
145 if (f > 0) {
146 g = -g;
147 }
148 e[i] = scale * g;
149 h = h - f * g;
150 d[i-1] = f - g;
151 for (int j = 0; j < i; j++) {
152 e[j] = 0.0;
153 }
154
155 // Apply similarity transformation to remaining columns.
156
157 for (int j = 0; j < i; j++) {
158 f = d[j];
159 V[j][i] = f;
160 g = e[j] + V[j][j] * f;
161 for (int k = j+1; k <= i-1; k++) {
162 g += V[k][j] * d[k];
163 e[k] += V[k][j] * f;
164 }
165 e[j] = g;
166 }
167 f = 0.0;
168 for (int j = 0; j < i; j++) {
169 e[j] /= h;
170 f += e[j] * d[j];
171 }
172 Real hh = f / (h + h);
173 for (int j = 0; j < i; j++) {
174 e[j] -= hh * d[j];
175 }
176 for (int j = 0; j < i; j++) {
177 f = d[j];
178 g = e[j];
179 for (int k = j; k <= i-1; k++) {
180 V[k][j] -= (f * e[k] + g * d[k]);
181 }
182 d[j] = V[i-1][j];
183 V[i][j] = 0.0;
184 }
185 }
186 d[i] = h;
187 }
188
189 // Accumulate transformations.
190
191 for (int i = 0; i < n-1; i++) {
192 V[n-1][i] = V[i][i];
193 V[i][i] = 1.0;
194 Real h = d[i+1];
195 if (h != 0.0) {
196 for (int k = 0; k <= i; k++) {
197 d[k] = V[k][i+1] / h;
198 }
199 for (int j = 0; j <= i; j++) {
200 Real g = 0.0;
201 for (int k = 0; k <= i; k++) {
202 g += V[k][i+1] * V[k][j];
203 }
204 for (int k = 0; k <= i; k++) {
205 V[k][j] -= g * d[k];
206 }
207 }
208 }
209 for (int k = 0; k <= i; k++) {
210 V[k][i+1] = 0.0;
211 }
212 }
213 for (int j = 0; j < n; j++) {
214 d[j] = V[n-1][j];
215 V[n-1][j] = 0.0;
216 }
217 V[n-1][n-1] = 1.0;
218 e[0] = 0.0;
219 }
220
221 // Symmetric tridiagonal QL algorithm.
222
223 void tql2 () {
224
225 // This is derived from the Algol procedures tql2, by
226 // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
227 // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
228 // Fortran subroutine in EISPACK.
229
230 for (int i = 1; i < n; i++) {
231 e[i-1] = e[i];
232 }
233 e[n-1] = 0.0;
234
235 Real f = 0.0;
236 Real tst1 = 0.0;
237 Real eps = pow(2.0,-52.0);
238 for (int l = 0; l < n; l++) {
239
240 // Find small subdiagonal element
241
242 tst1 = std::max(tst1,abs(d[l]) + abs(e[l]));
243 int m = l;
244
245 // Original while-loop from Java code
246 while (m < n) {
247 if (abs(e[m]) <= eps*tst1) {
248 break;
249 }
250 m++;
251 }
252
253
254 // If m == l, d[l] is an eigenvalue,
255 // otherwise, iterate.
256
257 if (m > l) {
258 int iter = 0;
259 do {
260 iter = iter + 1; // (Could check iteration count here.)
261
262 // Compute implicit shift
263
264 Real g = d[l];
265 Real p = (d[l+1] - g) / (2.0 * e[l]);
266 Real r = hypot(p,1.0);
267 if (p < 0) {
268 r = -r;
269 }
270 d[l] = e[l] / (p + r);
271 d[l+1] = e[l] * (p + r);
272 Real dl1 = d[l+1];
273 Real h = g - d[l];
274 for (int i = l+2; i < n; i++) {
275 d[i] -= h;
276 }
277 f = f + h;
278
279 // Implicit QL transformation.
280
281 p = d[m];
282 Real c = 1.0;
283 Real c2 = c;
284 Real c3 = c;
285 Real el1 = e[l+1];
286 Real s = 0.0;
287 Real s2 = 0.0;
288 for (int i = m-1; i >= l; i--) {
289 c3 = c2;
290 c2 = c;
291 s2 = s;
292 g = c * e[i];
293 h = c * p;
294 r = hypot(p,e[i]);
295 e[i+1] = s * r;
296 s = e[i] / r;
297 c = p / r;
298 p = c * d[i] - s * g;
299 d[i+1] = h + s * (c * g + s * d[i]);
300
301 // Accumulate transformation.
302
303 for (int k = 0; k < n; k++) {
304 h = V[k][i+1];
305 V[k][i+1] = s * V[k][i] + c * h;
306 V[k][i] = c * V[k][i] - s * h;
307 }
308 }
309 p = -s * s2 * c3 * el1 * e[l] / dl1;
310 e[l] = s * p;
311 d[l] = c * p;
312
313 // Check for convergence.
314
315 } while (abs(e[l]) > eps*tst1);
316 }
317 d[l] = d[l] + f;
318 e[l] = 0.0;
319 }
320
321 // Sort eigenvalues and corresponding vectors.
322
323 for (int i = 0; i < n-1; i++) {
324 int k = i;
325 Real p = d[i];
326 for (int j = i+1; j < n; j++) {
327 if (d[j] < p) {
328 k = j;
329 p = d[j];
330 }
331 }
332 if (k != i) {
333 d[k] = d[i];
334 d[i] = p;
335 for (int j = 0; j < n; j++) {
336 p = V[j][i];
337 V[j][i] = V[j][k];
338 V[j][k] = p;
339 }
340 }
341 }
342 }
343
344 // Nonsymmetric reduction to Hessenberg form.
345
346 void orthes () {
347
348 // This is derived from the Algol procedures orthes and ortran,
349 // by Martin and Wilkinson, Handbook for Auto. Comp.,
350 // Vol.ii-Linear Algebra, and the corresponding
351 // Fortran subroutines in EISPACK.
352
353 int low = 0;
354 int high = n-1;
355
356 for (int m = low+1; m <= high-1; m++) {
357
358 // Scale column.
359
360 Real scale = 0.0;
361 for (int i = m; i <= high; i++) {
362 scale = scale + abs(H[i][m-1]);
363 }
364 if (scale != 0.0) {
365
366 // Compute Householder transformation.
367
368 Real h = 0.0;
369 for (int i = high; i >= m; i--) {
370 ort[i] = H[i][m-1]/scale;
371 h += ort[i] * ort[i];
372 }
373 Real g = sqrt(h);
374 if (ort[m] > 0) {
375 g = -g;
376 }
377 h = h - ort[m] * g;
378 ort[m] = ort[m] - g;
379
380 // Apply Householder similarity transformation
381 // H = (I-u*u'/h)*H*(I-u*u')/h)
382
383 for (int j = m; j < n; j++) {
384 Real f = 0.0;
385 for (int i = high; i >= m; i--) {
386 f += ort[i]*H[i][j];
387 }
388 f = f/h;
389 for (int i = m; i <= high; i++) {
390 H[i][j] -= f*ort[i];
391 }
392 }
393
394 for (int i = 0; i <= high; i++) {
395 Real f = 0.0;
396 for (int j = high; j >= m; j--) {
397 f += ort[j]*H[i][j];
398 }
399 f = f/h;
400 for (int j = m; j <= high; j++) {
401 H[i][j] -= f*ort[j];
402 }
403 }
404 ort[m] = scale*ort[m];
405 H[m][m-1] = scale*g;
406 }
407 }
408
409 // Accumulate transformations (Algol's ortran).
410
411 for (int i = 0; i < n; i++) {
412 for (int j = 0; j < n; j++) {
413 V[i][j] = (i == j ? 1.0 : 0.0);
414 }
415 }
416
417 for (int m = high-1; m >= low+1; m--) {
418 if (H[m][m-1] != 0.0) {
419 for (int i = m+1; i <= high; i++) {
420 ort[i] = H[i][m-1];
421 }
422 for (int j = m; j <= high; j++) {
423 Real g = 0.0;
424 for (int i = m; i <= high; i++) {
425 g += ort[i] * V[i][j];
426 }
427 // Double division avoids possible underflow
428 g = (g / ort[m]) / H[m][m-1];
429 for (int i = m; i <= high; i++) {
430 V[i][j] += g * ort[i];
431 }
432 }
433 }
434 }
435 }
436
437
438 // Complex scalar division.
439
440 Real cdivr, cdivi;
441 void cdiv(Real xr, Real xi, Real yr, Real yi) {
442 Real r,d;
443 if (abs(yr) > abs(yi)) {
444 r = yi/yr;
445 d = yr + r*yi;
446 cdivr = (xr + r*xi)/d;
447 cdivi = (xi - r*xr)/d;
448 } else {
449 r = yr/yi;
450 d = yi + r*yr;
451 cdivr = (r*xr + xi)/d;
452 cdivi = (r*xi - xr)/d;
453 }
454 }
455
456
457 // Nonsymmetric reduction from Hessenberg to real Schur form.
458
459 void hqr2 () {
460
461 // This is derived from the Algol procedure hqr2,
462 // by Martin and Wilkinson, Handbook for Auto. Comp.,
463 // Vol.ii-Linear Algebra, and the corresponding
464 // Fortran subroutine in EISPACK.
465
466 // Initialize
467
468 int nn = this->n;
469 int n = nn-1;
470 int low = 0;
471 int high = nn-1;
472 Real eps = pow(2.0,-52.0);
473 Real exshift = 0.0;
474 Real p=0,q=0,r=0,s=0,z=0,t,w,x,y;
475
476 // Store roots isolated by balanc and compute matrix norm
477
478 Real norm = 0.0;
479 for (int i = 0; i < nn; i++) {
480 if ((i < low) || (i > high)) {
481 d[i] = H[i][i];
482 e[i] = 0.0;
483 }
484 for (int j = std::max(i-1,0); j < nn; j++) {
485 norm = norm + abs(H[i][j]);
486 }
487 }
488
489 // Outer loop over eigenvalue index
490
491 int iter = 0;
492 while (n >= low) {
493
494 // Look for single small sub-diagonal element
495
496 int l = n;
497 while (l > low) {
498 s = abs(H[l-1][l-1]) + abs(H[l][l]);
499 if (s == 0.0) {
500 s = norm;
501 }
502 if (abs(H[l][l-1]) < eps * s) {
503 break;
504 }
505 l--;
506 }
507
508 // Check for convergence
509 // One root found
510
511 if (l == n) {
512 H[n][n] = H[n][n] + exshift;
513 d[n] = H[n][n];
514 e[n] = 0.0;
515 n--;
516 iter = 0;
517
518 // Two roots found
519
520 } else if (l == n-1) {
521 w = H[n][n-1] * H[n-1][n];
522 p = (H[n-1][n-1] - H[n][n]) / 2.0;
523 q = p * p + w;
524 z = sqrt(abs(q));
525 H[n][n] = H[n][n] + exshift;
526 H[n-1][n-1] = H[n-1][n-1] + exshift;
527 x = H[n][n];
528
529 // Real pair
530
531 if (q >= 0) {
532 if (p >= 0) {
533 z = p + z;
534 } else {
535 z = p - z;
536 }
537 d[n-1] = x + z;
538 d[n] = d[n-1];
539 if (z != 0.0) {
540 d[n] = x - w / z;
541 }
542 e[n-1] = 0.0;
543 e[n] = 0.0;
544 x = H[n][n-1];
545 s = abs(x) + abs(z);
546 p = x / s;
547 q = z / s;
548 r = sqrt(p * p+q * q);
549 p = p / r;
550 q = q / r;
551
552 // Row modification
553
554 for (int j = n-1; j < nn; j++) {
555 z = H[n-1][j];
556 H[n-1][j] = q * z + p * H[n][j];
557 H[n][j] = q * H[n][j] - p * z;
558 }
559
560 // Column modification
561
562 for (int i = 0; i <= n; i++) {
563 z = H[i][n-1];
564 H[i][n-1] = q * z + p * H[i][n];
565 H[i][n] = q * H[i][n] - p * z;
566 }
567
568 // Accumulate transformations
569
570 for (int i = low; i <= high; i++) {
571 z = V[i][n-1];
572 V[i][n-1] = q * z + p * V[i][n];
573 V[i][n] = q * V[i][n] - p * z;
574 }
575
576 // Complex pair
577
578 } else {
579 d[n-1] = x + p;
580 d[n] = x + p;
581 e[n-1] = z;
582 e[n] = -z;
583 }
584 n = n - 2;
585 iter = 0;
586
587 // No convergence yet
588
589 } else {
590
591 // Form shift
592
593 x = H[n][n];
594 y = 0.0;
595 w = 0.0;
596 if (l < n) {
597 y = H[n-1][n-1];
598 w = H[n][n-1] * H[n-1][n];
599 }
600
601 // Wilkinson's original ad hoc shift
602
603 if (iter == 10) {
604 exshift += x;
605 for (int i = low; i <= n; i++) {
606 H[i][i] -= x;
607 }
608 s = abs(H[n][n-1]) + abs(H[n-1][n-2]);
609 x = y = 0.75 * s;
610 w = -0.4375 * s * s;
611 }
612
613 // MATLAB's new ad hoc shift
614
615 if (iter == 30) {
616 s = (y - x) / 2.0;
617 s = s * s + w;
618 if (s > 0) {
619 s = sqrt(s);
620 if (y < x) {
621 s = -s;
622 }
623 s = x - w / ((y - x) / 2.0 + s);
624 for (int i = low; i <= n; i++) {
625 H[i][i] -= s;
626 }
627 exshift += s;
628 x = y = w = 0.964;
629 }
630 }
631
632 iter = iter + 1; // (Could check iteration count here.)
633
634 // Look for two consecutive small sub-diagonal elements
635
636 int m = n-2;
637 while (m >= l) {
638 z = H[m][m];
639 r = x - z;
640 s = y - z;
641 p = (r * s - w) / H[m+1][m] + H[m][m+1];
642 q = H[m+1][m+1] - z - r - s;
643 r = H[m+2][m+1];
644 s = abs(p) + abs(q) + abs(r);
645 p = p / s;
646 q = q / s;
647 r = r / s;
648 if (m == l) {
649 break;
650 }
651 if (abs(H[m][m-1]) * (abs(q) + abs(r)) <
652 eps * (abs(p) * (abs(H[m-1][m-1]) + abs(z) +
653 abs(H[m+1][m+1])))) {
654 break;
655 }
656 m--;
657 }
658
659 for (int i = m+2; i <= n; i++) {
660 H[i][i-2] = 0.0;
661 if (i > m+2) {
662 H[i][i-3] = 0.0;
663 }
664 }
665
666 // Double QR step involving rows l:n and columns m:n
667
668 for (int k = m; k <= n-1; k++) {
669 int notlast = (k != n-1);
670 if (k != m) {
671 p = H[k][k-1];
672 q = H[k+1][k-1];
673 r = (notlast ? H[k+2][k-1] : 0.0);
674 x = abs(p) + abs(q) + abs(r);
675 if (x != 0.0) {
676 p = p / x;
677 q = q / x;
678 r = r / x;
679 }
680 }
681 if (x == 0.0) {
682 break;
683 }
684 s = sqrt(p * p + q * q + r * r);
685 if (p < 0) {
686 s = -s;
687 }
688 if (s != 0) {
689 if (k != m) {
690 H[k][k-1] = -s * x;
691 } else if (l != m) {
692 H[k][k-1] = -H[k][k-1];
693 }
694 p = p + s;
695 x = p / s;
696 y = q / s;
697 z = r / s;
698 q = q / p;
699 r = r / p;
700
701 // Row modification
702
703 for (int j = k; j < nn; j++) {
704 p = H[k][j] + q * H[k+1][j];
705 if (notlast) {
706 p = p + r * H[k+2][j];
707 H[k+2][j] = H[k+2][j] - p * z;
708 }
709 H[k][j] = H[k][j] - p * x;
710 H[k+1][j] = H[k+1][j] - p * y;
711 }
712
713 // Column modification
714
715 for (int i = 0; i <= std::min(n,k+3); i++) {
716 p = x * H[i][k] + y * H[i][k+1];
717 if (notlast) {
718 p = p + z * H[i][k+2];
719 H[i][k+2] = H[i][k+2] - p * r;
720 }
721 H[i][k] = H[i][k] - p;
722 H[i][k+1] = H[i][k+1] - p * q;
723 }
724
725 // Accumulate transformations
726
727 for (int i = low; i <= high; i++) {
728 p = x * V[i][k] + y * V[i][k+1];
729 if (notlast) {
730 p = p + z * V[i][k+2];
731 V[i][k+2] = V[i][k+2] - p * r;
732 }
733 V[i][k] = V[i][k] - p;
734 V[i][k+1] = V[i][k+1] - p * q;
735 }
736 } // (s != 0)
737 } // k loop
738 } // check convergence
739 } // while (n >= low)
740
741 // Backsubstitute to find vectors of upper triangular form
742
743 if (norm == 0.0) {
744 return;
745 }
746
747 for (n = nn-1; n >= 0; n--) {
748 p = d[n];
749 q = e[n];
750
751 // Real vector
752
753 if (q == 0) {
754 int l = n;
755 H[n][n] = 1.0;
756 for (int i = n-1; i >= 0; i--) {
757 w = H[i][i] - p;
758 r = 0.0;
759 for (int j = l; j <= n; j++) {
760 r = r + H[i][j] * H[j][n];
761 }
762 if (e[i] < 0.0) {
763 z = w;
764 s = r;
765 } else {
766 l = i;
767 if (e[i] == 0.0) {
768 if (w != 0.0) {
769 H[i][n] = -r / w;
770 } else {
771 H[i][n] = -r / (eps * norm);
772 }
773
774 // Solve real equations
775
776 } else {
777 x = H[i][i+1];
778 y = H[i+1][i];
779 q = (d[i] - p) * (d[i] - p) + e[i] * e[i];
780 t = (x * s - z * r) / q;
781 H[i][n] = t;
782 if (abs(x) > abs(z)) {
783 H[i+1][n] = (-r - w * t) / x;
784 } else {
785 H[i+1][n] = (-s - y * t) / z;
786 }
787 }
788
789 // Overflow control
790
791 t = abs(H[i][n]);
792 if ((eps * t) * t > 1) {
793 for (int j = i; j <= n; j++) {
794 H[j][n] = H[j][n] / t;
795 }
796 }
797 }
798 }
799
800 // Complex vector
801
802 } else if (q < 0) {
803 int l = n-1;
804
805 // Last vector component imaginary so matrix is triangular
806
807 if (abs(H[n][n-1]) > abs(H[n-1][n])) {
808 H[n-1][n-1] = q / H[n][n-1];
809 H[n-1][n] = -(H[n][n] - p) / H[n][n-1];
810 } else {
811 cdiv(0.0,-H[n-1][n],H[n-1][n-1]-p,q);
812 H[n-1][n-1] = cdivr;
813 H[n-1][n] = cdivi;
814 }
815 H[n][n-1] = 0.0;
816 H[n][n] = 1.0;
817 for (int i = n-2; i >= 0; i--) {
818 Real ra,sa,vr,vi;
819 ra = 0.0;
820 sa = 0.0;
821 for (int j = l; j <= n; j++) {
822 ra = ra + H[i][j] * H[j][n-1];
823 sa = sa + H[i][j] * H[j][n];
824 }
825 w = H[i][i] - p;
826
827 if (e[i] < 0.0) {
828 z = w;
829 r = ra;
830 s = sa;
831 } else {
832 l = i;
833 if (e[i] == 0) {
834 cdiv(-ra,-sa,w,q);
835 H[i][n-1] = cdivr;
836 H[i][n] = cdivi;
837 } else {
838
839 // Solve complex equations
840
841 x = H[i][i+1];
842 y = H[i+1][i];
843 vr = (d[i] - p) * (d[i] - p) + e[i] * e[i] - q * q;
844 vi = (d[i] - p) * 2.0 * q;
845 if ((vr == 0.0) && (vi == 0.0)) {
846 vr = eps * norm * (abs(w) + abs(q) +
847 abs(x) + abs(y) + abs(z));
848 }
849 cdiv(x*r-z*ra+q*sa,x*s-z*sa-q*ra,vr,vi);
850 H[i][n-1] = cdivr;
851 H[i][n] = cdivi;
852 if (abs(x) > (abs(z) + abs(q))) {
853 H[i+1][n-1] = (-ra - w * H[i][n-1] + q * H[i][n]) / x;
854 H[i+1][n] = (-sa - w * H[i][n] - q * H[i][n-1]) / x;
855 } else {
856 cdiv(-r-y*H[i][n-1],-s-y*H[i][n],z,q);
857 H[i+1][n-1] = cdivr;
858 H[i+1][n] = cdivi;
859 }
860 }
861
862 // Overflow control
863
864 t = std::max(abs(H[i][n-1]),abs(H[i][n]));
865 if ((eps * t) * t > 1) {
866 for (int j = i; j <= n; j++) {
867 H[j][n-1] = H[j][n-1] / t;
868 H[j][n] = H[j][n] / t;
869 }
870 }
871 }
872 }
873 }
874 }
875
876 // Vectors of isolated roots
877
878 for (int i = 0; i < nn; i++) {
879 if (i < low || i > high) {
880 for (int j = i; j < nn; j++) {
881 V[i][j] = H[i][j];
882 }
883 }
884 }
885
886 // Back transformation to get eigenvectors of original matrix
887
888 for (int j = nn-1; j >= low; j--) {
889 for (int i = low; i <= high; i++) {
890 z = 0.0;
891 for (int k = low; k <= std::min(j,high); k++) {
892 z = z + V[i][k] * H[k][j];
893 }
894 V[i][j] = z;
895 }
896 }
897 }
898
899public:
900
901
907 n = A.dim2();
908 V = Array2D<Real>(n,n);
909 d = Array1D<Real>(n);
910 e = Array1D<Real>(n);
911
912 issymmetric = 1;
913 for (int j = 0; (j < n) && issymmetric; j++) {
914 for (int i = 0; (i < n) && issymmetric; i++) {
915 issymmetric = (A[i][j] == A[j][i]);
916 }
917 }
918
919 if (issymmetric) {
920 for (int i = 0; i < n; i++) {
921 for (int j = 0; j < n; j++) {
922 V[i][j] = A[i][j];
923 }
924 }
925
926 // Tridiagonalize.
927 tred2();
928
929 // Diagonalize.
930 tql2();
931
932 } else {
934 ort = TNT::Array1D<Real>(n);
935
936 for (int j = 0; j < n; j++) {
937 for (int i = 0; i < n; i++) {
938 H[i][j] = A[i][j];
939 }
940 }
941
942 // Reduce to Hessenberg form.
943 orthes();
944
945 // Reduce Hessenberg to real Schur form.
946 hqr2();
947 }
948 }
949
950
956 V_ = V;
957 return;
958 }
959
965 d_ = d;
966 return ;
967 }
968
975 e_ = e;
976 return;
977 }
978
979
1014 D = Array2D<Real>(n,n);
1015 for (int i = 0; i < n; i++) {
1016 for (int j = 0; j < n; j++) {
1017 D[i][j] = 0.0;
1018 }
1019 D[i][i] = d[i];
1020 if (e[i] > 0) {
1021 D[i][i+1] = e[i];
1022 } else if (e[i] < 0) {
1023 D[i][i-1] = e[i];
1024 }
1025 }
1026 }
1027};
1028
1029} //namespace JAMA
1030
1031
1032#endif
1033// JAMA_EIG_H