Télécharger dsyevj3.eso

Retour à la liste

Numérotation des lignes :

dsyevj3
  1. C DSYEVJ3 SOURCE PV090527 24/01/19 21:15:04 11827
  2. * ----------------------------------------------------------------------------
  3. * Numerical diagonalization of 3x3 matrcies
  4. * Copyright (C) 2006 Joachim Kopp
  5. * ----------------------------------------------------------------------------
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. * ----------------------------------------------------------------------------
  20.  
  21.  
  22. * ----------------------------------------------------------------------------
  23. SUBROUTINE DSYEVJ3(A, Q, W)
  24. * ----------------------------------------------------------------------------
  25. * Calculates the eigenvalues and normalized eigenvectors of a symmetric 3x3
  26. * matrix A using the Jacobi algorithm.
  27. * The upper triangular part of A is destroyed during the calculation,
  28. * the diagonal elements are read but not destroyed, and the lower
  29. * triangular elements are not referenced at all.
  30. * ----------------------------------------------------------------------------
  31. * Parameters:
  32. * A: The symmetric input matrix
  33. * Q: Storage buffer for eigenvectors
  34. * W: Storage buffer for eigenvalues
  35. * ----------------------------------------------------------------------------
  36. -INC CCREEL
  37. * .. Arguments ..
  38. REAL*8 A(3,3)
  39. REAL*8 Q(3,3)
  40. REAL*8 W(3)
  41.  
  42. * .. Parameters ..
  43. INTEGER N
  44. PARAMETER ( N = 3 )
  45.  
  46. * .. Local Variables ..
  47. REAL*8 SD, SO
  48. REAL*8 S, C, T
  49. REAL*8 G, H, Z, THETA
  50. REAL*8 THRESH
  51. INTEGER I, X, Y, R
  52.  
  53. * Initialize Q to the identitity matrix
  54. * --- This loop can be omitted if only the eigenvalues are desired ---
  55. DO 10 X = 1, N
  56. Q(X,X) = 1.0D0
  57. DO 11, Y = 1, X-1
  58. Q(X, Y) = 0.0D0
  59. Q(Y, X) = 0.0D0
  60. 11 CONTINUE
  61. 10 CONTINUE
  62.  
  63. * Initialize W to diag(A)
  64. DO 20 X = 1, N
  65. W(X) = A(X, X)
  66. 20 CONTINUE
  67.  
  68. * Calculate SQR(tr(A))
  69. SD = 0.0D0
  70. DO 30 X = 1, N
  71. SD = SD + ABS(W(X))
  72. 30 CONTINUE
  73. SD = SD**2
  74.  
  75. * Main iteration loop
  76. DO 40 I = 1, 50
  77. * Test for convergence
  78. SO = 0.0D0
  79. DO 50 X = 1, N
  80. DO 51 Y = X+1, N
  81. SO = SO + ABS(A(X, Y))
  82. 51 CONTINUE
  83. 50 CONTINUE
  84. IF (SO .EQ. 0.0D0) THEN
  85. RETURN
  86. END IF
  87.  
  88. IF (I .LT. 4) THEN
  89. THRESH = 0.2D0 * SO / N**2
  90. ELSE
  91. THRESH = 0.0D0
  92. END IF
  93.  
  94. * Do sweep
  95. DO 60 X = 1, N
  96. DO 61 Y = X+1, N
  97. G = 100.0D0 * ( ABS(A(X, Y)) )
  98. IF ( I .GT. 4 .AND. ABS(W(X)) + G .EQ. ABS(W(X))
  99. $ .AND. ABS(W(Y)) + G .EQ. ABS(W(Y)) ) THEN
  100. A(X, Y) = 0.0D0
  101. ELSE IF (ABS(A(X, Y)) .GT. THRESH) THEN
  102. * Calculate Jacobi transformation
  103. H = W(Y) - W(X)
  104. IF ( ABS(H) + G .EQ. ABS(H) ) THEN
  105. T = A(X, Y) / H
  106. ELSE
  107. THETA = 0.5D0 * H / A(X, Y)
  108. IF (THETA .LT. 0.0D0) THEN
  109. T = -1.0D0 / (SQRT(1.0D0 + THETA**2) - THETA)
  110. ELSE
  111. T = 1.0D0 / (SQRT(1.0D0 + THETA**2) + THETA)
  112. END IF
  113. END IF
  114.  
  115. IF(ABS(T).lt.sqrt(xpetit/xzprec)) t=0.D0
  116. C = 1.0D0 / SQRT( 1.0D0 + T**2 )
  117. S = T * C
  118. Z = T * A(X, Y)
  119.  
  120. * Apply Jacobi transformation
  121. A(X, Y) = 0.0D0
  122. W(X) = W(X) - Z
  123. W(Y) = W(Y) + Z
  124. DO 70 R = 1, X-1
  125. T = A(R, X)
  126. A(R, X) = C * T - S * A(R, Y)
  127. A(R, Y) = S * T + C * A(R, Y)
  128. 70 CONTINUE
  129. DO 80, R = X+1, Y-1
  130. T = A(X, R)
  131. A(X, R) = C * T - S * A(R, Y)
  132. A(R, Y) = S * T + C * A(R, Y)
  133. 80 CONTINUE
  134. DO 90, R = Y+1, N
  135. T = A(X, R)
  136. A(X, R) = C * T - S * A(Y, R)
  137. A(Y, R) = S * T + C * A(Y, R)
  138. 90 CONTINUE
  139.  
  140. * Update eigenvectors
  141. * --- This loop can be omitted if only the eigenvalues are desired ---
  142. DO 100, R = 1, N
  143. T = Q(R, X)
  144. Q(R, X) = C * T - S * Q(R, Y)
  145. Q(R, Y) = S * T + C * Q(R, Y)
  146. 100 CONTINUE
  147. END IF
  148. 61 CONTINUE
  149. 60 CONTINUE
  150. 40 CONTINUE
  151.  
  152. PRINT *, "DSYEVJ3: No convergence."
  153.  
  154. END
  155. * End of subroutine DSYEVJ3
  156.  
  157.  
  158.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales