Skip to content
Snippets Groups Projects
Commit a1a3b3fa authored by orestis.malaspin's avatar orestis.malaspin
Browse files

added covid code

parent e131ee58
No related branches found
No related tags found
No related merge requests found
import numpy as np
import matplotlib.pyplot as plt
def s(dt, beta, S0, I0, N):
return S0 - dt * (beta * S0 * I0 / N)
def ii(dt, beta, lamb, S0, I0, N):
return I0 + dt * (beta * S0 * I0 / N - lamb * I0)
def r(dt, lamb, R0, I0, N):
return R0 + dt * lamb * I0
def compute_n(S, R, I):
return S + R + I
def timestep(S0, I0, R0, dt, beta, lamb, N):
S1 = s(dt, beta, S0, I0, N)
I1 = ii(dt, beta, lamb, S0, I0, N)
R1 = r(dt, lamb, R0, I0, N)
return S1, I1, R1
S0 = 400000
I0 = 1
R0 = 0
max_t = 100
n_steps = 1000
dt = max_t / n_steps
N = compute_n(S0, I0, R0)
lamb = 1.0 / 14.0
beta = 1
s_list = [S0]
r_list = [R0]
i_list = [I0]
t_list = [0]
for i in range(0, n_steps):
S1, I1, R1 = timestep(s_list[i], i_list[i], r_list[i], dt, beta, lamb, N)
s_list.append(S1)
i_list.append(I1)
r_list.append(R1)
t_list.append((i+1)*dt)
s = np.array(s_list)
r = np.array(r_list)
ii = np.array(i_list)
t = np.array(t_list)
plt.plot(t, s, 'b')
plt.plot(t, r, 'r')
plt.plot(t, ii, 'k')
plt.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment