How to store values in a matrix to plot later?

조회 수: 2 (최근 30일)
James Metz
James Metz 2020년 11월 25일
편집: James Metz 2020년 11월 26일
I am trying to create a pandemic simulation to account for several variables, store these values in a single matrix, and then plot these values on a graph. I'm having some trouble with this. My graphs are not showing up as expected and I'm not sure what the problem is. Please help. Thanks.
Here's my code:
%Epidemic Simulation
%Author: James Metz
%Date: Nov 15, 2020
%Define Natural Paramteres:
p = 0.0144; %Natural Birth Rate (Davidson County)
u = 0.008; %Natural Death Rate (Davidson County)
f = 0.03; %Infection Rate
r = 0.075; %Recovery Rate
m = 0.0001; %Death due to Infection Rate
v = 0.092; %Vaccination Rate
%Define Evaluation Time Paramteres:
dt = 1; %Time increments (days)
tEnd = 365; %Simulation length (days)
t = 1:dt:tEnd;
%Initialize Variables:
I = 10; %Initial infected population
R = 0; %Initial recovered population
S = 692587; %Initial susceptible population
I_1d = zeros(1, tEnd);
R_1d = zeros(1, tEnd);
S_1d = zeros(1, tEnd);
S_1d(1) = 692587;
I_1d(1) = 10;
R_1d(1) = 0;
%Loop through times:
for idx = 2:dt:tEnd
%Initialization:
S = S_1d(idx - 1);
R = R_1d(idx - 1);
I = I_1d(idx - 1);
%Find changes in population numbers
dS_dt = -f*S*I - S*u - S*v + S*p; %Drop in unifected population
dI_dt = f*S*I - r*I - m*I - u*I; %Drop in infected population
dR_dt = r*I + S*v - u*R; %Gain in Recovered population
%Store new values:
S_1d(idx) = S_1d(idx-1) + dS_dt;
R_1d(idx) = R_1d(idx-1) + dR_dt;
I_1d(idx) = I_1d(idx-1) + dI_dt;
end
figure(1)
subplot(2,2,1)
plot(t, S_1d)
xlabel('Time (days)')
ylabel('Susceptible Population')
title('Drop in Susceptible Population due to Infection')
subplot(2,2,2)
plot(t, R_1d)
xlabel('Time (days)')
ylabel('Recovered Population')
title('Recovery Rate of Infected Persons')
subplot(2,2,3)
plot(t, I_1d)
xlabel('Time (days)')
ylabel('Infected Population')
title('Infection Rate of Susceptible Persons')
subplot(2, 2, 4)
plot(t, S_1d, 'green')
plot(t, R_1d, 'Blue')
plot(t, I_1d, 'red')
my graphs look like this:

답변 (1개)

Sibi
Sibi 2020년 11월 25일
Try this , you should not multiply the infected population to sucesptible population
dS_dt = -f*S - S*u - S*v + S*p;
dI_dt = f*S - r*I - m*I- u*I;
dR_dt = r*I + S*v- u*R;
  댓글 수: 1
James Metz
James Metz 2020년 11월 26일
편집: James Metz 2020년 11월 26일
The equations are based on the SIR model.
See link for more information: https://www.ijraset.com/fileserve.php?FID=9443
But thank you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Biological and Health Sciences에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by