SUBROUTINE TRED2 (NM, N, A, D, E, Z) C***BEGIN PROLOGUE TRED2 C***PURPOSE Reduce a real symmetric matrix to a symmetric tridiagonal C matrix using and accumulating orthogonal transformations. C***LIBRARY SLATEC (EISPACK) C***CATEGORY D4C1B1 C***TYPE DOUBLE PRECISION (TRED2-D) C***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK C***AUTHOR Smith, B. T., et al. C***DESCRIPTION C C On Input C C NM must be set to the row dimension of the two-dimensional C array parameters, A and Z, as declared in the calling C program dimension statement. NM is an INTEGER variable. C C N is the order of the matrix A. N is an INTEGER variable. C N must be less than or equal to NM. C C A contains the real symmetric input matrix. Only the lower C triangle of the matrix need be supplied. A is a two- C dimensional REAL array, dimensioned A(NM,N). C C On Output C C D contains the diagonal elements of the symmetric tridiagonal C matrix. D is a one-dimensional REAL array, dimensioned D(N). C C E contains the subdiagonal elements of the symmetric C tridiagonal matrix in its last N-1 positions. E(1) is set C to zero. E is a one-dimensional REAL array, dimensioned C E(N). C C Z contains the orthogonal transformation matrix produced in C the reduction. Z is a two-dimensional REAL array, C dimensioned Z(NM,N). C C A and Z may coincide. If distinct, A is unaltered. C C Questions and comments should be directed to B. S. Garbow, C APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY C ------------------------------------------------------------------ C C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow, C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen- C system Routines - EISPACK Guide, Springer-Verlag, C 1976. C***ROUTINES CALLED (NONE) C***REVISION HISTORY (YYMMDD) cC 760101 DATE WRITTEN C 890831 Modified array declarations. (WRB) C 890831 REVISION DATE from Version 3.2 C 891214 Prologue converted to Version 4.0 format. (BAB) C 920501 Reformatted the REFERENCES section. (WRB) C 971023 Converted to double precision. (REK) C***END PROLOGUE TRED2 C INTEGER I, + J, + K, + L, + N, + II, + NM, + JP1 C C REAL A(NM,*),D(*),E(*),Z(NM,*) C REAL F,G,H,HH,SCALE DOUBLE PRECISION A(NM,N), + D(N), + E(N), + Z(NM,N) DOUBLE PRECISION F, + G, + H, + HH, + SCALE C C***FIRST EXECUTABLE STATEMENT TRED2 DO 100 I = 1, N C DO 100 J = 1, I Z(I,J) = A(I,J) 100 CONTINUE C IF (N .EQ. 1) GO TO 320 C .......... FOR I=N STEP -1 UNTIL 2 DO -- .......... DO 300 II = 2, N I = N + 2 - II L = I - 1 H = 0.0D0 SCALE = 0.0D0 IF (L .LT. 2) GO TO 130 C .......... SCALE ROW (ALGOL TOL THEN NOT NEEDED) .......... DO 120 K = 1, L 120 SCALE = SCALE + ABS(Z(I,K)) C IF (SCALE .NE. 0.0D0) GO TO 140 130 E(I) = Z(I,L) GO TO 290 C 140 DO 150 K = 1, L Z(I,K) = Z(I,K) / SCALE H = H + Z(I,K) * Z(I,K) 150 CONTINUE C F = Z(I,L) G = -SIGN(SQRT(H),F) E(I) = SCALE * G H = H - F * G Z(I,L) = F - G F = 0.0D0 C DO 240 J = 1, L Z(J,I) = Z(I,J) / H G = 0.0D0 C .......... FORM ELEMENT OF A*U .......... DO 180 K = 1, J 180 G = G + Z(J,K) * Z(I,K) C JP1 = J + 1 IF (L .LT. JP1) GO TO 220 C DO 200 K = JP1, L 200 G = G + Z(K,J) * Z(I,K) C .......... FORM ELEMENT OF P .......... 220 E(J) = G / H F = F + E(J) * Z(I,J) 240 CONTINUE C HH = F / (H + H) C .......... FORM REDUCED A .......... DO 260 J = 1, L F = Z(I,J) G = E(J) - HH * F E(J) = G C DO 260 K = 1, J Z(J,K) = Z(J,K) - F * E(K) - G * Z(I,K) 260 CONTINUE C 290 D(I) = H 300 CONTINUE C 320 D(1) = 0.0D0 E(1) = 0.0D0 C .......... ACCUMULATION OF TRANSFORMATION MATRICES .......... DO 500 I = 1, N L = I - 1 IF (D(I) .EQ. 0.0D0) GO TO 380 C DO 360 J = 1, L G = 0.0D0 C DO 340 K = 1, L 340 G = G + Z(I,K) * Z(K,J) C DO 360 K = 1, L Z(K,J) = Z(K,J) - G * Z(K,I) 360 CONTINUE C 380 D(I) = Z(I,I) Z(I,I) = 1.0D0 IF (L .LT. 1) GO TO 500 C DO 400 J = 1, L Z(I,J) = 0.0D0 Z(J,I) = 0.0D0 400 CONTINUE C 500 CONTINUE C RETURN END SUBROUTINE TQL2 (NM, N, D, E, Z, IERR) C***BEGIN PROLOGUE TQL2 C***PURPOSE Compute the eigenvalues and eigenvectors of symmetric C tridiagonal matrix. C***LIBRARY SLATEC (EISPACK) C***CATEGORY D4A5, D4C2A C***TYPE DOUBLE PRECISION (TQL2-D) C***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK C***AUTHOR Smith, B. T., et al. C***DESCRIPTION C C This subroutine is a translation of the ALGOL procedure TQL2, C NUM. MATH. 11, 293-306(1968) by Bowdler, Martin, Reinsch, and C Wilkinson. C HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 227-240(1971). C C This subroutine finds the eigenvalues and eigenvectors C of a SYMMETRIC TRIDIAGONAL matrix by the QL method. C The eigenvectors of a FULL SYMMETRIC matrix can also C be found if TRED2 has been used to reduce this C full matrix to tridiagonal form. C C On Input C C C NM must be set to the row dimension of the two-dimensional C array parameter, Z, as declared in the calling program C dimension statement. NM is an INTEGER variable. C C N is the order of the matrix. N is an INTEGER variable. C N must be less than or equal to NM. C C D contains the diagonal elements of the symmetric tridiagonal C matrix. D is a one-dimensional REAL array, dimensioned D(N). C C E contains the subdiagonal elements of the symmetric C tridiagonal matrix in its last N-1 positions. E(1) is C arbitrary. E is a one-dimensional REAL array, dimensioned C E(N). C C Z contains the transformation matrix produced in the C reduction by TRED2, if performed. If the eigenvectors C of the tridiagonal matrix are desired, Z must contain C the identity matrix. Z is a two-dimensional REAL array, C dimensioned Z(NM,N). C C On Output C C D contains the eigenvalues in ascending order. If an C error exit is made, the eigenvalues are correct but C unordered for indices 1, 2, ..., IERR-1. C C E has been destroyed. C C Z contains orthonormal eigenvectors of the symmetric C tridiagonal (or full) matrix. If an error exit is made, C Z contains the eigenvectors associated with the stored C eigenvalues. C C IERR is an INTEGER flag set to C Zero for normal return, C J if the J-th eigenvalue has not been C determined after 30 iterations. C C Calls PYTHAG(A,B) for sqrt(A**2 + B**2). C C Questions and comments should be directed to B. S. Garbow, C APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY C ------------------------------------------------------------------ C C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow, C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen- C system Routines - EISPACK Guide, Springer-Verlag, C 1976. C***ROUTINES CALLED PYTHAG C***REVISION HISTORY (YYMMDD) C 760101 DATE WRITTEN C 890831 Modified array declarations. (WRB) C 890831 REVISION DATE from Version 3.2 C 891214 Prologue converted to Version 4.0 format. (BAB) C 920501 Reformatted the REFERENCES section. (WRB) C 971023 Converted to double precision. (REK) C***END PROLOGUE TQL2 C INTEGER I, + J, + K, + L, + M, + N, + II, + L1, + L2, + NM, + MML, + IERR CC REAL D(*),E(*),Z(NM,*) DOUBLE PRECISION D(N), + E(N), + Z(NM,N) DOUBLE PRECISION B, + C, + C2, + C3, + DL1, + EL1, + F, + G, + H, + P, + R, + S, + S2 DOUBLE PRECISION PYTHAG C C***FIRST EXECUTABLE STATEMENT TQL2 IERR = 0 IF (N .EQ. 1) GO TO 1001 C DO 100 I = 2, N 100 E(I-1) = E(I) C F = 0.0D0 B = 0.0D0 E(N) = 0.0D0 C DO 240 L = 1, N J = 0 H = ABS(D(L)) + ABS(E(L)) IF (B .LT. H) B = H C .......... LOOK FOR SMALL SUB-DIAGONAL ELEMENT .......... DO 110 M = L, N IF (B + ABS(E(M)) .EQ. B) GO TO 120 C .......... E(N) IS ALWAYS ZERO, SO THERE IS NO EXIT C THROUGH THE BOTTOM OF THE LOOP .......... 110 CONTINUE C 120 IF (M .EQ. L) GO TO 220 130 IF (J .EQ. 30) GO TO 1000 J = J + 1 C .......... FORM SHIFT .......... L1 = L + 1 L2 = L1 + 1 G = D(L) P = (D(L1) - G) / (2.0D0 * E(L)) R = PYTHAG(P,1.0D0) D(L) = E(L) / (P + SIGN(R,P)) D(L1) = E(L) * (P + SIGN(R,P)) DL1 = D(L1) H = G - D(L) IF (L2 .GT. N) GO TO 145 C DO 140 I = L2, N 140 D(I) = D(I) - H C 145 F = F + H C .......... QL TRANSFORMATION .......... P = D(M) C = 1.0D0 C2 = C EL1 = E(L1) S = 0.0D0 MML = M - L C .......... FOR I=M-1 STEP -1 UNTIL L DO -- .......... DO 200 II = 1, MML C3 = C2 C2 = C S2 = S I = M - II G = C * E(I) H = C * P IF (ABS(P) .LT. ABS(E(I))) GO TO 150 C = E(I) / P R = SQRT(C*C+1.0D0) E(I+1) = S * P * R S = C / R C = 1.0D0 / R GO TO 160 150 C = P / E(I) R = SQRT(C*C+1.0D0) E(I+1) = S * E(I) * R S = 1.0D0 / R C = C * S 160 P = C * D(I) - S * G D(I+1) = H + S * (C * G + S * D(I)) C .......... FORM VECTOR .......... DO 180 K = 1, N H = Z(K,I+1) Z(K,I+1) = S * Z(K,I) + C * H Z(K,I) = C * Z(K,I) - S * H 180 CONTINUE C 200 CONTINUE C P = -S * S2 * C3 * EL1 * E(L) / DL1 E(L) = S * P D(L) = C * P IF (B + ABS(E(L)) .GT. B) GO TO 130 220 D(L) = D(L) + F 240 CONTINUE CC .......... ORDER EIGENVALUES AND EIGENVECTORS .......... DO 300 II = 2, N I = II - 1 K = I P = D(I) C DO 260 J = II, N IF (D(J) .GE. P) GO TO 260 K = J P = D(J) 260 CONTINUE C IF (K .EQ. I) GO TO 300 D(K) = D(I) D(I) = P C DO 280 J = 1, N P = Z(J,I) Z(J,I) = Z(J,K) Z(J,K) = P 280 CONTINUE C 300 CONTINUE C GO TO 1001 C .......... SET ERROR -- NO CONVERGENCE TO AN C EIGENVALUE AFTER 30 ITERATIONS .......... 1000 IERR = L 1001 RETURN END DOUBLE PRECISION FUNCTION PYTHAG (A, B) C***BEGIN PROLOGUE PYTHAG C***SUBSIDIARY C***PURPOSE Compute the complex square root of a complex number without C destructive overflow or underflow. C***LIBRARY SLATEC C***TYPE SINGLE PRECISION (PYTHAG-S) C***AUTHOR (UNKNOWN) C***DESCRIPTION C C Finds sqrt(A**2+B**2) without overflow or destructive underflow C C***SEE ALSO EISDOC C***ROUTINES CALLED (NONE) C***REVISION HISTORY (YYMMDD) C 811101 DATE WRITTEN C 890531 Changed all specific intrinsics to generic. (WRB) C 891214 Prologue converted to Version 4.0 format. (BAB) C 900402 Added TYPE section. (WRB) C 971023 Converted to double precision. (REK) C***END PROLOGUE PYTHAG DOUBLE PRECISION A, + B C DOUBLE PRECISION P, + Q, + R, + S, + T C***FIRST EXECUTABLE STATEMENT PYTHAG P = MAX (ABS (A), ABS (B)) Q = MIN (ABS (A), ABS (B)) IF (Q .EQ. 0.0D0) GO TO 20 10 CONTINUE R = (Q / P)**2 T = 4.0D0 + R IF (T .EQ. 4.0D0) GO TO 20 S = R / T P = P + 2.0D0*P*S Q = Q * S GO TO 10 20 PYTHAG = P RETURN END