[英]Python simulation problem: ODE system with randomly changing coefficients
I'm pretty new to this type of problem, so I appreciaty any help.我对这类问题很陌生,所以我很感激任何帮助。
I'm trying to simulate a dipole-dipole interaction problem, where one large dipole is stationary at the origin and another (small dipole) is located somewhere inside the electric field of the larger one.我正在尝试模拟一个偶极子-偶极子相互作用问题,其中一个大偶极子在原点静止,另一个(小偶极子)位于较大偶极子的电场内某处。 I'm trying to find the path the smaller dipole takes given some orientation and starting position.
我试图找到较小偶极子在给定方向并启动 position 的路径。
The catch is that the orientation of the small dipole randomly changes at every time step.问题是小偶极子的方向在每个时间步都是随机变化的。 I have managed to simulate this problem if the orientation of the small dipole is kept constant using scipy.integrate.odeint
如果使用 scipy.integrate.odeint 使小偶极子的方向保持不变,我已经设法模拟了这个问题
When I try to solve the same problem, but with the dipole orienation changing randomly, i get the following error:当我尝试解决相同的问题,但偶极子方向随机变化时,我收到以下错误:
ODEintWarning: Excess work done on this call (perhaps wrong Dfun type).
ODEintWarning:在此调用上完成的工作过多(可能是错误的 Dfun 类型)。 Run with full_output = 1 to get quantitative information.
以 full_output = 1 运行以获取定量信息。
warnings.warn(warning_msg, ODEintWarning)警告.warn(warning_msg, ODEintWarning)
Can I fix this?我可以解决这个问题吗? Should I use another method of numerical integration that is better suited for this, and if so which one?
我是否应该使用另一种更适合于此的数值积分方法,如果可以,使用哪一种?
Here is the relevant part of my code这是我的代码的相关部分
from cmath import exp
from scipy.integrate import odeint
import numpy as np
#constants
pv = 10e12
m = 1
Q = 6.95e-12
K = pv*(1/m)*Q
def px(t):
return np.random.normal()
def py(t):
return np.random.normal()
def pz(t):
return np.random.normal()
def odes(q,t, px, py, pz): #q is a vector
#u1 = x, v1 = y, w1 = z, ...
u1 = q[0]
v1 = q[1]
w1 = q[2]
u2 = q[3]
v2 = q[4]
w2 = q[5]
du1dt = u2
dv1dt = v2
dw1dt = w2
#Force
du2dt = (u1**2 + v1**2 + w1**2)**(-2.5)*(px(t)*(-2*u1 + w1**2 + v1**2)*w1 - py(t)*3*u1*v1*w1 + pz(t)*(-2*w1**2 + u1**2 + v1**2)*u1)
dv2dt = (u1**2 + v1**2 + w1**2)**(-2.5)*(-px(t)*3*u1*v1*w1 + py(t)*(-2*v1**2 + w1**2 + u1**2) + pz(t)*(-2*w1**2 + u1**2 + v1**2)*v1)
dw2dt = (u1**2 + v1**2 + w1**2)**(-2.5)*(-px(t)*3*(w1**2 - pv)*u1 - py(t)*3*(w1**2 - pv)*v1 + pz(t)*(3*pv + 2*u1**2 + 2*v1**2 - w1**2)*w1)
return [du1dt, dv1dt, dw1dt, du2dt, dv2dt, dw2dt]
#initial conditions
x0 = 90
y0 = 110
z0 = 100
dxdt0 = 0
dydt0 = 0
dzdt0 = 0
q0 = [x0, y0, z0, dxdt0, dydt0, dzdt0]
T = 10
dt = 0.0025
t = np.linspace(0, T, int(T//dt))
args = (px,py,pz)
q = odeint(odes, q0, t, args)
x = q[:,0]
y = q[:,1]
z = q[:,2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.