Info

此问题已关闭。 请重新打开它进行编辑或回答。

Using ODE23s

1 次查看(过去 30 天)
SA
SA 2019-4-24
关闭: MATLAB Answer Bot 2021-8-20
In the code below, y1, y2 and y3 are functions of three variabes t, x and y. y1(0,x,y) = 1 and y2(0,x,y)=y3(0,x,y)=0 are the initial conditions. But there is an exception; at y1(0,0.5,0.5) = y2(0,0.5,0.5)=0.5
How do I incorproate this in my code?
%Solving and plotting Model 4
tfinal = 10; %will vary
tRange = [0,tfinal];
y0=[1; 0; 0];%the initial conditions for I,S and R respectively
%I=y1;
%S=y2;
%R=y3;
options = odeset('Events',@myEventsFcn);
[t,y,te,ye,ie] = ode23s(@challenge215,tRange,y0,options)
plot(t,mean(y(:,1)),'k')
hold on
plot(t,mean(y(:,2)),'b')
hold on
plot(t,mean(y(:,3)),'r')
xlabel('Days')
ylabel('Population')
xlim([-inf tfinal])
ylim([0 inf])
legend('Infected', 'Susceptible', 'Recovered')
title('Solution to Ordinary Differential Equation Model 4')
function dydt=challenge215(t,y)
k = 4;
tau = 0.8;
delta = 0.2;
y1=y(:,1);
y2=y(:,2);
y3=y(:,3);
[Atilde]=GetTheMatrix(11);
dydt = [tau*y1.*y2-(1/k)*y1+delta*((1/(0.1^2))*Atilde*y1).*y2;-tau*y1.*y2-delta*((1/(0.1^2))*Atilde*y1).*y2;(1/k)*y1];
end
function [position,isterminal,direction] = myEventsFcn(t,y)
position = [y1-(10^-5); y2-(10^-5)]; % the function I is unknown
isterminal = [1; 1]; %terminate when I(t) drops below 10^-5
direction = [0; 0];
end
  1 个评论
Jan
Jan 2019-4-25
What does "y1(0,x,y) = 1" mean? What is x and y here? "% the function I is unknown"? Which function I? If you have "y1(0,0.5,0.5) = y2(0,0.5,0.5)=0.5", it is not an initial value problem anymore, but a boundary value problem, isn't it?

回答(0 个)

此问题已关闭。

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by