Selecting Absolute Tolerance and Relative Tolerance for Simulation
RelativeTolerance to control the accuracy of integration during
simulation. Specifically, AbsoluteTolerance is used to control
the largest allowable absolute error at any step during simulation. It controls the
error when a solution is small. Intuitively, when the solution approaches 0,
AbsoluteTolerance is the threshold below which you do not worry
about the accuracy of the solution since it is effectively 0. RelativeTolerance controls the relative error of a single step of the
integrator. Intuitively, it controls the number of significant digits in a solution,
except when it is smaller than the absolute tolerance, and is the number of correct digits. For more tips on tolerances, see
Troubleshooting Simulation Problems.
At each simulation step
i, the solver estimates
the local error
e in the state
the simulation. The solver reduces the size of time step
the error of the state satisfies:
Thus at state values of larger magnitude, the accuracy is determined
RelativeTolerance. As the state values approach
zero, the accuracy is controlled by
The correct choice of values for
depending on the problem. The default values may work for first trials
of the simulation. As you adjust the tolerances, consider that there
are trade-offs between speed and accuracy:
If the simulation takes too long, you can increase (or loosen) the values of
AbsoluteToleranceat the cost of some accuracy.
If the results seem inaccurate, you can decrease (or tighten) the relative tolerance values by dividing with 10N, where N is a real positive number. But this tends to slow down the solver.
If the magnitude of the state values is high, you can decrease the relative tolerance to get more accurate results.
Absolute Tolerance Scaling
How SimBiology uses
determine the error depends on whether the AbsoluteToleranceScaling property
is enabled. By default,
enabled which means each state has its own absolute tolerance that
may increase over the course of simulation:
CSAbsTol is the
SolverOptions of the active configuration
For a state that has a nonzero initial value, the scale is the maximum magnitude over the state, as seen over the simulation thus far:
For a state that has an initial value of zero, the scale is
estimated as the state value after taking a trial step of size AbsoluteToleranceStepSize using the Euler
method. Let us call this value
If an initial state is zero and has no dynamic at time = 0, then:
Doses, events, and initial assignment rules at simulation time = 0 are not considered when calculating absolute tolerance scaling.