我正在使用scipy的ode求解器来计算B和E场中电子的轨迹(但是目前所有组件的E场均为零)。我首先对常数和字段使用非常简单的数字,即。 q = m = Bz = Ez = vy = 1并得到正确的解。但是,当我尝试为q和m输入更实际的值时,它给我的解决方案是完全错误的。我不认为这是ode求解器的错,而是我自己的错,所以我想问问是否有人可以看出我的初始条件和时间步骤可能出了什么问题,以了解为什么会这样。代码:
import numpy as np
import pylab
from scipy.integrate import odeint
import matplotlib.pyplot as plt
#import random
import mpl_toolkits.mplot3d.axes3d as p3
P0 = [0,0,0]
V0 = [1.759E+11,0,0]
t = np.linspace(0,9E-8,num=10E-8)
#Physical/Natural Constants
q_e = -1.602E-19
m_e = 9.11E-31
#Math
ICs = np.concatenate((P0,V0),axis=0)
def BField(x,y,z):
Bx = 0
By = 0
Bz = 1
BVec = np.array([Bx,By,Bz])
return BVec
Bout = BField(0,0,0.02)
def EField(x,y,z):
Ex = 0
Ey = 0
Ez = 0
EVec = np.array([Ex,Ey,Ez])
return EVec
def LorentzForce(PosVel,t,Constants):
x,y,z,vx,vy,vz = PosVel
Ex,Ey,Ez,Bx,By,Bz,q_e,m_e = Constants
EFInput = np.array([Ex,Ey,Ez])
BFInput = np.array([Bx,By,Bz])
VelInput = np.array([vx,vy,vz])
Accel = (q_e/m_e) * (EFInput + np.cross(VelInput, BFInput))
LFEqs = np.concatenate((VelInput, Accel), axis = 0)
return LFEqs
Ex,Ey,Ez = EField(P0[0],P0[1],P0[2])
Bx,By,Bz = BField(P0[0],P0[1],P0[2])
#Ex = Ey = Ez = 0
AllConstantInputs = [Ex,Ey,Ez,Bx,By,Bz,q_e,m_e]
ParticleTrajectory = odeint(LorentzForce, ICs, t, args=(AllConstantInputs,))
print(ParticleTrajectory)
fig = pylab.figure()
particleplot = p3.Axes3D(fig)
plt.plot(ParticleTrajectory[:, 0],ParticleTrajectory[:, 1],ParticleTrajectory[:, 2],'b')
plt.legend(loc='best')
plt.grid()
plt.show()