Amin
Amin

Reputation: 261

MATLAB event function to pass me a flag when it sends one to ode45 at the same time

I am using ode45 and want to stop integration by event function when the solution hits zero. What I need is event function to return ME a "flag" . That means whenever event sends a stop sign to ode45 to stop, this stop sign (whatever it is) is sent to me as well.

thanks

Upvotes: 0

Views: 652

Answers (1)

am304
am304

Reputation: 13876

From the ode45 documentation:

[T,Y,TE,YE,IE] = solver(odefun,tspan,y0,options) solves as above while also finding where functions of (t,y), called event functions, are zero. For each event function, you specify whether the integration is to terminate at a zero and whether the direction of the zero crossing matters. Do this by setting the 'Events' property to a function, e.g., events or @events, and creating a function [value,isterminal,direction] = events(t,y). For the ith event function in events,

  • value(i) is the value of the function.
  • isterminal(i) = 1, if the integration is to terminate at a zero of this event >function and 0 otherwise.
  • direction(i) = 0 if all zeros are to be computed (the default), +1 if only the zeros where the event function increases, and -1 if only the zeros where the event function decreases.

Corresponding entries in TE, YE, and IE return, respectively, the time at which an event occurs, the solution at the time of the event, and the index i of the event function that vanishes.

The event function is set through the options argument, with the odeset function

Upvotes: 1

Related Questions