-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovid-2.py
54 lines (46 loc) · 1.25 KB
/
covid-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 10:32:49 2020
@author: benho
"""
#%%
# Acknowledgement:
# https://www.maa.org/press/periodicals/loci/joma/the-sir-model-for-spread-of-disease-introduction
#%%
import numpy as np
import matplotlib.pyplot as plt
#%%
n = 400
susceptible = np.zeros(n)
infected = np.zeros(n)
recovered = np.zeros(n)
time = np.zeros(n)
delta_t = .25
#%%
susceptible[0] = 1 # this is just 1, not 1 million b/c represents fraction
infected[0] = .000015
recovered[0] = 0
time[0] = 0 #time is measured in days
#%%
b = .9 # number of infected encounters per day
k = .07 # fraction that recovers each day
# these values are estimates
#%%
for i in range(n-1):
ds = -b*susceptible[i]*infected[i]
di = b*susceptible[i]*infected[i]-k*infected[i]
dr = k*infected[i]
susceptible[i+1] = susceptible[i] + ds*delta_t
infected[i+1] = infected[i] + di*delta_t
recovered[i+1] = recovered[i] + dr*delta_t
time[i+1] = time[i] + delta_t
#%%
plt.figure()
plt.xlabel("time in days")
plt.grid()
plt.plot(time,susceptible)
plt.plot(time,infected)
plt.plot(time,recovered)
plt.legend(labels=["Susceptible","Infected","Recovered"])
plt.text(5,0.8,r'b={} k={}'.format(b,k))
plt.show()