Question

Suppose I am trying to solve a system of differential equations using an ode solver in MATLAB.

Suppose also that I have defined an events functions to locate three different events which are all terminal.

I have noticed that on some occasions the ie quantity that is returned upon the location of one of the events (ie is the index of the event that stopped the solver, in my case it could be 1, 2 or 3) is not always a single number but a vector with two elements (usually these elements are identical)

In those cases that ie is NOT scalar, is it ie(1) or ie(2) that stopped the solver?

Was it helpful?

Solution

Actually, I noticed that this happens when the simulation stops due to a terminal event and then starts again from the same point (initial time and conditions) that stopped.

Technically, due to arithmetic inaccuracies in the initial conditions MATLAB re-detects the same event that made it previously stop. MATLAB is incapable of distinguishing this, BUT it is programmed NOT to stop in terminal events that occur just after the first successful step (see odezero function for reference). It does record the event, though.

Consequently, the next time that the ode stops due to a terminal event, the ie is appended with the new index and that's when (and why) ie is a vector with two elements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top