! From: "COMPUTATIONAL PHYSICS, 2nd Ed" ! by RH Landau, MJ Paez, and CC Bordeianu ! Copyright Wiley - VCH, 2007. ! Electronic Materials copyright: R Landau, Oregon State Univ, 2007; ! MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. ! Supported by the US National Science Foundation ! ! qmc.f90: Feynman path integral for ground state wave Function Program qmc Implicit none Integer :: i, j, max, element, prop(100) Real*8 :: change, ranDom, energy, newE, oldE, out, path(100) max = 250000 open(9, FILE = 'qmc.dat', Status = 'Unknown') ! initial path and probability Do j = 1, 100 path(j) = 0.0 prop(j) = 0 End Do ! find energy of initial path oldE = energy(path, 100) ! pick random element, change by random Do i = 1, max element = ranDom()*100 + 1 change = ((ranDom() - 0.5)*2) path(element) = path(element) + change newE = energy(path, 100) ! find new energy ! Metropolis algorithm If ((newE > oldE) .AND. (exp( - newE + oldE) < ranDom())) then path(element) = path(element) - change EndIf ! add up probabilities Do j = 1, 100 element = path(j)*10 + 50 prop(element) = prop(element) + 1 End Do oldE = newE End Do ! write output data to file Do j = 1, 100 out = prop(j) write(9, *) j - 50, out/max End Do close(9) Stop 'data saved in qmc.dat' End Program qmc ! Function calculates energy of the system Function energy(array, max) Implicit none Integer :: i, max Real*8 :: energy, array(max) energy = 0 Do i = 1, (max - 1) energy = energy + (array(i+ 1) - array(i))**2 + array(i)**2 End Do Return End