Why doesn't ode stop when value equals zero ?

I'm working on a project for the University. I decided to use an event with ode15s solver : This solver simulates the speed and position of a car and the event makes the simulation stop as the car reaches the speed limit on a road. This solver is inside a for loop, simulating a different part of the road.
Options=odeset('Events',@eventfunction);
[T,Y,TE,YE,IE] = ode15s(@odefun,tspan,init,Options,indice,Theta,Omega,Cmax,Fmot,vref,l,lparcourue,Rho,S,Cx,f0,f2,mveh,g,atrans,btrans)
The event function's code is
function [value,isterminal,direction]=eventfunction(t,variables,indice,Theta,Omega,Cmax,Fmot,vref,l,lparcourue,Rho,S,Cx,f0,f2,mveh,g,atrans,btrans)
value=variables(2)-vref;
isterminal=1;
direction=0;
if(variables(1)>lparcourue+l)
value=0;
end
end
And odefun is defined as :
function derivee = odefun(t,variables,indice,Theta,Omega,Cmax,Fmot,vref,l,lparcourue,Rho,S,Cx,f0,f2,mveh,g,atrans,btrans)
v = variables(2);
F1 = Fmot;
F2 = Faero(Rho,S,Cx,v);
F3 = Frlt(f0,f2,mveh,g,Theta,v);
F4 =Fgrav(mveh,g,Theta);
M = me(atrans,btrans,indice,mveh);
derivee = zeros(2,1);
derivee(1) = v;
derivee(2) = (F1-F2-F3-F4)/M;
end
For the first loop, everything is OK, but during the second loop, when the speed remains the same and the solver should stop imediately, it doesn't. I first tough my value had no zero, but after removing the semicolon after "value=..." I had :
value =
0
value =
0
value =
0
value =
0
value =
0
value =
0
value =
0
value =
0
value =
0
value =
0
value =
0
T =
1.0e+005 *
0.0000
0.1000
0.2000
0.3000
0.4000
0.5000
0.6000
0.7000
0.8000
0.9000
1.0000
Y =
1.0e+006 *
0.0008 0.0000
0.1396 0.0000
0.2785 0.0000
0.4174 0.0000
0.5563 0.0000
0.6952 0.0000
0.8341 0.0000
0.9730 0.0000
1.1119 0.0000
1.2508 0.0000
1.3896 0.0000
TE =
[]
YE =
[]
IE =
[]
Can anyone explain me what is my error ? Thank you.

回答 (0 件)

カテゴリ

タグ

質問済み:

2015 年 4 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by