Discontinuous ODE . Why solvers dont reduce step size?

Ive been tryng to solve an edo, but no matter which solver I use ( ode45, ode23, ode113, ode15s, ode23s,...) i ve got a wrong solution. The equation is:
dy = (Qin - Qout) / (pi * Rt ^ 2); Qout = siphon * C * sqrt(2 * g * y(1)) * pi * r ^ 2; Siphon can be 0 or 1. I ve got a solution using a solver with a fixed small step size. My question is: why the solvers were not able to reduce the step size when the variable siphon changes his value? thanks

4 Comments

Is siphon a function of time?
Maybe we can come to an answer if we see your code.
Best wishes
Torsten.
Thanks for answering
Here s my code:
function dy = Plinyode(t,y)
global siphon Rt = 0.05; r = 0.007; yhi = 0.1; ylo = 0.025; C = 0.6; g = 9.81; Qin = 0.00005;
if y(1) <= ylo
siphon = 0;
elseif y(1) >= yhi
siphon = 1;
end
Qout = siphon * C * sqrt(2 * g * y(1)) * pi * r ^ 2;
dy = (Qin - Qout) / (pi * Rt ^ 2);
global siphon
siphon = 0;
tspan = [0 100]; y0 = 0;
[tp,yp]=ode45(@Plinyode,tspan,y0);
plot(tp,yp)
xlabel('time, (s)')
ylabel('water level in tank, (m)')
Best wishes
You don't treat the case where ylo <= y(1) <= yhi.
And following Jan Simon's comment: It might be better to use MATLAB's "event"-option than to switch the variable "siphon" by the if-statement.
Best wishes
Torsten.

Sign in to comment.

 Accepted Answer

See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047. Matlab's integrators cannot handle non-smooth functions.
What a pitty that TMW included an example with a linear interpolation in the docs: https://www.mathworks.com/help/matlab/ref/ode45.html#bu3l43b . Not smart.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 18 May 2017

Commented:

on 22 May 2017

Community Treasure Hunt

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

Start Hunting!