MATLAB Answers

What are the general guidelines for choosing ODE solvers for simulating a model using Simulink?

18 views (last 30 days)
I want to know the basic procedure to be followed in choosing solvers from Configuration Parameters while simulating a Simulink model.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 30 May 2013
Sometimes different solver configuration cause simulation results to change a lot. It means the model should be tuned a little bit to get good simulation results. The following are some heuristic rules to help user select the solver and verify the simulation results and tune the model.
1 Variable-step solver:
When simulating a model, if possible, always start with a variable step solver (a good start is ODE45) with zero crossing (if applicable) turned on. If the simulation result is as expected, change to other variable step solver. If the model is well designed, the simulation results given by different solver should be pretty close. In this case, the system probably is a non-stiff system. If the simulation is very slow or the results are not consistent with different implicit solver, try changing to implicit solver such as ODE15s. If the implicit solver works better than the explicit solver, the system may be a stiff system.
In this stage, the tolerance and min/max step size should be changed to see if the simulation result is stable. For example, change the relative tolerance from 1e-3 to 1e-6. The two simulation results should be pretty close. If not, change the tolerance from 1e-6 to 1e-9 and so on. Once a set of parameters gives a stable simulation result, use this simulation result as a base line.
2. Fixed step solver:
The same idea of selecting/configure variable step solver applies to fixed step solver. Start with a fixed step size and a solver, simulate, then reduce the step size by a factor of 10 to see if the results are close.
3. Ode14x is an implicit fixed step solver. If the variable step solver used is ODE15s or other implicit solver, when switching to fixed step solver, ode14x may be a start.
4. Fixed step solvers don’t support zero crossing yet. If the system has a lot of zero crossing, consider reducing the step size.
5. For system with switching, it is highly possible that these switching may introduce discontinuities and chattering in the system. To remove the chattering, consider adding a hysteresis after the original switching signal. For example, if the original switching condition is a==0, then change it to: if abs(a)<0.001. The hystersis band size is selected by trial and error.
6. When checking the simulation results, don’t check the final answer. Please also check the value of internal states and make sure they are in the correct range. For example, don’t just check the output from an integrator; also check its derivative input since integrator works like a low pass filter, it may filter out some of the unexpected high frequency components in the input signal.
7. Remove algebraic loops by using state port or some memory blocks.
8. If possible, try not using numerical derivative (du/dt ) in the model.

Community Treasure Hunt

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

Start Hunting!