我正在研究阻尼驱动摆的动力学,其二阶ODE定义为so,具体来说我是编程:
d ^ 2y / dt ^ 2 + c * dy / dt + sin(y)= a * cos(wt)
import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate
def pendeq(t,y,a,c,w):
y0 = -c*y[1] - np.sin(y[0]) + a*np.cos(w*t)
y1 = y[1]
z = np.array([y0, y1])
return z
a = 2.1
c = 1e-4
w = 0.666667 # driving angular frequency
t = np.array([0, 5000]) # interval of integration
y = np.array([0, 0]) # initial conditions
yp = integrate.quad(pendeq, t[0], t[1], args=(y,a,c,w))
此问题看起来与Need help solving a second order non-linear ODE in python非常相似,但我收到错误
Supplied function does not return a valid float.
我做错了什么?
答案 0 :(得分:3)
integrate.quad
要求提供的函数(在您的情况下为pendeq
)仅返回浮点数。你的函数正在返回一个数组。