Info

This question is closed. Reopen it to edit or answer.

Including conditions within ode 45

1 view (last 30 days)
SP
SP on 16 Jan 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (0)

Community Treasure Hunt

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

Start Hunting!