Odeint错误 - 在此调用中完成的工作量过多

时间:2018-04-18 11:52:08

标签: 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(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()

0 个答案:

没有答案