# Relative tolerance

Relative tolerance for solver tolerance calculation

Model Configuration Pane: Solver

## Description

Specify the largest acceptable solver error, relative to the size of each state during each time step. If the relative error exceeds this tolerance, the solver reduces the time step size.

At each time step, the solver:

• Calculates the value of each state

• Estimates the error in each state calculation

• Determines the acceptable error for each state using the relative tolerance, absolute tolerance, and state values

The acceptable error considered for each state on each time step is determined by either the relative tolerance or the absolute tolerance, whichever results in a larger tolerance. The solver calculates the acceptable error based on the relative tolerance by multiplying the relative tolerance and the state value.

ei = reltol * |x|,

where:

• ei is the acceptable error based on relative tolerance at that time step.

• reltol is the value specified for the Relative tolerance parameter.

• x is the state value.

When ei is larger than the value specified for the Absolute tolerance parameter, the relative tolerance determines the tolerance for that state on that time step. When the absolute tolerance is greater than ei, the absolute tolerance determines the tolerance for that state on that time step. In general, the absolute tolerance applies when the state values approach zero.

## Dependencies

To enable this parameter:

• Set the solver Type to `Variable-step`.

• Set the Solver parameter to a value other than `discrete (no continuous states)`.

## Settings

`1e-3` (default) | `auto` | positive scalar number

The relative tolerance indicates the tolerance allowed for the computational accuracy of the variable-step solver as a percentage of each state value. The default value `1e-3` indicates that the computed state value at each time step must be accurate within `0.1%`.

The default relative tolerance is appropriate for most applications. Decreasing the relative tolerance can slow simulation.

When you specify the Relative tolerance as `auto`, the software uses the default value of `1e-3`.

## Tips

To assess the accuracy of a simulation, reduce the relative tolerance to `1e-4` and simulate the model again. If the results of the two simulations are not significantly different, the solution has converged.

## Recommended Settings

The table summarizes recommended values for this parameter based on considerations related to code generation.

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyNo impact
Safety precautionNo impact

## Programmatic Use

 Parameter: `RelTol` Type: string | character vector Value: positive scalar number Default: `'1e-3'`

## Version History

Introduced before R2006a