Hi, i am trying plot my thesis graph using dde23 but i keep on getting this error, derivative and history function have different lengths.. HELP PLEASE!

function Hassan
lags = 0.2;
tspan = [0,60];
sol = dde23(@ddehs, lags, @hshist, tspan);
time = sol.x;
S = sol.y(1,:);
I = sol.y(2,:);
V = sol.y(3,:);
figure;
plot(time,S,'r')
xlabel('Time (Years)'); ylabel('Susceptible Human Population');
legend('S_h')
figure;
plot(time,I,'b')
xlabel('Time (Years'); ylabel('Infected Human Population');
legend('I_h')
figure;
plot(time,V,'b')
xlabel('Time (Years'); ylabel('Vaccinated Human Population');
legend('V_h')
end
function dydt = ddehs(~,y,z)
Kh = 10000; muH = 0.0066;
aH = 0.02; Bh = 0.3;
muD = 0.08; tau = 0.2;
wH = 1;
ylag1 = z(:,1);
dydt = [ muH*Kh - (muH + aH)*y(1) - Bh*y(1)*ylag1*exp(-muH*tau)
Bh*y(1)*ylag1*exp(-muD*tau) - (muH + wH)*y(2)
aH*y(1) - muH*y(3) ];
end
function s = hshist(~)
s = ones(3,1);
end

 Accepted Answer

z(:,1) is a 3x1 vector with z(1,1) = y1(t-0.02), z(2,1) = y2(t-0.02) and z(3,1) = y3(t-0.02),
You have to decide which of the three delay terms you want to insert in dydx(1) and dydx(2).

9 Comments

Hi, thank you for your help.. how can i plot both equation on same graph??
Why both ? You have three.
plot(sol.x,sol.y)
Or use
time = sol.x;
S = sol.y(1,:);
I = sol.y(2,:);
V = sol.y(3,:);
hold on
plot(time,S,'r')
plot(time,I,'b')
plot(time,V,'g')
xlabel('Time (Years)');
legend('S_h','I_h','V_h')
hold off
Thank you so much.. How can i show the effect of one parameter on one population by varying the parameter values.. (like effects of varying delay values on infected humans populations)?
Make a loop over the parameter values, call dde23 for each parameter value and save the results.
After you have exited the loop, plot the solution curves.
Hi, I have tried ploting my modified model equations but the graph is not displaying..
here is my code...
function Modified
lags = 0.2;
tspan = [0,60];
sol = dde23(@ddehs, lags, @hshist, tspan);
time = sol.x;
S = sol.y(1,:);
I = sol.y(2,:);
V = sol.y(3,:);
T = sol.y(4,:);
R = sol.y(5,:);
hold on
plot(time,I,'b')
plot(time,S,'r')
plot(time,V,'g')
plot(time,T,'k')
plot(time,R,'y')
xlabel('Time (Years)');
legend('S_h','I_h','V_h','T_h','R_h')
hold off
end
function dydt = ddehs(~,y,z)
Lh = 100000; muh = 0.06;
uh = 0.09; Bh = 0.5;
mud = 0.08; tau = 0.2;
ah = 1; mh = 0.2; bh =0.5; rh = 0.5;
dh = 0.21;
ylag1 = z(3,1);
dydt = [ Lh - Bh*y(1)*ylag1*exp(-mud*tau)-(muh + uh)*y(1) + bh*y(3) + dh*y(5)
Bh*y(1)*ylag1*exp(-mud*tau) - (muh + mh + ah)*y(2)
uh*y(1) - (bh + muh)*y(3)
ah*y(2) - (muh + rh)*y(4)
rh*y(4) - (muH + dh)*y(5) ];
end
function s = hshist(~)
s = ones(3,1);
end
Can you please give me a hint on how to go about that loop?... trying to show the effect of one parameter on one population..
lags = [0.2,2.0,6.0,12.0];
time = 0:0.1:60;
for i = 1:numel(lags)
tspan = [0,60];
sol = dde23(@ddehs, lags(i), @hshist, tspan);
yint = deval(sol,time);
S(i,:) = yint(1,:);
I(i,:) = yint(2,:);
V(i,:) = yint(3,:);
end
figure;
plot(time,S,'r')
xlabel('Time (Years)'); ylabel('Susceptible Human Population');
legend('S_h')
figure;
plot(time,I,'b')
xlabel('Time (Years)'); ylabel('Infected Human Population');
legend('I_h')
figure;
plot(time,V,'b')
xlabel('Time (Years)'); ylabel('Vaccinated Human Population');
legend('V_h')
function dydt = ddehs(~,y,z)
Kh = 10000; muH = 0.0066;
aH = 0.02; Bh = 0.3;
muD = 0.08; tau = 0.2;
wH = 1;
ylag1 = z(2,1);
dydt = [ muH*Kh - (muH + aH)*y(1) - Bh*y(1)*ylag1*exp(-muH*tau)
Bh*y(1)*ylag1*exp(-muD*tau) - (muH + wH)*y(2)
aH*y(1) - muH*y(3) ];
end
function s = hshist(~)
s = ones(3,1);
end

Sign in to comment.

More Answers (1)

Hi, I have been trying to plot the graph of the equations from the existing journal i am working on.. but shape i am getting is not the same with what they have.. below is a screenshot of their graph and what i am obtaining from my code..
and this is what my plot
Can you please point out my error here? Thank you so much..

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Products

Release

R2020a

Tags

Community Treasure Hunt

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

Start Hunting!