Borrar filtros
Borrar filtros

Using dde23 with events option

1 visualización (últimos 30 días)
SA
SA el 15 de Abr. de 2019
Comentada: SA el 16 de Abr. de 2019
Can someone kindly check this code for me?
I can't seem to find my error. I can't plot the graph because my dimensions are unequal.
%Solving and plotting Model 3
xfinal = 60; %will vary
xRange = [0,xfinal];
y0=[0.005; 1-0.005; 0];%the initial conditions for I,S and R respectively
%I=y(1);
%S=y(2);
%R=y(3);
options = ddeset('Events',@myEventsFcn);
sol = dde23(@challenge213,4,@ddex1hist,xRange,options)
plot(sol.x,sol.y(:,1),'k')
hold on
plot(sol.x,sol.y(:,2),'b')
hold on
plot(sol.x,sol.y(:,3),'r')
xlabel('Days')
ylabel('Population')
xlim([-inf xfinal])
ylim([0 inf])
legend('Infected', 'Susceptible', 'Recovered')
title('Solution to Ordinary Differential Equation Model 3')
function h = ddex1hist(x)
h = [0;1;0];
end
function dydx = challenge213(x,y,Z)
k = 4;
m = 0.8;
ylag1 = Z(:,1);
%ylag2 = Z(:,2);
dydx = [m*y(1)*y(2) - m*ylag1(1)*ylag1(2); -m*y(1)*y(2); m*ylag1(1)*ylag1(2)];
end
function [position,isterminal,direction] = myEventsFcn(x,y,Z)
position = [y(1)-(10^-5); y(2)-(10^-5); y(3)]; % the function I is unknown
isterminal = [1; 1; 1]; %terminate when I(t) drops below 10^-5
direction = [0; 0; 0];
end
thank you

Respuesta aceptada

Torsten
Torsten el 15 de Abr. de 2019
plot(sol.x,sol.y(1,:),'k')
hold on
plot(sol.x,sol.y(2,:),'b')
hold on
plot(sol.x,sol.y(3,:),'r')
  1 comentario
SA
SA el 16 de Abr. de 2019
It worked. Thank you Torsten.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Delay Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by