Using Simulink |
 |
Improving Simulation Performance and Accuracy
Simulation performance and accuracy can be affected by many things, including the model design and choice of simulation parameters.
The solvers handle most model simulations accurately and efficiently with their default parameter values. However, some models yield better results if you adjust solver and simulation parameters. Also, if you know information about your model's behavior, your simulation results can be improved if you provide this information to the solver.
Speeding Up the Simulation
Slow simulation speed can have many causes. Here are a few:
- Your model includes a MATLAB Fcn block. When a model includes a MATLAB Fcn block, the MATLAB interpreter is called at each time step, drastically slowing down the simulation. Use the built-in Fcn block or Math Function block whenever possible.
- Your model includes an M-file S-function. M-file S-functions also cause the MATLAB interpreter to be called at each time step. Consider either converting the S-function to a subsystem or to a C-MEX file S-function.
- Your model includes a Memory block. Using a Memory block causes the variable-order solvers (
ode15s
and ode113
) to be reset back to order 1 at each time step.
- The maximum step size is too small. If you changed the maximum step size, try running the simulation again with the default value (
auto
).
- Did you ask for too much accuracy? The default relative tolerance (0.1% accuracy) is usually sufficient. For models with states that go to zero, if the absolute tolerance parameter is too small, the simulation can take too many steps around the near-zero state values. See the discussion of error in Error Tolerances.
- The time scale might be too long. Reduce the time interval.
- The problem might be stiff but you are using a nonstiff solver. Try using
ode15s
.
- The model uses sample times that are not multiples of each other. Mixing sample times that are not multiples of each other causes the solver to take small enough steps to ensure sample time hits for all sample times.
- The model contains an algebraic loop. The solutions to algebraic loops are iteratively computed at every time step. Therefore, they severely degrade performance. For more information, see Algebraic Loops.
- Your model feeds a Random Number block into an Integrator block. For continuous systems, use the Band-Limited White Noise block in the Sources library.
| Creating Custom Simulation Error Messages | | Improving Simulation Accuracy |  |