How can I use ode events in MATLAB?

1 view (last 30 days)
Olgola
Olgola on 5 Nov 2015
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 = ...;
end
I need to define the value as a function of q and t in 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 plot )
Finally, what checks can I perform to be sure the ODE correctly identifies all the events?

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!