Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.79 KB | None | 0 0
  1. c program rede_cubica_2
  2.  
  3. implicit real*8 (a-h,o-z)
  4. Parameter(L=3, Nat=27, d1viz=1.1d0, V=1.0d0)
  5.  
  6. Real*8 d(Nat), e(Nat), a(Nat,Nat), r(3,Nat)
  7. external tqli, pythag, tred2
  8. Open(10,File='autovalores')
  9.  
  10. c Do i=1,Nat
  11. c Read(10,*) r(1,i), r(2,i), r(3,i)
  12. c Enddo
  13.  
  14. Size=DBLE(L)
  15. Iat=1
  16. Do i=1,L
  17. Do j=1,L
  18. Do k=1,L
  19. r(1,Iat)=DBLE(i-1)
  20. r(2,Iat)=DBLE(j-1)
  21. r(3,Iat)=DBLE(k-1)
  22. Iat=Iat+1
  23. Enddo
  24. Enddo
  25. Enddo
  26.  
  27. Do iat=1,Nat
  28. Print*,r(1,iat),r(2,iat), r(3,iat)
  29. Enddo
  30.  
  31.  
  32. Do iat=1,Nat
  33. Do jat=1,Nat
  34. a(iat,jat)=0.0d0
  35. Enddo
  36. Enddo
  37.  
  38. Do iat=1,Nat-1
  39. Do jat=iat+1,Nat
  40. dx=r(1,iat)-r(1,jat)
  41. dy=r(2,iat)-r(2,jat)
  42. dz=r(3,iat)-r(3,jat)
  43.  
  44. If(dx.gt.(Size/2)) dx=dx-Size
  45. If(dy.gt.(Size/2)) dy=dy-Size
  46. If(dz.gt.(Size/2)) dz=dz-Size
  47. If(dx.lt.(-Size/2)) dx=dx+Size
  48. If(dy.lt.(-Size/2)) dy=dy+Size
  49. If(dz.lt.(-Size/2)) dz=dz+Size
  50.  
  51. Dist=dsqrt(dx**2 + dy**2 + dz**2)
  52.  
  53. If(Dist.lt.d1viz)Then
  54. a(iat,jat)=V
  55. a(jat,iat)=V
  56. EndIf
  57. Enddo
  58. Enddo
  59.  
  60. Call tred2(a,Nat,Nat,d,e)
  61. Call tqli (d,e,Nat,Nat,a)
  62. Call ordena (d,a,Nat)
  63. do n=1,Nat
  64. Print*,d(n)
  65. Write(10,*)d(n)
  66. Enddo
  67.  
  68. stop
  69.  
  70. end
  71. c
  72. c --------------------------------------------------
  73. c
  74. SUBROUTINE tqli(d,e,n,Nat,a)
  75. c
  76. c d = na entrada, elementos diagonais;na saida, autovalores
  77. c e = na entrada, elementos fora da diagonal;
  78. c a = na entrada é a matriz identidade; saida, as colunas são os autovetores
  79. c
  80. INTEGER n,Nat
  81. REAL*8 d(Nat),e(Nat),a(Nat,Nat)
  82. INTEGER i,iter,k,l,m
  83. REAL*8 b,c,dd,f,g,p,r,s,pythag
  84.  
  85. external pythag
  86.  
  87. do 11 i=2,n
  88. e(i-1)=e(i)
  89. 11 continue
  90.  
  91. e(n)=0.d0
  92. do 15 l=1,n
  93. iter=0
  94.  
  95. 1 do 12 m=l,n-1
  96. dd = dabs(d(m))+ dabs(d(m+1))
  97. if ((dabs(e(m))+dd).eq.dd) goto 2
  98. 12 continue
  99.  
  100. m=n
  101. 2 if(m.ne.l)then
  102. if(iter.eq.30)pause 'too many iterations in tqli'
  103. iter=iter+1
  104. g=(d(l+1)-d(l))/(2.d0*e(l))
  105. r=pythag(g,1.d0)
  106. g=d(m)-d(l)+e(l)/(g+dsign(r,g))
  107. s=1.d0
  108. c=1.d0
  109. p=0.d0
  110.  
  111. do 14 i=m-1,l,-1
  112. f=s*e(i)
  113. b=c*e(i)
  114. r=pythag(f,g)
  115. e(i+1)=r
  116. if(r.eq.0.d0)then
  117. d(i+1)=d(i+1)-p
  118. e(m)=0.d0
  119. goto 1
  120. endif
  121. s=f/r
  122. c=g/r
  123. g=d(i+1)-p
  124. r=(d(i)-g)*s+2.d0*c*b
  125. p=s*r
  126. d(i+1)=g+p
  127. g=c*r-b
  128. C Omit lines from here ...
  129. C
  130. C do 13 k=1,n
  131. C f=z(k,i+1)
  132. C z(k,i+1)=s*z(k,i)+c*f
  133. C z(k,i)=c*z(k,i)-s*f
  134. C13 continue
  135. C
  136. C ... to here when finding only eigenvalues.
  137. 14 continue
  138.  
  139. d(l)=d(l)-p
  140. e(l)=g
  141. e(m)=0.d0
  142. goto 1
  143.  
  144. endif
  145. 15 continue
  146.  
  147. return
  148. END
  149. C
  150. c ------------------------------------------------------------
  151. c.
  152. FUNCTION pythag(a,b)
  153. REAL*8 a,b,pythag
  154. REAL*8 absa,absb
  155. absa=dabs(a)
  156. absb=dabs(b)
  157. if(absa.gt.absb)then
  158. pythag=absa*dsqrt(1.d0+(absb/absa)**2)
  159. else
  160. if(absb.eq.0.d0)then
  161. pythag=0.d0
  162. else
  163. pythag=absb*dsqrt(1.d0+(absa/absb)**2)
  164. endif
  165. endif
  166. return
  167. END
  168.  
  169. c ---------------------------------------------------------
  170.  
  171. SUBROUTINE tred2(a,n,Nat,d,e)
  172. C
  173. IMPLICIT NONE
  174. C------------Variables--------------------------------------
  175. C -- Input/output variables --
  176. INTEGER n, Nat
  177. REAL*8 a(Nat,Nat), d(Nat), e(Nat)
  178. C -- Local variables --
  179. INTEGER i,j,k,l
  180. REAL*8 f,g,h,hh,scale
  181. C------------Main-------------------------------------------
  182. C
  183. DO 18 i = n, 2, -1
  184. l = i - 1
  185. h = 0.D0
  186. scale = 0.D0
  187. IF(l.GT.1) THEN
  188. DO 11 k = 1, l
  189. scale = scale + DABS(a(i,k))
  190. 11 CONTINUE
  191. IF(scale.EQ.0.D0) THEN
  192. C (Skip transformation.)
  193. e(i)=a(i,l)
  194. ELSE
  195. DO 12 k = 1, l
  196. a(i,k) = a(i,k)/scale
  197. C (Use scaled a's for transformation.)
  198. h = h + a(i,k)**2
  199. C (Form sigma in h.)
  200. 12 CONTINUE
  201. f = a(i,l)
  202. g = - DSIGN( DSQRT(h), f )
  203. e(i) = scale*g
  204. h = h - f*g
  205. C (Now h is equation (11.2.4).)
  206. a(i,l) = f - g
  207. C (Store u in the i-th row of a.)
  208. f = 0.D0
  209. DO 15 j = 1, l
  210. C Omit following line if finding only eigenvalues.
  211. a(j,i) = a(i,j)/h
  212. C (Store u/H in i-th column of a.)
  213. g = 0.D0
  214. C (Form an element of A*u in g.)
  215. DO 13 k = 1, j
  216. g = g + a(j,k)*a(i,k)
  217. 13 CONTINUE
  218. DO 14 k = j+1, l
  219. g = g + a(k,j)*a(i,k)
  220. 14 CONTINUE
  221. e(j) = g/h
  222. C (Form element of p in temporarily
  223. C unused element of e.)
  224. f = f + e(j) * a(i,j)
  225. 15 CONTINUE
  226. hh = f/(h+h)
  227. C (Form K, equation (11.2.11).)
  228. DO 17 j = 1, l
  229. C (Form q and store in e overwriting p.)
  230. f = a(i,j)
  231. C (Note that e(l)=e(i-1) survives.)
  232. g = e(j) - hh*f
  233. e(j) = g
  234. DO 16 k = 1, j
  235. C (Reduce a, equation (11.2.13).)
  236. a(j,k) = a(j,k) - f*e(k) - g*a(i,k)
  237. 16 CONTINUE
  238. 17 CONTINUE
  239. ENDIF
  240. ELSE
  241. e(i) = a(i,l)
  242. ENDIF
  243. d(i) = h
  244. 18 CONTINUE
  245. C
  246. C Omit following line if finding only eigenvalues.
  247. d(1) = 0.D0
  248. e(1) = 0.D0
  249. C
  250. DO 24 i = 1, n
  251. C (Begin accumulation of transformation matrices.)
  252. C Delete lines from here ...
  253. l = i - 1
  254. IF(d(i).NE.0.D0) THEN
  255. C (This block skipped when i=1.)
  256. DO 22 j = 1, l
  257. g = 0.D0
  258. DO 19 k = 1, l
  259. C (Use u and u/H stored in a to form P*Q.)
  260. g = g + a(i,k)*a(k,j)
  261. 19 CONTINUE
  262. DO 21 k = 1, l
  263. a(k,j) = a(k,j) - g*a(k,i)
  264. 21 CONTINUE
  265. 22 CONTINUE
  266. ENDIF
  267. C ... to here when finding only eigenvalues.
  268. C
  269. d(i) = a(i,i)
  270. C (This statement remains.)
  271. C
  272. C Also delete lines from here ...
  273. C (Reset row and column of a to identity matrix
  274. C for next iteration)
  275. a(i,i) = 1.D0
  276. DO 23 j = 1, l
  277. a(i,j) = 0.D0
  278. a(j,i) = 0.D0
  279. 23 CONTINUE
  280. C ... to here when finding only eigenvalues.
  281. C
  282. 24 CONTINUE
  283. C
  284. C-----------------------------------------------------------
  285. RETURN
  286. END
  287. C***********************************************************
  288. C***************************************************END*****
  289. C .
  290. c ---------------------------------------------------------------
  291. c
  292. subroutine ordena(d,a,Nat)
  293.  
  294. implicit real*8 (a-h,o-z)
  295. dimension d(Nat), a(Nat,Nat)
  296.  
  297. do i=1,Nat-1
  298.  
  299. do j=i+1,Nat
  300.  
  301. if(d(i).gt.d(j)) then
  302.  
  303. aux1 = d(j)
  304. d(j) = d(i)
  305. d(i) = aux1
  306.  
  307. do k=1,Nat
  308.  
  309. aux2 = a(k,j)
  310. a(k,j) = a(k,i)
  311. a(k,i) = aux2
  312.  
  313. end do
  314.  
  315.  
  316. end if
  317.  
  318. end do
  319.  
  320. end do
  321.  
  322. return
  323. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement