HOW CAN I PLOT THE SUM OF A LOOP AGAINST TIME TO HAVE SIX LINES OF SOLUTION ON THE GRAPH

1 Ansicht (letzte 30 Tage)
HOW CAN I PLOT SUM OF THE SOLUTION ON THE GRAPH WITH THE LOOP AGAINST TIME SO THAT I WILL HAVE SIX LINES ON THE GRAPH.(i.e 0:300:1500)
IVSTAB()
function IVSTAB()
global beta_c theta eta2 eta3 eta4 epsilon kappa phi omega gamma tau alpha mu delta P
clear all
clc
tspan=[0 300];
x0=0:300:1500;
x1=0:300:1500;
x2=0:300:1500;
x3=0:300:1500;
beta_c=0.75;theta=1.2; eta2=1.3; eta3=0.033; eta4=1.5;P =209; epsilon=1.0; kappa=0.01; phi=0.01; omega=0.22; gamma=0.9858475; tau=0.89; alpha=0.3; mu=0.022; delta=0.0;
delta=0.0;
figure
hold on
for k=1:length(x0)
for j=1:length(x1)
for l=1:length(x2)
for m=1:length(x3)
[t,x]=ode45(@model, tspan,[9561;x0(k);x1(j);82; x2(l); x3(m)]);
plot(t,x(:,2)+x(:,3)+x(:,4)+x(:,5)+x(:,6),'color',[.5 .5 .5],'linewidth',1.5)%'color',[.5 .5 .5] for gray or 'g' for green
xlabel('Time (Days)','Interpreter','Latex'),ylabel('Infectious Individuals','Interpreter','Latex')
box on
set(gca, 'FontSize', 12);
end
end
end
end
format long
function dx = model(t,x)
dx = [0;0;0;0;0;0];
dx(1)= P - ((beta_c*(x(2) + theta*x(3) + eta2*x(4) + eta3*x(5) + eta4*x(6)) * x(1))/(x(1) + x(2) + x(3) + x(4) + x(5) + x(6))) - mu*x(1);
dx(2) = ((epsilon*beta_c*(x(2) + theta*x(3) + eta2*x(4) + eta3*x(5) + eta4*x(6)) * x(1))/(x(1) + x(2) + x(3) + x(4) + x(5) + x(6))) - (kappa+mu)*x(2) + phi*x(5);
dx(3)= (((1-epsilon)*beta_c*(x(2) + theta*x(3) + eta2*x(4) + eta3*x(5) + eta4*x(6)) * x(1))/(x(1) + x(2) + x(3) + x(4) + x(5) + x(6)))+ (1 - omega)*kappa*x(2) - (gamma + mu)*x(3);
dx(4)= omega*kappa*x(2) - (tau + mu)*x(4) + gamma*x(3);
dx(5)= (1 - alpha)*tau*x(4) - (phi + mu)*x(5);
dx(6)= alpha*x(4) -(mu+delta)*x(6);
end
end

Antworten (1)

Walter Roberson
Walter Roberson am 21 Nov. 2022
Your third variable, x2, is the only one that is length 6, so I had to guess that you wanted the sum of all the entries for each x2 value.
IVSTAB()
function IVSTAB()
global beta_c theta eta2 eta3 eta4 epsilon kappa phi omega gamma tau alpha mu delta P
format long
tspan = 0:300;
x0=0:300:600;
x1=0:300:600;
x2=0:300:1500;
x3=0:300:1500;
num_x0 = length(x0);
num_x1 = length(x1);
num_x2 = length(x2);
num_x3 = length(x3);
ntspan = length(tspan);
totals = zeros(ntspan, num_x2);
beta_c=0.75;theta=1.2; eta2=1.3; eta3=0.033; eta4=1.5;P =209; epsilon=1.0; kappa=0.01; phi=0.01; omega=0.22; gamma=0.9858475; tau=0.89; alpha=0.3; mu=0.022; delta=0.0;
delta=0.0;
figure
hold on
for k = 1:num_x0
for j = 1:num_x1
for l = 1:num_x2
for m = 1:num_x3
[t,x]=ode45(@model, tspan,[9561;x0(k);x1(j);82; x2(l); x3(m)]);
total = x(:,2)+x(:,3)+x(:,4)+x(:,5)+x(:,6);
totals(:,l) = totals(:,l) + total;
end
end
end
end
plot(tspan, totals, 'color', [.5 .5 .5], 'linewidth',1.5) %'color',[.5 .5 .5] for gray or 'g' for green
xlabel('Time (Days)','Interpreter','Latex');
ylabel('total Infectious Individuals','Interpreter','Latex')
box on
set(gca, 'FontSize', 12);
function dx = model(t,x)
dx = [0;0;0;0;0;0];
dx(1)= P - ((beta_c*(x(2) + theta*x(3) + eta2*x(4) + eta3*x(5) + eta4*x(6)) * x(1))/(x(1) + x(2) + x(3) + x(4) + x(5) + x(6))) - mu*x(1);
dx(2) = ((epsilon*beta_c*(x(2) + theta*x(3) + eta2*x(4) + eta3*x(5) + eta4*x(6)) * x(1))/(x(1) + x(2) + x(3) + x(4) + x(5) + x(6))) - (kappa+mu)*x(2) + phi*x(5);
dx(3)= (((1-epsilon)*beta_c*(x(2) + theta*x(3) + eta2*x(4) + eta3*x(5) + eta4*x(6)) * x(1))/(x(1) + x(2) + x(3) + x(4) + x(5) + x(6)))+ (1 - omega)*kappa*x(2) - (gamma + mu)*x(3);
dx(4)= omega*kappa*x(2) - (tau + mu)*x(4) + gamma*x(3);
dx(5)= (1 - alpha)*tau*x(4) - (phi + mu)*x(5);
dx(6)= alpha*x(4) -(mu+delta)*x(6);
end
end
  4 Kommentare
Walter Roberson
Walter Roberson am 21 Nov. 2022
You want 6 curves output, and you want each of those curves to be the sum of something. Which of the variables should be the one that you want one line for each value? And please be explicit about which variables you want the summation to be over.
The code I posted in my Answer does not care how many values are in x0, x1, or x3, and will produce one output line for each value in x2.
SAHEED AJAO
SAHEED AJAO am 24 Nov. 2022
Is there a way to do it so that the first curve out will be the summation of x2,x3,x4,x5 and x6 when x0,x1,x2, and x3 are all zero at the initial time, then followed by when x0,x1,x2,x3 are all equal to 300 and so on till the values get to 1500?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by