[∇]
[Δ] Modèle SIR
programmé en Python
![](images/SIR_Python_20_20D03Q03_1400x0900c.png)
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
N = 5000
I0 = 6
R0 = 0
S0 = N - I0 - R0
beta = 0.3
gamma = 0.1
y0 = S0, I0, R0
t = np.linspace(0, 200, 200)
def func(y, t, N, beta, gamma):
S, I, R = y
dSdt = -beta * S * I / N
dIdt = beta * S * I / N - gamma * I
dRdt = gamma * I
return dSdt, dIdt, dRdt
values = odeint(func, y0, t, args=(N, beta, gamma))
S, I, R = values.T
fig = plt.figure()
ax = fig.add_subplot(111, axisbelow=True)
ax.plot(t, S, 'black', lw=1.5, label='Susceptible')
ax.plot(t, I, 'orange', lw=1.5, label='Infected')
ax.plot(t, R, 'blue', lw=1.5, label='Recovered')
ax.set_xlabel('Time (days)')
ax.set_ylabel('Number of People')
ax.set_ylim(0,5100)
ax.set_xlim(0,200)
ax.grid(b=True, which='major', c='#bbbbbb', lw=1, ls='-')
legend = ax.legend()
legend.get_frame().set_alpha(0.5)
plt.show()