Main Content

Check and Improve Simulation Accuracy

Check Simulation Accuracy

  1. Simulate the model over a reasonable time span.

  2. Reduce either the relative tolerance to 1e-4 (the default is 1e-3) or the absolute tolerance.

  3. Simulate the model again.

  4. Compare the results from both simulations.

If the results are not significantly different, the solution has converged.

If the simulation misses significant behavior at the start, reduce the initial step size to ensure that the simulation does not step over that behavior.

Unstable Simulation Results

When simulation results become unstable over time,

  • The system can be unstable.

  • If you are using the ode15s solver, try restricting the maximum order to 2 (the maximum order for which the solver is A-stable). You can also try using the ode23s solver.

Inaccurate Simulation Results

If simulation results are not 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 in the Solver pane of model configuration parameters or adjust it for individual states in the function block parameters of the Integrator block.

  • If reducing the absolute tolerances does not improve simulation accuracy enough, reduce the size of the relative tolerance parameter. This change reduces the acceptable error and forces smaller step sizes and more steps.

Certain modeling constructs can also produce unexpected or inaccurate simulation results.

  • A Source block that inherits sample time can produce different simulation results if, for example, the sample times of the downstream blocks are modified (see How Propagation Affects Inherited Sample Times).

  • A Derivative block found in an algebraic loop can result in a loss in solver accuracy.

Related Examples

More About