0

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

Amin
  • 261
  • 3
  • 16
  • Your question isn't very clear. If the events function detects your zeros and stops the integration, `ode45` halts and returns its output. What more do you need? What is this flag and where exactly do you expect it to go? You might check out some of my answers to related questions that provide examples of how to use (and how not to use) event detection: [\[1\]](http://stackoverflow.com/a/15992197/2278029), [\[2\]](http://stackoverflow.com/a/16681767/2278029), [\[3\]](http://stackoverflow.com/a/20429657/2278029), and [\[4\]](http://stackoverflow.com/a/17370733/2278029). – horchler Dec 18 '13 at 15:26
  • thank you. the flag is IE in this statement [T,Y,TE,YE,IE] = solver(odefun,tspan,y0,options) I need it for some investigations of stability for numerical calculations of problem of my interest. – Amin Dec 18 '13 at 17:22

1 Answers1

1

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

am304
  • 13,758
  • 2
  • 22
  • 40