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

1 view (last 30 days)
SAHEED AJAO on 21 Nov 2022
Commented: SAHEED AJAO on 24 Nov 2022
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
##### 2 CommentsShowHide 1 older comment
SAHEED AJAO on 21 Nov 2022
Oh, I forgot. I have included and updated it. Thanks

Walter Roberson on 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
SAHEED AJAO on 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?

### Categories

Find more on Graphics Performance in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by