None
This notebook contains material from nbpages by Jeffrey Kantor (jeff at nd.edu). The text is released under the CC-BY-NC-ND-4.0 license. The code is released under the MIT license.
The Susceptible-Infectious-Recovered (SIR) model is an example of a compartmental model that is widely used to forecast the progress of disease epidemics.
\begin{align} \frac{dS}{dt} & = -\frac{\beta I S}{N} \\ \frac{dI}{dt} & = \frac{\beta I S}{N} - \gamma I \\ \frac{dR}{dt} & = \gamma I \end{align}Where the basic reproduction number $R_0 = \frac{\beta}{\gamma}$
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
N = 10000.0
R0 = 2.4
gamma = 1/8.0
beta = gamma*R0
def deriv(t, y):
S, I, R = y
dSdt = -beta*I*S/N
dIdt = beta*I*S/N - gamma*I
dRdt = gamma*I
return [dSdt, dIdt, dRdt]
t = np.linspace(0, 180, 181)
y0 = [N - 1.0, 1.0, 0.0]
soln = solve_ivp(deriv, [t[0], t[-1]], y0, t_eval=t)
plt.plot(soln.t, soln.y[0], label='Susceptible')
plt.plot(soln.t, soln.y[1], label='Infectious')
plt.plot(soln.t, soln.y[2], label='Recoverd')
plt.legend()
plt.xlabel('days')
plt.grid(True)
The Susceptible-Infectious-Recovered (SIR) model is an example of a compartmental model that is widely used to forecast the progress of disease epidemics.
\begin{align} \frac{dS}{dt} & = -\frac{\beta I S}{N} \\ \frac{dI}{dt} & = \frac{\beta I S}{N} - \gamma I \\ \frac{dR}{dt} & = \gamma I \end{align}Where the basic reproduction number $R_0 = \frac{\beta}{\gamma}$
This cell has been tagged with "home-activity".
This cell has been tagged with "class-activity".
This cell has been tagged with "important-note".
For teaching purposes, it is often useful to selecting remove code from cells a
In the following cell write a function that returns the square of a number.
# write a function that returns the square of a number
### BEGIN SOLUTION
def sqr(x):
return x**2
### END SOLUTION
assert sqr(2) == 4
assert sqr(-1) == 1
### BEGIN HIDDEN TESTS
assert sqr(3) == 9
assert abs(sqr(3.3) - 10.89) < 0.001
### END HIDDEN TESTS