【问题标题】:Plotting particles positions over time随时间绘制粒子位置
【发布时间】:2016-09-03 11:02:35
【问题描述】:

我在一个封闭的体积中绘制了 N 个粒子的一个位置 (x,y,z)。

x[i] = random.uniform(a,b) ...

我还发现了 N 个粒子的恒定速度(vx,vy,vz)。

vx[i] = random.gauss(mean,sigma) ...

现在我想找到 N(=100) 个粒子随时间变化的位置。我使用了 Euler-Cromer 方法。

delta_t = linspace(0,2,n-1) 
n = 1000
v[0] = vx;...
r[0] = x;...

for i in range(n-1):
    v[i+1,:] = v[i,:]
    r[i+1,:] = r[i,:] + delta_t*v[i+1,:]
    t[i+1] = t[i] + delta_t

但我想找到每个粒子随时间推移的位置。我怎样才能做到这一点?另外,如何在 3D 中绘制粒子位置随时间的变化?

【问题讨论】:

    标签: python simulation particles


    【解决方案1】:

    要查找粒子在给定时间的位置,您可以使用以下代码:

    import numpy as np
    
    # assign random positions in the box 0,0,0 to 1,1,1
    x = np.random.random((100,3))
    # assign random velocities in the range around 0
    v = np.random.normal(size=(100,3))
    
    # define function to project the position in time according to
    # laws of motion.  x(t) = x_0 + v_0 * t
    def position(x_0, v_0, t):
        return x_0 + v_0*t
    
    # get new position at time = 3.2
    position(x, v, 3.2)
    

    【讨论】:

      猜你喜欢
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      相关资源
      最近更新 更多