【发布时间】:2016-01-19 20:39:36
【问题描述】:
我正在尝试求解类似于 d2(phi)/dt = -(g/R) *sin(phi) 的钟摆式微分方程(这是泰勒经典力学中的滑板问题)。我是 scipy 和 odeint 等的新手,所以我这样做是为了为将来更复杂的数值解决方案做准备。
我使用来自here 的代码来尝试导航编码,但我想出的只是phi(t) 的一条平线。我认为这源于我试图将二阶微分方程分成两个一阶,其中一个不依赖于另一个(因为 d(phi)/dt 出现);但我不确定如何修复它。
有人知道这是怎么回事吗?
# integrate skateboard problem, plot result
from numpy import *
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def skate(y, t, params):
phi, omega = y
g, R = params
derivs = [omega, -(g/R)*np.sin(phi)]
return derivs
# Parameters
g = 9.81
R = 5
params = [g, R]
#Initial values
phi0 = 20
omega0 = 0
y0 = [phi0, omega0]
t = linspace(0, 20, 5000)
solution = odeint(skate, y0, t, args=(params,))
plt.plot(t, solution[:,0])
plt.xlabel('time [s]')
plt.ylabel('angle [rad]')
plt.show()
【问题讨论】:
标签: python integration numerical odeint