Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Using ODE23s

1 visualizzazione (ultimi 30 giorni)
SA
SA il 24 Apr 2019
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commento
Jan
Jan il 25 Apr 2019
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?

Risposte (0)

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by