I need to have a better understanding about how to define ODE events. What I know is that if I have my ODE defined as

[t,q,te,qe,ie] = ode45(odefun,tspan,q0(:,1),options);
options = odeset('Events',@events);
function [value,isterminal,direction] = events(t,q)
    value = ...; 
    isterminal = ...; 
    direction = ...; 

I need to define the value as a function of q and tin such a way that it goes to zero. So, for example, if I want to find when v = 0 I just need to write

value = q(2);
isterminal = 1;
direction = 0;

But is writing

value = [q(2),q(2)];
isterminal = [1,1];
direction = [1,-1];

equivalent to the previous formulation?

And what if I want to stop the integration when q(2) < toll? I mean, is it possible to stop the integration if q(2) is very close to xero but not exactly zero? (I am thinking about something like the Karnopp model used to model the sticking condition in this picture http://vibrationacoustics.asmedigitalcollection.asme.org/data/journals/jvacek/28878/s_011506vaj1.jpeg)

Also, in the vector te and qe I have the time instants and the solution values when the events are encountered. If I have 2 different events to be satisfied (lets call them type 1 and type 2) but I want to plot only the events of type 1, how can I tell Matlab?

Finally, what checks can I perform to be sure the ODE correctly identifies all the events?

  • 1
    $\begingroup$ For Matlab-specific advice, you might consider asking your question at Matlab Central (in the Newsgroup or Answers sections). $\endgroup$
    – GeoMatt22
    Nov 5 '15 at 3:06

Browse other questions tagged or ask your own question.