numpy随机位移平均位移。
我正在使用numpy Random.ormal的步骤长度进行随机步行的模拟。我知道当我使用时,我应该得到σ(t)²的平方位移
x += random.normal(loc = 0.0,scale = sigma)
。
我不明白的是,为什么我在这里使用σ(t)²的MSD
x += sigma*random.normal(loc = 0.0,scale = 1.0)
的完整代码
import numpy as np
import matplotlib as plt
dt = 0.001 #length of time step
tf = 10.0 #time to run simulation
tmax = int(tf/dt) #number of steps to run
sigma = np.sqrt(2*dt) #standard deviation of random walk
run_n = 1000 #number of runs
xp1s = np.zeros(tmax) #x values of sigma*N(0.0,1.0)
xp2s = np.zeros(tmax) #x values of N(0.0,sigma)
for run in range(run_n):
#how much the particle moves at each point in time
xp1 = sigma*np.random.normal(0.0,1.0, size = tmax)
xp2 = np.random.normal(0.0,sigma, size = tmax)
#position at each time is the sum of steps before it
xp1tmp = np.cumsum(xp1)
xp2tmp = np.cumsum(xp2)
#get the MSD for each point in time
xp1s += xp1tmp**2 /run_n
xp2s += xp2tmp**2 /run_n
plt.plot(linspace(0,tf,tmax),xp1s)
plt.plot(linspace(0,tf,tmax),xp2s)
是我无法共享图像 ,但我确实会得到每个σ(t)²的MSD模拟。
I am running a simulation for a random walk using steps lengths from numpy random.normal. I understand that I should get a mean squared displacement of σ(t)² when I use
x += random.normal(loc = 0.0,scale = sigma)
which I do.
What I don't understand is why I get a MSD of σ(t)² when I use
x += sigma*random.normal(loc = 0.0,scale = 1.0)
Here is the full code for my simulation
import numpy as np
import matplotlib as plt
dt = 0.001 #length of time step
tf = 10.0 #time to run simulation
tmax = int(tf/dt) #number of steps to run
sigma = np.sqrt(2*dt) #standard deviation of random walk
run_n = 1000 #number of runs
xp1s = np.zeros(tmax) #x values of sigma*N(0.0,1.0)
xp2s = np.zeros(tmax) #x values of N(0.0,sigma)
for run in range(run_n):
#how much the particle moves at each point in time
xp1 = sigma*np.random.normal(0.0,1.0, size = tmax)
xp2 = np.random.normal(0.0,sigma, size = tmax)
#position at each time is the sum of steps before it
xp1tmp = np.cumsum(xp1)
xp2tmp = np.cumsum(xp2)
#get the MSD for each point in time
xp1s += xp1tmp**2 /run_n
xp2s += xp2tmp**2 /run_n
plt.plot(linspace(0,tf,tmax),xp1s)
plt.plot(linspace(0,tf,tmax),xp2s)
I can't share images, but I do get an MSD of σ(t)² for each simulation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论