Info

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

Including conditions within ode 45

1 次查看(过去 30 天)
SP
SP 2018-1-16
关闭: MATLAB Answer Bot 2021-8-20
I have a system of equations where a,b,c,d,e,k are constant parameters. In this system the behaviour of y(1) and y(2) over time would be it would reach a peak and then decline. What I want is when both y(1) and y(2) are less than 1, I want y(1) and y(2) to be set to zero. That is I don't want a rebound to happen once y(1) and y(2) reach low values. Also, I want the solutions to y(3) to start after certain time (tr) has passed. Up until that time the value of y(3) should remain at the initial level. This is the function that I am solving using ode45 and this is how I have implemented those conditions.
[t,y]=ode45(@model,0:time,[100000,450,10^-12]
function s= model(t,y)
s=zeros(3,1);
tr=50;
if y(1)<1 && y(2)<1
y(1)=0;
y(2)=0;
else
s(1)=a*y(1)*(1-((y(2)+y(1))/k))-b*y(3)*y(1);
s(2)=a*y(2)*(1-((y(1)+y(2))/k))-b*y(5)*y(2);
if t>tr
s(3)=c*(d-y(5))*(y(1)+y(2))-e*y(5);
else
s(3)=0;
end
Can someone please let me know if I have done this correctly or is there any other method to do it

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by