Python的解决与四功能二阶ODE

问题描述:

我学习阻尼的动态,用二阶ODE驱动摆定义像so,具体我预设电台:Python的解决与四功能二阶ODE

d^2Y/dt的^ 2 + C * DY/DT +罪(Y)= A * cos(重量)

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

它看起来像你解决摆的位置作为几个参数的函数,是吗? – 2014-11-06 01:30:48

+0

是的,这是正确的。 – 2014-11-06 01:31:30

+1

'quad'集成了一个标量函数。它不能求解一个常微分方程。再看一下你链接的例子 - 'scipy.integrate.odeint'(不是'quad')被用来生成解决方案。另请参阅http://wiki.scipy.org/Cookbook/CoupledSpringMassSystem – 2014-11-06 02:17:59

integrate.quad要求提供的功能(pendeq,在你的情况下)只返回一个浮点数。你的函数正在返回一个数组。

+0

我已经回答了“我在做什么错了?”这个问题的部分内容,但我仍然在试图弄清楚如何正确执行。如果我能弄明白,我会编辑我的答案。在这一点上,它更像是一个物理问题,而不是一个编程问题。 – 2014-11-06 01:34:09