Python Odeint错误-此调用完成的工作量过多
我正在写一个代码,用scipy的odeint解耦合谐振子方程。我想在ODESolver的每个时间步向其中一个方程添加一个随机数。为此,我编写了两个与时间相关的常数,并使用了它们。但是,这给了我以下错误Python Odeint错误-此调用完成的工作量过多,python,python-3.x,python-2.7,numpy,scipy,Python,Python 3.x,Python 2.7,Numpy,Scipy,我正在写一个代码,用scipy的odeint解耦合谐振子方程。我想在ODESolver的每个时间步向其中一个方程添加一个随机数。为此,我编写了两个与时间相关的常数,并使用了它们。但是,这给了我以下错误 ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information. warnings.warn(war
ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run
with full_output = 1 to get quantitative information.
warnings.warn(warning_msg, ODEintWarning)
我的代码如下
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
import scipy.stats as stats
from scipy.stats import beta
m1 = 1.1
m2 = 1.0
k1 = 1000.0
k2 = 1000.0
k12 = 100
g = 0.0
global Steps
Steps = 0
x10 = 1
x20 = 0
alpha = 1
a = 2
b = 3
v10 = 0
v20 = 0
#A = np.random.beta(a,b, 10) * alpha
#B = np.random.beta(a,b, 10) * alpha
def c(t):
return np.random.beta(a,b) * alpha
def d(t):
return np.random.beta(a,b) * alpha
def f(x, t, c, d):
y = []
y.append(x[1] - c(t) * x[0])
#print(c(t))
y.append(-(k1 + k12) / m1 * x[0] + k12 / m1 * x[2] - 2 * g * x[1] - c(t) * x[1])
y.append(x[3] - d(t) * x[2])
y.append(-(k2 + k12) / m2 * x[2] + k12 / m2 * x[0] - 2 * g * x[3] - d(t) * x[3])
return y
b0 = [x10, v10, x20, v20]
b0 = np.array(b0)
args = (c, d)
t = np.linspace(0, 1, 1000 )
t = np.array(t)
X1, infodict = odeint(f, b0, t, args, full_output = 1)
X1 = X1.T
Q1 = X1[0]
Q2 = X1[2]
plt.plot(t, Q1, 'g-')
plt.plot(t, Q2, 'b-')
plt.show()
a = m1*m2
b = -(m1*(k2 + k12) + m2*(k1 + k12))
c = k1*k2 + k12*(k1 + k2)
wp = np.sqrt((-b + np.sqrt(b**2 - 4*a*c))/(2*a))
wm = np.sqrt((-b - np.sqrt(b**2 - 4*a*c))/(2*a))
print(wp)
print(wm)
f = open('simdata.csv', mode='w')
for i in range(len(t)):
p = str(t[i]) + ',' + str(Q1[i]) + ',' + str(Q2[i]) + '\n'
f.write(p)
f.close()
“…在每个时间步向其中一个方程添加一个随机数…”这违反了
odeint
算法的假设,因此odeint
失败也就不足为奇了odeint
(与大多数ODE解算器一样)假设解足够平滑,可以用截断的泰勒级数进行局部近似。你的随机过程违反了这个假设。(当使用相同的输入多次调用时,您的系统甚至不会返回相同的值!)我支持Warren Weckesser的评论。积分随机微分方程(正如你显然想做的)不同于积分常微分方程。