我正在尝试让 Scipy 的 ODE 求解器求解洛伦兹力微分方程。它不能用 B 场分量正确求解方程,因为无论我做多大的 E 场,它都会完全忽略它(这也是我知道它忽略它的原因)。为什么是这样?我也已经尝试过修改 E-field 功能上的标志。代码:import numpy as npimport pylabfrom scipy.integrate import odeintimport matplotlib.pyplot as plt#import randomimport mpl_toolkits.mplot3d.axes3d as p3#Mirroring Angle to RecreateThetaMirror = 40TStep = 1TFinal = 10P0 = [0.,0.02,0.]V0 = [1,0,0]t = np.linspace(0,TFinal,num=(TFinal/TStep))#Physical/Natural Constantsq_e = -1m_e = 1QeMe = q_e/m_eu0 = 1#MathICs = np.concatenate((P0,V0),axis=0)def BField(x,y,z): Bx = 0 By = 0 Bz = 1 BVec = np.array([Bx,By,Bz]) return BVecdef EField(x,y,z): Ex = 0 Ey = 0 Ez = 2.8E8*z**4 EVec = np.array([Ex,Ey,Ez]) return EVecdef LorentzForce(PosVel,t,Constants): x,y,z,vx,vy,vz = PosVel Ex,Ey,Ez,Bx,By,Bz,QeMe = Constants EFInput = np.array([Ex,Ey,Ez]) BFInput = np.array([Bx,By,Bz]) VelInput = np.array([vx,vy,vz]) Accel = QeMe * (EFInput + np.cross(VelInput, BFInput)) LFEqs = np.concatenate((VelInput, Accel), axis = 0) return LFEqsEx,Ey,Ez = EField(P0[0],P0[1],P0[2])Bx,By,Bz = BField(P0[0],P0[1],P0[2])#Ex = Ey = Ez = 0AllConstantInputs = [Ex,Ey,Ez,Bx,By,Bz,QeMe]ParticleTrajectory = odeint(LorentzForce, ICs, t, args=(AllConstantInputs,))print(ParticleTrajectory)print(Bz)fig = plt.figure()particleplot = fig.add_subplot(111,projection='3d')particleplot.plot(ParticleTrajectory[:, 0],ParticleTrajectory[:, 1],ParticleTrajectory[:, 2],'b')particleplot.set_xlabel('x axis')particleplot.set_ylabel('y axis')particleplot.set_zlabel('z axis')particleplot.legend(loc='best')particleplot.grid()plt.show()
1 回答
HUH函数
TA贡献1836条经验 获得超4个赞
你定义P0[2] = 0.
. 电场函数计算Ez = 2.8E8*z**4
。因此,python 没有忽略 E-field 函数,您自己将其 z 分量置零:z = P0[2] = 0
.
添加回答
举报
0/150
提交
取消