传染病模型python_用matplotlib绘制python传染病SIR模型

我试图用Python中的matplotlib绘制一个SIR模型,它具有:

a)人口2200

b)并显示了30天内受影响的人口过程

c)δt=0.01

-Delta是变化的,t是时间

这是我的代码:import matplotlib.pyplot as pyplot

def SIR(population, days, dt):

susceptible = population - 1

infected = 1.0

recovered = 0.0

recRate = 0.25

infRate = 0.0004

SList = [susceptible]

IList = [infected]

RList = [recovered]

timeList =[0]

for day in range(1, int(days/dt) + 1):

population = population + (0.0004 * population - 0.25) * dt

t = day * dt

timeList.append(t)

SList.append(SList)

IList.append(SList)

RList.append(SList)

pyplot.plot(timeList, SList, label = 'Susceptible')

pyplot.plot(timeList, IList, label = 'Infected')

pyplot.plot(timeList, RList, label = 'Recovered')

pyplot.legend(loc = 'center right')

pyplot.xlabel('Days')

pyplot.ylabel('Individuals')

pyplot.show()

SIR(2200, 30, 0.01)

所以当我现在运行代码时,matplotlib会出现,但是没有显示任何数据。当我尝试用差分方程循环时,我做错了什么?在

然后假设最终结果在图上产生三条线,“易感”、“已感染”和“已恢复”,每一条线都显示了人口受疾病影响的速度。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值