我现在有一个n体系统中10000个时间点的速度列表。它是一个三维阵列,涉及三维空间中时间点的n粒子。例如,如果两个时间点上有三个粒子,则将其设置为
[[[vx1][vy1][vz1]
[vx2][vy2][vz2]
[vx3][vy3][vz3]]
[[vx1][vy1][vz1]
[vx2][vy2][vz2]
[vx3][vy3][vz3]]]
我的目标是这样的:
^{pr2}$但是我不能求出速度分量的平方相加,而粒子的数量是自由变化的。我可以用这样的两个粒子来做:
# Takes all velocities and converts them to speeds
all_speeds=[]
for i in range(len(all_velocities)):
all_speeds.append([math.sqrt(all_velocities[i][0][0]**2\
+all_velocities[i][0][1]**2+all_velocities[i][0][2]**2)],\
[math.sqrt(all_velocities[i][1][0]**2+all_velocities[i][1][1]**2\
+all_velocities[i][1][2]**2)])
但我不确定如何将其扩展到n粒子。我的最终目标是把速度数组平方,然后乘以质量数组,我要计算系统的动能,但是我不能把它推广到任何输入下。谢谢。在
你只需要在主循环中的粒子数上增加一个循环。在
为了便于阅读,我还在下面的代码片段中创建了一个函数来进行速度计算:
再添加一个循环
希望这有帮助。在
^{pr2}$a.shape
是(t,n,d)。你需要三维速度平方和的平方根:b.shape
是(t,n)。在我的数据集中似乎没有粒子在加速。在或者简单地说:
相关问题 更多 >
编程相关推荐