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!

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Torsten
Torsten el 26 de En. de 2023
Movida: Torsten el 26 de En. de 2023
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 comentarios
Torsten
Torsten el 1 de Feb. de 2023
Editada: Torsten el 1 de Feb. de 2023
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

Iniciar sesión para comentar.

Más respuestas (1)

Musa Abdullahi
Musa Abdullahi el 2 de Feb. de 2023
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..

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by