我知道在 Matlab 上进行 Feynman 路径积分与 Fortran 或 C 相比非常耗时。
但是,有人通过路径积分获得了谐振子的 Matlab 代码吗?我没有设法在网上找到任何东西(甚至在 Matlab 论坛上)。
下面是我不知道如何翻译成 Matlab 的 Fortran 代码(我是新手)谢谢, 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 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