如何用我的两个微分方程来显示曲线?

2024-06-12 18:35:23 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我正在尝试用我的代码实现euler显式方法。 这是我的两个微分方程。 -dSdt=psS(1-((R+S)/K))-(C*S) -dRdt=prR(1-((R+S)/K))-(βSR)

如何显示曲线

谢谢你的回答

h = 0.5
t = np.linspace(0, 35, 35)
def S(t):
    if(t <= 0):
        return S0
    else:
        return funcS(t - h) + h * ps*funcS(t - h)*(1-((funcR(t - h) + funcS(t - h))/K)) - (C * funcS(t - h))

def R(t):
    if(t == 0):
        return R0
    else:
        return pr*funcR(t - h)*(1-((funcR(t - h) + funcS(t - h))/K)) - (beta*funcS(t - h)*funcR(t - h))

Tags: 方法代码returnifdefelse曲线funcs
1条回答
网友
1楼 · 发布于 2024-06-12 18:35:23

使用matplotlib尝试以下操作:

import matplotlib.pyplot as plt

plt.plot(t, S(t))          # assuming you want to plot S(t)
plt.show()                 # this will display your figure

相关问题 更多 >