我试图弄清楚如何计算粒子的轨迹。
我很难搞清楚从哪里开始。
下图是我想要的样子,因为后来,我想用maxwells分布方程绘制这些轨迹的速度和速度分布。
到目前为止,这是我的代码
import numpy as np
import matplotlib.pyplot as plt
import time
from numpy.random import rand
from scipy.linalg import norm
def F(pos,vel,n,nsteps):
for tsteps in range(nsteps-1):
i=0
vel[i] = vel[i]
pos[i] = pos[i] + vel[i] * dt
if pos[i,0] > L:
pos[i,0] = pos[i,0] - L
elif pos[i,0] < 0:
pos[i,0] = pos[i,0] + L
elif pos[i,1] > L:
pos[i,1] = pos[i,1] - L
elif pos[i,1] < 0:
pos[i,1] = pos[i,1] + L
vel[i,1] *= -1
if tsteps%1 == 0:
plt.scatter(pos[i,0],pos[i,1],color="b",s=2)
plt.draw()
n=1
L=10
nsteps=200
dt=0.28
pos=np.zeros([n,2])
vel=np.zeros([n,2])
plt.figure(figsize=[8,8])
plt.axis([0,L,0,L])
plt.ion()
plt.show()
pos_init = np.array([0,0])
vel_init = np.array([-1,-0.31456])
pos[0,:] = pos_init[:]
vel[0,:] = vel_init[:]
t0= time.time()
F(pos,vel,n,nsteps)
print("execution time = " , time.time()- t0)