我正在尝试使用matplotlib在Python中绘制一个SIR模型,该模型具有:
a)人口2200b)并显示人口在30天内的过程
c)c)(Δ)t = 0.01 -Delta正在改变而且是时间这是我的代码:
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,但我的数据都没有显示。在尝试使用差分方程循环时,我做错了什么?
然后,最终结果假设在图表上产生三条线,"感知","感染"和"恢复",每个显示的速率人口受疾病的影响。