I know that doing Feynman path Integral on Matlab is time consuming compare to Fortran or C.
However, do someone have a Matlab code of harmonic oscillator via path integral? I didn't manage to find any on the web (and even on Matlab forum).
Below a Fortran code which I don't know how to translate to Matlab (I am novice) Thanks, Joni
! qmc . f90 : Feynman path i n t e g r a l for ground s t a t e 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 开发者_Python百科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
This is an open source code for calculating Feynman integrals in MATLAB: http://arxiv.org/pdf/1205.6872v1.pdf which can be run on any ordinary CPU and much faster on a GPU.
Since it only uses extremely efficient built-in MATLAB functions which are compiled to machine code, it's not expected to be significantly slower than FORTRAN or C (keeping in mind that the computational cost of calculating Feynman integrals scales exponentially with respect to the number of time steps, meaning that FORTRAN, C, and MATLAB will all be slow in many cases, and the differences between them will be much smaller than the difference between taking 12 time steps and 13 time steps).
If you run this MATLAB code on a GPU it will in fact be faster than the FORTRAN or C implementation (only a CUDA FORTRAN or CUDA C code will be able to compare).
If you have more questions about this code you can email the author at dattani.nike@gmail.com
精彩评论