tred3.f 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. *DECK TRED3
  2. SUBROUTINE TRED3 (N, NV, A, D, E, E2)
  3. C***BEGIN PROLOGUE TRED3
  4. C***PURPOSE Reduce a real symmetric matrix stored in packed form to
  5. C symmetric tridiagonal matrix using orthogonal
  6. C transformations.
  7. C***LIBRARY SLATEC (EISPACK)
  8. C***CATEGORY D4C1B1
  9. C***TYPE SINGLE PRECISION (TRED3-S)
  10. C***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
  11. C***AUTHOR Smith, B. T., et al.
  12. C***DESCRIPTION
  13. C
  14. C This subroutine is a translation of the ALGOL procedure TRED3,
  15. C NUM. MATH. 11, 181-195(1968) by Martin, Reinsch, and Wilkinson.
  16. C HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 212-226(1971).
  17. C
  18. C This subroutine reduces a REAL SYMMETRIC matrix, stored as
  19. C a one-dimensional array, to a symmetric tridiagonal matrix
  20. C using orthogonal similarity transformations.
  21. C
  22. C On Input
  23. C
  24. C N is the order of the matrix A. N is an INTEGER variable.
  25. C
  26. C NV is an INTEGER variable set equal to the dimension of the
  27. C array A as specified in the calling program. NV must not
  28. C be less than N*(N+1)/2.
  29. C
  30. C A contains the lower triangle, stored row-wise, of the real
  31. C symmetric packed matrix. A is a one-dimensional REAL
  32. C array, dimensioned A(NV).
  33. C
  34. C On Output
  35. C
  36. C A contains information about the orthogonal transformations
  37. C used in the reduction in its first N*(N+1)/2 positions.
  38. C
  39. C D contains the diagonal elements of the symmetric tridiagonal
  40. C matrix. D is a one-dimensional REAL array, dimensioned D(N).
  41. C
  42. C E contains the subdiagonal elements of the symmetric
  43. C tridiagonal matrix in its last N-1 positions. E(1) is set
  44. C to zero. E is a one-dimensional REAL array, dimensioned
  45. C E(N).
  46. C
  47. C E2 contains the squares of the corresponding elements of E.
  48. C E2 may coincide with E if the squares are not needed.
  49. C E2 is a one-dimensional REAL array, dimensioned E2(N).
  50. C
  51. C Questions and comments should be directed to B. S. Garbow,
  52. C APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
  53. C ------------------------------------------------------------------
  54. C
  55. C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
  56. C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
  57. C system Routines - EISPACK Guide, Springer-Verlag,
  58. C 1976.
  59. C***ROUTINES CALLED (NONE)
  60. C***REVISION HISTORY (YYMMDD)
  61. C 760101 DATE WRITTEN
  62. C 890831 Modified array declarations. (WRB)
  63. C 890831 REVISION DATE from Version 3.2
  64. C 891214 Prologue converted to Version 4.0 format. (BAB)
  65. C 920501 Reformatted the REFERENCES section. (WRB)
  66. C***END PROLOGUE TRED3
  67. C
  68. INTEGER I,J,K,L,N,II,IZ,JK,NV
  69. REAL A(*),D(*),E(*),E2(*)
  70. REAL F,G,H,HH,SCALE
  71. C
  72. C .......... FOR I=N STEP -1 UNTIL 1 DO -- ..........
  73. C***FIRST EXECUTABLE STATEMENT TRED3
  74. DO 300 II = 1, N
  75. I = N + 1 - II
  76. L = I - 1
  77. IZ = (I * L) / 2
  78. H = 0.0E0
  79. SCALE = 0.0E0
  80. IF (L .LT. 1) GO TO 130
  81. C .......... SCALE ROW (ALGOL TOL THEN NOT NEEDED) ..........
  82. DO 120 K = 1, L
  83. IZ = IZ + 1
  84. D(K) = A(IZ)
  85. SCALE = SCALE + ABS(D(K))
  86. 120 CONTINUE
  87. C
  88. IF (SCALE .NE. 0.0E0) GO TO 140
  89. 130 E(I) = 0.0E0
  90. E2(I) = 0.0E0
  91. GO TO 290
  92. C
  93. 140 DO 150 K = 1, L
  94. D(K) = D(K) / SCALE
  95. H = H + D(K) * D(K)
  96. 150 CONTINUE
  97. C
  98. E2(I) = SCALE * SCALE * H
  99. F = D(L)
  100. G = -SIGN(SQRT(H),F)
  101. E(I) = SCALE * G
  102. H = H - F * G
  103. D(L) = F - G
  104. A(IZ) = SCALE * D(L)
  105. IF (L .EQ. 1) GO TO 290
  106. F = 0.0E0
  107. C
  108. DO 240 J = 1, L
  109. G = 0.0E0
  110. JK = (J * (J-1)) / 2
  111. C .......... FORM ELEMENT OF A*U ..........
  112. DO 180 K = 1, L
  113. JK = JK + 1
  114. IF (K .GT. J) JK = JK + K - 2
  115. G = G + A(JK) * D(K)
  116. 180 CONTINUE
  117. C .......... FORM ELEMENT OF P ..........
  118. E(J) = G / H
  119. F = F + E(J) * D(J)
  120. 240 CONTINUE
  121. C
  122. HH = F / (H + H)
  123. JK = 0
  124. C .......... FORM REDUCED A ..........
  125. DO 260 J = 1, L
  126. F = D(J)
  127. G = E(J) - HH * F
  128. E(J) = G
  129. C
  130. DO 260 K = 1, J
  131. JK = JK + 1
  132. A(JK) = A(JK) - F * E(K) - G * D(K)
  133. 260 CONTINUE
  134. C
  135. 290 D(I) = A(IZ+1)
  136. A(IZ+1) = SCALE * SQRT(H)
  137. 300 CONTINUE
  138. C
  139. RETURN
  140. END