我试图用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会出现,但是没有显示任何数据。当我尝试用差分方程循环时,我做错了什么?在
然后假设最终结果在图上产生三条线,“易感”、“已感染”和“已恢复”,每一条线都显示了人口受疾病影响的速度。在