Untitled
unknown
python
13 days ago
1.1 kB
1
Indexable
Never
import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint # Parameters beta = 0.3 # Infection rate gamma = 0.1 # Recovery rate v = 0.05 # Vaccination rate # Initial conditions: S(0), I(0), R(0) S0 = 990 I0 = 10 R0 = 0 N = S0 + I0 + R0 # Total population # Time points (days) t = np.linspace(0, 160, 160) # The SIR model differential equations def sir_vaccination(y, t, N, beta, gamma, v): S, I, R = y dSdt = -beta * S * I / N - v * S dIdt = beta * S * I / N - gamma * I dRdt = gamma * I + v * S return dSdt, dIdt, dRdt # Initial conditions vector y0 = S0, I0, R0 # Integrate the SIR equations over the time grid solution = odeint(sir_vaccination, y0, t, args=(N, beta, gamma, v)) S, I, R = solution.T # Plot the data plt.figure(figsize=(10,6)) plt.plot(t, S, 'b', label='Susceptible') plt.plot(t, I, 'r', label='Infected') plt.plot(t, R, 'g', label='Recovered') plt.xlabel('Time (days)') plt.ylabel('Population') plt.title('SIR Model with Vaccination') plt.legend() plt.grid(True) plt.show()
Leave a Comment