This is because derivatives that are calculated using if -stations, module operations ( abs() ), or things like block step functions, delta triangles, etc., introduce gaps in the value of the solution or its derivative (s ), which leads to kinks, jumps, inflection points, etc.
This means that the ODE solution has a complete change in behavior at the appropriate times. What integrators of variable steps will do is
- define it
- recognize that they will not be able to use the information directly behind the “problem point”
- reduce the pitch and repeat from above until the problem meets the accuracy requirements
Consequently, there will be many unsuccessful steps and step size reductions near problem points, which will negatively affect the overall integration time.
However, variable step integrators will continue to get good results. Permanent step integrators are not a good way to solve this problem, because they cannot detect such problems in the first place (there is no error rating).
What you can do is simply divide the problem into several parts. If you know in advance at which points in time changes will occur, you simply start a new integration for each interval, each time using the output of the previous integration as the initial value for the next.
If you don’t know in advance where the problems will be, you can use this very nice feature in Matlab ODE solvers called event functions (see the documentation ). You allow one of the Matlab solvers to detect an event (sign change in a derivative, state change in if -statement or something else) and stop integration when such events are detected. Then start a new integration, starting from the last time and with the initial conditions of the previous integration, as before, until the end time is reached.
Thus, there will still be a small penalty in the overall execution time, since Matlab will try to pinpoint the location of the event. However, it is still much better than incorporating blind integration when it comes to runtime and accuracy of results.