Télécharger b3_jac.eso

Retour à la liste

Numérotation des lignes :

b3_jac
  1. C B3_JAC SOURCE PV090527 23/01/27 21:15:07 11574
  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 b3_jac(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. * .. Arguments ..
  37. * implicit none
  38. real*8 A(3,3),W(3),Q(3,3)
  39. real*8 B(3,3)
  40. * .. Parameters ..
  41. integer N
  42. parameter (N=3)
  43. * .. Local Variables ..
  44. real*8 SD, SO
  45. real*8 S, C, T
  46. real*8 G, H, Z, THETA
  47. real*8 THRESH
  48. integer I, X, Y, R
  49. * determinant
  50. real*8 det
  51.  
  52. * on verifie que le determinant ne soit pas nul
  53. det = a(1,1) * a(2,2) * a(3,3) - a(1,1) * a(2,3) * a(3,2) - a(1,2)
  54. # * a(2,1) * a(3,3) + a(1,2) * a(2,3) * a(3,1) + a(1,3) * a(2,1) *
  55. #a(3,2) - a(1,3) * a(2,2) * a(3,1)
  56. c print*,'Dans b3_jac det=',det
  57. if(det.eq.0.d0) then
  58. c on ne calcul pas, on assigne
  59. do i=1,3
  60. W(i)=0.d0
  61. do j=1,3
  62. if(i.eq.j) then
  63. Q(j,i)=1.d0
  64. else
  65. Q(i,j)=0.d0
  66. end if
  67. end do
  68. end do
  69. return
  70. end if
  71.  
  72.  
  73. * Initialize Q to the identitity matrix
  74. * --- This loop can be omitted if only the eigenvalues are desired -
  75. * A=B
  76. do x=1,n
  77. do y=1,n
  78. b(x,y)=a(x,y)
  79. end do
  80. end do
  81. DO 10 X = 1, N
  82. Q(X,X) = 1.0D0
  83. DO 11, Y = 1, X-1
  84. Q(X, Y) = 0.0D0
  85. Q(Y, X) = 0.0D0
  86. 11 CONTINUE
  87. 10 CONTINUE
  88.  
  89. * Initialize W to diag(A)
  90. DO 20 X = 1, N
  91. W(X) = A(X, X)
  92. 20 CONTINUE
  93.  
  94. * Calculate SQR(tr(A))
  95. SD = 0.0D0
  96. DO 30 X = 1, N
  97. SD = SD + ABS(W(X))
  98. 30 CONTINUE
  99. SD = SD**2
  100.  
  101. * Main iteration loop
  102. DO 40 I = 1, 50
  103. * Test for convergence
  104. SO = 0.0D0
  105. DO 50 X = 1, N
  106. DO 51 Y = X+1, N
  107. SO = SO + ABS(A(X, Y))
  108. 51 CONTINUE
  109. 50 CONTINUE
  110. IF (SO .EQ. 0.0D0) THEN
  111. c print*,'convergence jacobi en ',I,' iterations'
  112. RETURN
  113. END IF
  114.  
  115. IF (I .LT. 4) THEN
  116. THRESH = 0.2D0 * SO / N**2
  117. ELSE
  118. THRESH = 0.0D0
  119. END IF
  120.  
  121. * Do sweep
  122. DO 60 X = 1, N
  123. DO 61 Y = X+1, N
  124. G = 100.0D0 * ( ABS(A(X, Y)) )
  125. IF ( I .GT. 4 .AND. (ABS(W(X)) + G) .EQ. ABS(W(X))
  126. & .AND. ABS(W(Y)) + G .EQ. ABS(W(Y)) ) THEN
  127. A(X, Y) = 0.0D0
  128. ELSE IF (ABS(A(X, Y)) .GT. THRESH) THEN
  129. * Calculate Jacobi transformation
  130. H = W(Y) - W(X)
  131. IF ( ABS(H) + G .EQ. ABS(H) ) THEN
  132. T = A(X, Y) / H
  133. ELSE
  134. THETA = 0.5D0 * H / A(X, Y)
  135. IF (THETA .LT. 0.0D0) THEN
  136. T = -1.0D0 / (SQRT(1.0D0 + THETA**2) - THETA)
  137. ELSE
  138. T = 1.0D0 / (SQRT(1.0D0 + THETA**2) + THETA)
  139. END IF
  140. END IF
  141.  
  142. C = 1.0D0 / SQRT( 1.0D0 + T**2 )
  143. S = T * C
  144. Z = T * A(X, Y)
  145.  
  146. * Apply Jacobi transformation
  147. A(X, Y) = 0.0D0
  148. W(X) = W(X) - Z
  149. W(Y) = W(Y) + Z
  150. DO 70 R = 1, X-1
  151. T = A(R, X)
  152. A(R, X) = C * T - S * A(R, Y)
  153. A(R, Y) = S * T + C * A(R, Y)
  154. 70 CONTINUE
  155. DO 80, R = X+1, Y-1
  156. T = A(X, R)
  157. A(X, R) = C * T - S * A(R, Y)
  158. A(R, Y) = S * T + C * A(R, Y)
  159. 80 CONTINUE
  160. DO 90, R = Y+1, N
  161. T = A(X, R)
  162. A(X, R) = C * T - S * A(Y, R)
  163. A(Y, R) = S * T + C * A(Y, R)
  164. 90 CONTINUE
  165.  
  166. * Update eigenvectors
  167. * --- This loop can be omitted if only the eigenvalues are desired ---
  168. DO 100, R = 1, N
  169. T = Q(R, X)
  170. Q(R, X) = C * T - S * Q(R, Y)
  171. Q(R, Y) = S * T + C * Q(R, Y)
  172. 100 CONTINUE
  173. END IF
  174. 61 CONTINUE
  175. 60 CONTINUE
  176. 40 CONTINUE
  177.  
  178. PRINT *, "B3_JAC: No convergence."
  179. print*,'A'
  180. call afic33(B)
  181. print*,'W'
  182. do i=1,3
  183. print*,W(i)
  184. end do
  185. print*,'Q'
  186. call afic33(Q)
  187. return
  188. END
  189. * End of subroutine DSYEVJ3
  190.  
  191.  
  192.  

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