numpy随机位移平均位移。

发布于 2025-01-22 02:46:24 字数 1154 浏览 3 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文