OpenLibm/slatec/tql1.f
Viral B. Shah c977aa998f Add Makefile.extras to build libopenlibm-extras.
Replace amos with slatec
2012-12-31 16:37:05 -05:00

167 lines
5 KiB
Fortran

*DECK TQL1
SUBROUTINE TQL1 (N, D, E, IERR)
C***BEGIN PROLOGUE TQL1
C***PURPOSE Compute the eigenvalues of symmetric tridiagonal matrix by
C the QL method.
C***LIBRARY SLATEC (EISPACK)
C***CATEGORY D4A5, D4C2A
C***TYPE SINGLE PRECISION (TQL1-S)
C***KEYWORDS EIGENVALUES OF A SYMMETRIC TRIDIAGONAL MATRIX, EISPACK,
C QL METHOD
C***AUTHOR Smith, B. T., et al.
C***DESCRIPTION
C
C This subroutine is a translation of the ALGOL procedure TQL1,
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 of a SYMMETRIC
C TRIDIAGONAL matrix by the QL method.
C
C On Input
C
C N is the order of the matrix. N is an INTEGER variable.
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 On Output
C
C D contains the eigenvalues in ascending order. If an
C error exit is made, the eigenvalues are correct and
C ordered for indices 1, 2, ..., IERR-1, but may not be
C the smallest eigenvalues.
C
C E has been destroyed.
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***END PROLOGUE TQL1
C
INTEGER I,J,L,M,N,II,L1,L2,MML,IERR
REAL D(*),E(*)
REAL B,C,C2,C3,DL1,EL1,F,G,H,P,R,S,S2
REAL PYTHAG
C
C***FIRST EXECUTABLE STATEMENT TQL1
IERR = 0
IF (N .EQ. 1) GO TO 1001
C
DO 100 I = 2, N
100 E(I-1) = E(I)
C
F = 0.0E0
B = 0.0E0
E(N) = 0.0E0
C
DO 290 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 210
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.0E0 * E(L))
R = PYTHAG(P,1.0E0)
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.0E0
C2 = C
EL1 = E(L1)
S = 0.0E0
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.0E0)
E(I+1) = S * P * R
S = C / R
C = 1.0E0 / R
GO TO 160
150 C = P / E(I)
R = SQRT(C*C+1.0E0)
E(I+1) = S * E(I) * R
S = 1.0E0 / R
C = C * S
160 P = C * D(I) - S * G
D(I+1) = H + S * (C * G + S * D(I))
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
210 P = D(L) + F
C .......... ORDER EIGENVALUES ..........
IF (L .EQ. 1) GO TO 250
C .......... FOR I=L STEP -1 UNTIL 2 DO -- ..........
DO 230 II = 2, L
I = L + 2 - II
IF (P .GE. D(I-1)) GO TO 270
D(I) = D(I-1)
230 CONTINUE
C
250 I = 1
270 D(I) = P
290 CONTINUE
C
GO TO 1001
C .......... SET ERROR -- NO CONVERGENCE TO AN
C EIGENVALUE AFTER 30 ITERATIONS ..........
1000 IERR = L
1001 RETURN
END