HOW CAN I PLOT THE SUM OF A LOOP AGAINST TIME TO HAVE SIX LINES OF SOLUTION ON THE GRAPH
3 views (last 30 days)
Show older comments
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
Answers (1)
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
4 Comments
Walter Roberson
on 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.
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!