Using dde23 with events option
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Torsten
2019년 4월 15일
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')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Delay Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!