| Simulink® | ![]() |
| On this page… |
|---|
Simulation performance and accuracy can be affected by many things, including the model design and choice of configuration 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 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.
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 Maximum order.
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.
Your model contains a scope viewer that displays a large number of data points. Try adjusting the viewer parameter settings that can affect performance. For more information, see How Scope Viewer Parameter Settings Can Affect Performance.
To check your simulation accuracy, run the simulation over a reasonable time span. Then, either reduce the relative tolerance to 1e-4 (the default is 1e-3) or reduce the absolute tolerance and run it again. Compare the results of both simulations. If the results are not significantly different, you can feel confident that the solution has converged.
If the simulation misses significant behavior at its start, reduce the initial step size to ensure that the simulation does not step over the significant behavior.
If the simulation results become unstable over time,
Your system might be unstable.
If you are using ode15s, you might need to restrict the maximum order to 2 (the maximum order for which the solver is A-stable) or try using the ode23s solver.
If the simulation results do not appear to be accurate,
For a model that has states whose values approach zero, if the absolute tolerance parameter is too large, the simulation takes too few steps around areas of near-zero state values. Reduce this parameter value or adjust it for individual states in the Integrator dialog box.
If reducing the absolute tolerances does not sufficiently improve the accuracy, reduce the size of the relative tolerance parameter to reduce the acceptable error and force smaller step sizes and more steps.
Certain modeling constructs can also produce unexpected or inaccurate simulation results.
A Source block that inherits its sample time can produce different simulation results if, for example, the sample times of the downstream blocks are modified (see "Propagating Sample Times Back to Source Blocks").
A Derivative block found in an algebraic loop can result in a loss in solver accuracy.
![]() | Diagnosing Simulation Errors | Running a Simulation Programmatically | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |