% SIR Model Simulation using ode45
% Parameters
a = 0.05; % Infection rate
b = 0.12; % Recovery rate
n = 200; % Total population
% Initial conditions
I0 = 1; % Initial number of infected individuals
S0 = n - I0; % Initial number of susceptible individuals
R0 = 0; % Initial number of recovered individuals
% Time span
tspan = [0 10]; % From t = 0 to t = 10
% Define the system of differential equations
sir_model = @(t, y) [
-a * y(1) * y(2); % dS/dt
a * y(1) * y(2) - b * y(2); % dI/dt
b * y(2) % dR/dt
];
% Solve the system using ode45
[t, y] = ode45(sir_model, tspan, [S0; I0; R0]);
% Plot the results
figure;
plot(t, y(:,1), 'b', 'LineWidth', 2); hold on;
plot(t, y(:,2), 'r', 'LineWidth', 2);
plot(t, y(:,3), 'g', 'LineWidth', 2);
xlabel('Time (days)');
ylabel('Number of People');
title('SIR Model of Disease Spread');
legend('Susceptible', 'Infected', 'Recovered');
grid on;