我學習阻尼的動態,用二階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.
做錯了?
它看起來像你解決擺的位置作爲幾個參數的函數,是嗎? – 2014-11-06 01:30:48
是的,這是正確的。 – 2014-11-06 01:31:30
'quad'集成了一個標量函數。它不能求解一個常微分方程。再看一下你鏈接的例子 - 'scipy.integrate.odeint'(不是'quad')被用來生成解決方案。另請參閱http://wiki.scipy.org/Cookbook/CoupledSpringMassSystem – 2014-11-06 02:17:59