Problem Statement: Epidemic Spread Model (SIR Model)
The SIR model is a basic mathematical model to describe the spread of infectious diseases.
It divides the population into three compartments:
- S (Susceptible): People who can catch the disease.
- I (Infected): People currently infected and able to spread the disease.
- R (Recovered): People who have recovered and are now immune.
The dynamics are governed by these equations:
$$
\frac{dS}{dt} = -\beta S I
$$
$$
\frac{dI}{dt} = \beta S I - \gamma I
$$
$$
\frac{dR}{dt} = \gamma I
$$
- $(\beta)$ is the infection rate.
- $(\gamma)$ is the recovery rate.
Simulate the SIR model for $160$ days with a population of $1,000$, assuming an initial infection of $1$ person, $(\beta = 0.3)$, and $(\gamma = 0.1)$.
Visualize the results.
Python Code
1 | import numpy as np |
Explanation of Code
- Model Dynamics:
- The
sir_modelfunction defines the SIR equations. - The
odeintfunction solves these differential equations numerically.
- The
- Parameters:
- $(N)$: Total population.
- $(\beta)$: Controls how fast the disease spreads.
- $(\gamma)$: Determines how fast infected individuals recover.
- Initial Conditions:
- Start with $1$ infected person, $0$ recovered, and the rest susceptible.
- Time Points:
- Simulate the system for $160$ days.
- Visualization:
- Plot the population dynamics of the S, I, and R compartments over time.
Results

- Blue Curve (Susceptible): Shows the decreasing number of people vulnerable to infection.
- Red Curve (Infected): Demonstrates the rise and eventual decline of infections as the epidemic progresses.
- Green Curve (Recovered): Represents the growing number of immune individuals over time.
This visualization provides insight into how diseases spread and decline in a population.









