Hi Jose,
I understand that your goal is to produce a graph showing a descending exponential trend of susceptible individuals, indicating how the disease spreads through the population.
The initial code seems like infection rate is treated as static, so incorporating dynamic updates for both the infection and recovery rates is required.
To more accurately capture the exponential nature of infectious disease spread, an ‘SIR’ divides the population into three compartments (Susceptible, Infected, Recovered) and updates the counts in each compartment daily based on the transmission and recovery rates.
Typical dynamics of an SIR model, requires how the transmission rate (`beta`) and recovery rate (`gamma`) interact.
Below is the modified code incorporating these suggestions:
% Parameters
N = 2961167; % Total population
S0 = N - 10; % Initial number of susceptible individuals (assuming 10 initially infected)
I0 = 10; % Initial number of infected individuals
B = 10; % Beta = Contact Rate
d = 10; % Duration of Infection in 1 Person
R0 = 2; % Basic reproduction number
beta = B / N; % Transmission rate per individual per day
gamma = 1 / d; % Recovery rate per day
days = 477;
% Initialize arrays
S = zeros(1, days); % Susceptible
I = zeros(1, days); % Infected
R = zeros(1, days); % Recovered
S(1) = S0;
I(1) = I0;
R(1) = 0; % Initially, no one is recovered
for t = 2:days
newInfections = beta * I(t-1) * S(t-1);
newRecoveries = gamma * I(t-1);
S(t) = S(t-1) - newInfections;
I(t) = I(t-1) + newInfections - newRecoveries;
R(t) = R(t-1) + newRecoveries;
% Ensure the numbers do not exceed total population due to rounding
if S(t) < 0, S(t) = 0; end
if I(t) < 0, I(t) = 0; end
if R(t) > N, R(t) = N; end
end
% Plotting
figure;
plot(1:days, S, 'b', 'LineWidth', 2);
hold on;
plot(1:days, I, 'r', 'LineWidth', 2);
plot(1:days, R, 'g', 'LineWidth', 2);
legend('Susceptible', 'Infected', 'Recovered', 'Location', 'best');
xlabel('Days');
ylabel('Number of Individuals');
title('SIR Model Simulation over 477 Days');
grid on;
You may refer to this documentation link on SIR epidemic spread model
Hope this answers your query!