Do ODE solvers use location of root of event function in its solution even if integration isn't specified to stop?

1 view (last 30 days)
Say I want to solve an ODE with a piece-wise continuous function and I want to accrurately capture the corner point in the solution. Do I need to set the solver to stop when it reaches the corner (which is detected as an event), or can I let it keep integrating and the solver will use the presice location of the corner as a step in its solution?

Accepted Answer

Torsten
Torsten on 4 Mar 2024
Edited: Torsten on 4 Mar 2024
You will have to tell the solver to return control to the calling program once the corner point is reached. From there, you can continue integration.
If the corner point is known in advance (e.g. a certain time t*), you can integrate (without the use of an event function) from tstart to t* and restart the solver from t* to tend.
  5 Comments
Torsten
Torsten on 4 Mar 2024
Edited: Torsten on 4 Mar 2024
Your understanding is correct.
Each time your equations change (in your case even discontinuously), you have to stop integration and restart from the solution obtained so far. So you should just pass a flag to your ode function that indicates if you are in the regime before or after the event. Depending on this flag, you can set f = 0 or f = 1.
So don't use an if statement concerning sin(x) < 0 or >=0 to control the value for f, but the flag you set in the calling program which indicates whether you are before or after the event location.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!