1 /* eigen.f -- translated by f2c (version of 19 December 1990 16:50:21).
8 #define doublereal double
9 #define Min(x,y) ((x) > (y) ? (y) : (x))
10 #define Max(x,y) ((x) > (y) ? (x) : (y))
11 #define Abs(x) ((x) >= 0 ? (x) : -(x))
13 static /* Subroutine */ int tred2(), tql2();
14 static doublereal
pythag(), d_sign();
16 /* Table of constant values */
18 static doublereal c_b39
= 1.;
20 /* Subroutine */ int eigen(nm
, n
, a
, w
, z
, fv1
, ierr
)
22 doublereal
*a
, *w
, *z
, *fv1
;
25 /* System generated locals */
26 integer a_dim1
, a_offset
, z_dim1
, z_offset
;
28 /* THIS SUBROUTINE CALLS THE RECOMMENDED SEQUENCE OF */
29 /* SUBROUTINES FROM THE EIGENSYSTEM SUBROUTINE PACKAGE (EISPACK) */
30 /* TO FIND THE EIGENVALUES AND EIGENVECTORS */
31 /* OF A REAL SYMMETRIC MATRIX. */
35 /* NM MUST BE SET TO THE ROW DIMENSION OF THE TWO-DIMENSIONAL */
36 /* ARRAY PARAMETERS AS DECLARED IN THE CALLING PROGRAM */
37 /* DIMENSION STATEMENT. */
39 /* N IS THE ORDER OF THE MATRIX A. */
41 /* A CONTAINS THE REAL SYMMETRIC MATRIX. */
45 /* W CONTAINS THE EIGENVALUES IN ASCENDING ORDER. */
47 /* Z CONTAINS THE EIGENVECTORS IF MATZ IS NOT ZERO. */
49 /* IERR IS AN INTEGER OUTPUT VARIABLE SET EQUAL TO AN ERROR */
50 /* COMPLETION CODE DESCRIBED IN THE DOCUMENTATION FOR TQLRAT */
51 /* AND TQL2. THE NORMAL COMPLETION CODE IS ZERO. */
53 /* FV1 IS A TEMPORARY STORAGE ARRAY. */
55 /* ------------------------------------------------------------------
58 /* Parameter adjustments */
61 z_offset
= z_dim1
+ 1;
65 a_offset
= a_dim1
+ 1;
74 /* .......... FIND BOTH EIGENVALUES AND EIGENVECTORS .......... */
76 tred2(nm
, n
, &a
[a_offset
], &w
[1], &fv1
[1], &z
[z_offset
]);
77 tql2(nm
, n
, &w
[1], &fv1
[1], &z
[z_offset
], ierr
);
82 static /* Subroutine */ int tred2(nm
, n
, a
, d
, e
, z
)
84 doublereal
*a
, *d
, *e
, *z
;
86 /* System generated locals */
87 integer a_dim1
, a_offset
, z_dim1
, z_offset
, i__1
, i__2
, i__3
;
91 static doublereal f
, g
, h
;
92 static integer i
, j
, k
, l
;
93 static doublereal scale
, hh
;
94 static integer ii
, jp1
;
98 /* THIS SUBROUTINE IS A TRANSLATION OF THE ALGOL PROCEDURE TRED2, */
99 /* NUM. MATH. 11, 181-195(1968) BY MARTIN, REINSCH, AND WILKINSON. */
100 /* HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 212-226(1971). */
102 /* THIS SUBROUTINE REDUCES A REAL SYMMETRIC MATRIX TO A */
103 /* SYMMETRIC TRIDIAGONAL MATRIX USING AND ACCUMULATING */
104 /* ORTHOGONAL SIMILARITY TRANSFORMATIONS. */
108 /* NM MUST BE SET TO THE ROW DIMENSION OF TWO-DIMENSIONAL */
109 /* ARRAY PARAMETERS AS DECLARED IN THE CALLING PROGRAM */
110 /* DIMENSION STATEMENT. */
112 /* N IS THE ORDER OF THE MATRIX. */
114 /* A CONTAINS THE REAL SYMMETRIC INPUT MATRIX. ONLY THE */
115 /* LOWER TRIANGLE OF THE MATRIX NEED BE SUPPLIED. */
119 /* D CONTAINS THE DIAGONAL ELEMENTS OF THE TRIDIAGONAL MATRIX. */
121 /* E CONTAINS THE SUBDIAGONAL ELEMENTS OF THE TRIDIAGONAL */
122 /* MATRIX IN ITS LAST N-1 POSITIONS. E(1) IS SET TO ZERO. */
124 /* Z CONTAINS THE ORTHOGONAL TRANSFORMATION MATRIX */
125 /* PRODUCED IN THE REDUCTION. */
127 /* A AND Z MAY COINCIDE. IF DISTINCT, A IS UNALTERED. */
129 /* QUESTIONS AND COMMENTS SHOULD BE DIRECTED TO BURTON S. GARBOW, */
130 /* MATHEMATICS AND COMPUTER SCIENCE DIV, ARGONNE NATIONAL LABORATORY
133 /* THIS VERSION DATED AUGUST 1983. */
135 /* ------------------------------------------------------------------
138 /* Parameter adjustments */
140 z_offset
= z_dim1
+ 1;
145 a_offset
= a_dim1
+ 1;
150 for (i
= 1; i
<= i__1
; ++i
) {
153 for (j
= i
; j
<= i__2
; ++j
) {
155 z
[j
+ i
* z_dim1
] = a
[j
+ i
* a_dim1
];
158 d
[i
] = a
[*n
+ i
* a_dim1
];
165 /* .......... FOR I=N STEP -1 UNTIL 2 DO -- .......... */
167 for (ii
= 2; ii
<= i__1
; ++ii
) {
175 /* .......... SCALE ROW (ALGOL TOL THEN NOT NEEDED) .......... */
177 for (k
= 1; k
<= i__2
; ++k
) {
179 scale
+= (d__1
= d
[k
], Abs(d__1
));
189 for (j
= 1; j
<= i__2
; ++j
) {
190 d
[j
] = z
[l
+ j
* z_dim1
];
191 z
[i
+ j
* z_dim1
] = 0.;
192 z
[j
+ i
* z_dim1
] = 0.;
200 for (k
= 1; k
<= i__2
; ++k
) {
208 g
= -d_sign(&d__1
, &f
);
212 /* .......... FORM A*U .......... */
214 for (j
= 1; j
<= i__2
; ++j
) {
220 for (j
= 1; j
<= i__2
; ++j
) {
222 z
[j
+ i
* z_dim1
] = f
;
223 g
= e
[j
] + z
[j
+ j
* z_dim1
] * f
;
230 for (k
= jp1
; k
<= i__3
; ++k
) {
231 g
+= z
[k
+ j
* z_dim1
] * d
[k
];
232 e
[k
] += z
[k
+ j
* z_dim1
] * f
;
240 /* .......... FORM P .......... */
244 for (j
= 1; j
<= i__2
; ++j
) {
251 /* .......... FORM Q .......... */
253 for (j
= 1; j
<= i__2
; ++j
) {
257 /* .......... FORM REDUCED A .......... */
259 for (j
= 1; j
<= i__2
; ++j
) {
264 for (k
= j
; k
<= i__3
; ++k
) {
266 z
[k
+ j
* z_dim1
] = z
[k
+ j
* z_dim1
] - f
* e
[k
] - g
* d
[k
];
269 d
[j
] = z
[l
+ j
* z_dim1
];
270 z
[i
+ j
* z_dim1
] = 0.;
278 /* .......... ACCUMULATION OF TRANSFORMATION MATRICES .......... */
280 for (i
= 2; i
<= i__1
; ++i
) {
282 z
[*n
+ l
* z_dim1
] = z
[l
+ l
* z_dim1
];
283 z
[l
+ l
* z_dim1
] = 1.;
290 for (k
= 1; k
<= i__2
; ++k
) {
292 d
[k
] = z
[k
+ i
* z_dim1
] / h
;
296 for (j
= 1; j
<= i__2
; ++j
) {
300 for (k
= 1; k
<= i__3
; ++k
) {
302 g
+= z
[k
+ i
* z_dim1
] * z
[k
+ j
* z_dim1
];
306 for (k
= 1; k
<= i__3
; ++k
) {
307 z
[k
+ j
* z_dim1
] -= g
* d
[k
];
314 for (k
= 1; k
<= i__3
; ++k
) {
316 z
[k
+ i
* z_dim1
] = 0.;
324 for (i
= 1; i
<= i__1
; ++i
) {
325 d
[i
] = z
[*n
+ i
* z_dim1
];
326 z
[*n
+ i
* z_dim1
] = 0.;
330 z
[*n
+ *n
* z_dim1
] = 1.;
335 static /* Subroutine */ int tql2(nm
, n
, d
, e
, z
, ierr
)
337 doublereal
*d
, *e
, *z
;
340 /* System generated locals */
341 integer z_dim1
, z_offset
, i__1
, i__2
, i__3
;
342 doublereal d__1
, d__2
;
344 /* Local variables */
345 static doublereal c
, f
, g
, h
;
346 static integer i
, j
, k
, l
, m
;
347 static doublereal p
, r
, s
, c2
, c3
;
348 static integer l1
, l2
;
349 static doublereal s2
;
351 static doublereal dl1
, el1
;
353 static doublereal tst1
, tst2
;
357 /* THIS SUBROUTINE IS A TRANSLATION OF THE ALGOL PROCEDURE TQL2, */
358 /* NUM. MATH. 11, 293-306(1968) BY BOWDLER, MARTIN, REINSCH, AND */
360 /* HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 227-240(1971). */
362 /* THIS SUBROUTINE FINDS THE EIGENVALUES AND EIGENVECTORS */
363 /* OF A SYMMETRIC TRIDIAGONAL MATRIX BY THE QL METHOD. */
364 /* THE EIGENVECTORS OF A FULL SYMMETRIC MATRIX CAN ALSO */
365 /* BE FOUND IF TRED2 HAS BEEN USED TO REDUCE THIS */
366 /* FULL MATRIX TO TRIDIAGONAL FORM. */
370 /* NM MUST BE SET TO THE ROW DIMENSION OF TWO-DIMENSIONAL */
371 /* ARRAY PARAMETERS AS DECLARED IN THE CALLING PROGRAM */
372 /* DIMENSION STATEMENT. */
374 /* N IS THE ORDER OF THE MATRIX. */
376 /* D CONTAINS THE DIAGONAL ELEMENTS OF THE INPUT MATRIX. */
378 /* E CONTAINS THE SUBDIAGONAL ELEMENTS OF THE INPUT MATRIX */
379 /* IN ITS LAST N-1 POSITIONS. E(1) IS ARBITRARY. */
381 /* Z CONTAINS THE TRANSFORMATION MATRIX PRODUCED IN THE */
382 /* REDUCTION BY TRED2, IF PERFORMED. IF THE EIGENVECTORS */
383 /* OF THE TRIDIAGONAL MATRIX ARE DESIRED, Z MUST CONTAIN */
384 /* THE IDENTITY MATRIX. */
388 /* D CONTAINS THE EIGENVALUES IN ASCENDING ORDER. IF AN */
389 /* ERROR EXIT IS MADE, THE EIGENVALUES ARE CORRECT BUT */
390 /* UNORDERED FOR INDICES 1,2,...,IERR-1. */
392 /* E HAS BEEN DESTROYED. */
394 /* Z CONTAINS ORTHONORMAL EIGENVECTORS OF THE SYMMETRIC */
395 /* TRIDIAGONAL (OR FULL) MATRIX. IF AN ERROR EXIT IS MADE, */
396 /* Z CONTAINS THE EIGENVECTORS ASSOCIATED WITH THE STORED */
400 /* ZERO FOR NORMAL RETURN, */
401 /* J IF THE J-TH EIGENVALUE HAS NOT BEEN */
402 /* DETERMINED AFTER 30 ITERATIONS. */
404 /* CALLS PYTHAG FOR DSQRT(A*A + B*B) . */
406 /* QUESTIONS AND COMMENTS SHOULD BE DIRECTED TO BURTON S. GARBOW, */
407 /* MATHEMATICS AND COMPUTER SCIENCE DIV, ARGONNE NATIONAL LABORATORY
410 /* THIS VERSION DATED AUGUST 1983. */
412 /* ------------------------------------------------------------------
415 /* Parameter adjustments */
417 z_offset
= z_dim1
+ 1;
429 for (i
= 2; i
<= i__1
; ++i
) {
439 for (l
= 1; l
<= i__1
; ++l
) {
441 h
= (d__1
= d
[l
], Abs(d__1
)) + (d__2
= e
[l
], Abs(d__2
));
445 /* .......... LOOK FOR SMALL SUB-DIAGONAL ELEMENT .......... */
447 for (m
= l
; m
<= i__2
; ++m
) {
448 tst2
= tst1
+ (d__1
= e
[m
], Abs(d__1
));
452 /* .......... E(N) IS ALWAYS ZERO, SO THERE IS NO EXIT */
453 /* THROUGH THE BOTTOM OF THE LOOP .......... */
466 /* .......... FORM SHIFT .......... */
470 p
= (d
[l1
] - g
) / (e
[l
] * 2.);
471 r
= pythag(&p
, &c_b39
);
472 d
[l
] = e
[l
] / (p
+ d_sign(&r
, &p
));
473 d
[l1
] = e
[l
] * (p
+ d_sign(&r
, &p
));
481 for (i
= l2
; i
<= i__2
; ++i
) {
488 /* .......... QL TRANSFORMATION .......... */
495 /* .......... FOR I=M-1 STEP -1 UNTIL L DO -- .......... */
497 for (ii
= 1; ii
<= i__2
; ++ii
) {
504 r
= pythag(&p
, &e
[i
]);
508 p
= c
* d
[i
] - s
* g
;
509 d
[i
+ 1] = h
+ s
* (c
* g
+ s
* d
[i
]);
510 /* .......... FORM VECTOR .......... */
512 for (k
= 1; k
<= i__3
; ++k
) {
513 h
= z
[k
+ (i
+ 1) * z_dim1
];
514 z
[k
+ (i
+ 1) * z_dim1
] = s
* z
[k
+ i
* z_dim1
] + c
* h
;
515 z
[k
+ i
* z_dim1
] = c
* z
[k
+ i
* z_dim1
] - s
* h
;
522 p
= -s
* s2
* c3
* el1
* e
[l
] / dl1
;
525 tst2
= tst1
+ (d__1
= e
[l
], Abs(d__1
));
533 /* .......... ORDER EIGENVALUES AND EIGENVECTORS .......... */
535 for (ii
= 2; ii
<= i__1
; ++ii
) {
541 for (j
= ii
; j
<= i__2
; ++j
) {
558 for (j
= 1; j
<= i__2
; ++j
) {
559 p
= z
[j
+ i
* z_dim1
];
560 z
[j
+ i
* z_dim1
] = z
[j
+ k
* z_dim1
];
561 z
[j
+ k
* z_dim1
] = p
;
570 /* .......... SET ERROR -- NO CONVERGENCE TO AN */
571 /* EIGENVALUE AFTER 30 ITERATIONS .......... */
578 static doublereal
pythag(a
, b
)
581 /* System generated locals */
582 doublereal ret_val
, d__1
, d__2
, d__3
;
584 /* Local variables */
585 static doublereal p
, r
, s
, t
, u
;
588 /* FINDS DSQRT(A**2+B**2) WITHOUT OVERFLOW OR DESTRUCTIVE UNDERFLOW */
592 d__1
= Abs(*a
), d__2
= Abs(*b
);
598 d__2
= Abs(*a
), d__3
= Abs(*b
);
599 /* Computing 2nd power */
600 d__1
= Min(d__2
,d__3
) / p
;
610 /* Computing 2nd power */
619 static double d_sign(a
,b
)
623 x
= (*a
>= 0 ? *a
: - *a
);
624 return( *b
>= 0 ? x
: -x
);