If..else statement in a function - how to obtain the graph

I'm using ode45 to solve a pair of ODEs which include an element with an 'if...then' statement. When I try to solve, MATLAB doesn't seem to take account of this command.
This is my function:
function dxdt = newode1(t,x)
%x(1)->Xo
%x(2)->Xi
a = 3600;
mu = 3600;
x(1)=1-x(2);
if (0 <= t) && (t <= 0.3)
Dt1 = 1;
else
Dt1 = 0;
end
Uh = 10*max(x(1)-x(2),0)*Dt1;
dxdt=zeros(2,1);
dxdt(1)=(a*x(1).^2)./(x(1).^2+x(2).^2)+Uh-mu.*x(1);
dxdt(2)=(a*x(2).^2)./(x(1).^2+x(2).^2)-Uh-mu.*x(2);
end
and what I put in the command line:
tspan = [0 1];
x0 = [0 1];
[t,x] = ode45(@(t,x) newode1(t,x), tspan, x0);
plot(t,x(:,1),'-o',t,x(:,2),'-.')
This is the graph I get
And this is what I should get
Note that I have denoted X_0(t) as x(1) and X_1(t) as x(2). What am I doing wrong?

4 Comments

upload your code instead of a picture
What are the differential equations you are coding?
Please post an image or PDF and a description of the simulation.
Essentially the ODEs describe the change in volume of water in the inner layer (X_I) and outer layer (X_O) of the Venus Flytrap's upper leaf (trap). This movement of water is what allows the trap to snap shut. I am looking to solve the ODEs for time for different parts of the prey capture process (which will have different conditions - eg. for the closing process, where the trap moves from an open to semi-closed state, we have u_a and u_c equal to zero.) These u terms are water transport rates driven by various gradients, α is the water supply rate from the roots, μ is the water consumption rate and C is the charge.
equations.png
Here is a link to the article: https://www.tandfonline.com/doi/pdf/10.4161/psb.5.8.12136?needAccess=true the mathematical modelling stuff starts at the end of page 6.
(In the question I posted I just considered the closing process mentioned above, i.e. where u_a and u_c =0, for simplicity.)

Sign in to comment.

Answers (0)

Asked:

on 28 Nov 2018

Commented:

on 28 Nov 2018

Community Treasure Hunt

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

Start Hunting!