我面临着微分方程(python)的问题:
这是我的DE:
m*x"(t) + d*x'(t) + k*x(t) = y(t)
哪里y(t) = Y * sin(w*t)
数据:
m=3
d=79
k=200000
w=152
Y=0.05
t=np.linspace(t_0,t_1, n) # not that important.
我必须使用numpy.array
获得x(t)
的scipy.integrate.odeint
,并且我有很大的问题将我的DE改为2.命令到1.命令的DE。
我正在寻找的是fip in scipy.integrate.odeint https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.odeint.html基于我的方程式。主要是需要找到x(t)的np.array,然后是x'(t)和x''(t)。
通常的程序是设置v=x'
然后
x' = v
v' = ( y(t) - d*v - k*x) / m
要么
def derivs(u,t):
x,v = u
return [ v, ( y(t) - d*v - k*x) / m ]
def y(t): return Y*np.sin(w*t)
t_0, t_1, n = 0, 1, 501
t=np.linspace(t_0,t_1, n)
x0, v0 = 0.0, 0.0
u0 = [ x0, v0 ]
u = odeint(derivs, u0, t)
plt.subplot(2,1,1); plt.title("x(t)"); plt.plot(t, u[:,0])
plt.subplot(2,1,2); plt.title("x'(t)"); plt.plot(t, u[:,1])
plt.show()
结果