传染病模型python_用matplotlib绘制python传染病SIR模型
我试图用Python中的matplotlib绘制一个SIR模型,它具有:a)人口2200b)并显示了30天内受影响的人口过程c)δt=0.01-Delta是变化的,t是时间这是我的代码:import matplotlib.pyplot as pyplotdef SIR(population, days, dt):susceptible = population - 1infected = 1.0r
我试图用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会出现,但是没有显示任何数据。当我尝试用差分方程循环时,我做错了什么?在
然后假设最终结果在图上产生三条线,“易感”、“已感染”和“已恢复”,每一条线都显示了人口受疾病影响的速度。在
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)