【发布时间】:2018-11-01 10:33:35
【问题描述】:
我正在尝试解决这个微分方程,作为我作业的一部分。我无法理解如何将您的条件放入代码中。下图代码中,我随意提供了
u = 5.
2dx(t)dt=−x(t)+u(t)
5dy(t)dt=−y(t)+x(t)
u=2S(t−5)
x(0)=0
y(0)=0
where S(t−5) is a step function that changes from zero to one at t=5. When it is multiplied by two, it changes from zero to two at that same time, t=5。
def model(x,t,u):
dxdt = (-x+u)/2
return dxdt
def model2(y,x,t):
dydt = -(y+x)/5
return dydt
x0 = 0
y0 = 0
u = 5
t = np.linspace(0,40)
x = odeint(model,x0,t,args=(u,))
y = odeint(model2,y0,t,args=(u,))
plt.plot(t,x,'r-')
plt.plot(t,y,'b*')
plt.show()
【问题讨论】:
-
欢迎接受任何答案(上下投票按钮下方的绿色钩子)。这有助于我们的声誉。请提供一点反馈...
标签: python scipy ode differential-equations