## Solver

### Description

Select the solver you want to use to compute the states of the model during simulation or code generation.

**Category:** Solver

### Settings

Select from these types:

The default setting for new models is
`VariableStepAuto`

.

#### Fixed-step Solvers

**Default:**
`FixedStepAuto`

In general, all fixed-step solvers except for `ode 14x`

calculate the next step as:

*X*(*n*+1) =
*X*(*n*) + *h*
*dX*(*n*)

where *X* is the state, *h* is the step size, and *dX* is the state derivative. *dX*(*n*) is calculated by a particular algorithm using one or more
derivative evaluations depending on the order of the method.

`auto`

Computes the state of the model using a fixed-step solver that auto solver selects. At the time the model compiles,

`auto`

changes to a fixed-step solver that auto solver selects based on the model dynamics. Click on the solver hyperlink in the lower right corner of the model to accept or change this selection.`ode3 (Bogacki-Shampine)`

Computes the state of the model at the next time step as an explicit function of the current value of the state and the state derivatives, using the Bogacki-Shampine Formula integration technique to compute the state derivatives.

`Discrete (no continuous states)`

Computes the time of the next time step by adding a fixed step size to the current time.

Use this solver for models with no states or discrete states only, using a fixed step size. Relies on the model's blocks to update discrete states.

The accuracy and length of time of the resulting simulation depends on the size of the steps taken by the simulation: the smaller the step size, the more accurate the results but the longer the simulation takes.

**Note**The fixed-step discrete solver cannot be used to simulate models that have continuous states.

`ode8 (Dormand-Prince RK8(7))`

Uses the eighth-order Dormand-Prince formula to compute the model state at the next time step as an explicit function of the current value of the state and the state derivatives approximated at intermediate points.

`ode5 (Dormand-Prince)`

Uses the fifth-order Dormand-Prince formula to compute the model state at the next time step as an explicit function of the current value of the state and the state derivatives approximated at intermediate points.

`ode4 (Runge-Kutta)`

Uses the fourth-order Runge-Kutta (RK4) formula to compute the model state at the next time step as an explicit function of the current value of the state and the state derivatives.

`ode2 (Heun)`

Uses the Heun integration method to compute the model state at the next time step as an explicit function of the current value of the state and the state derivatives.

`ode1 (Euler)`

Uses the Euler integration method to compute the model state at the next time step as an explicit function of the current value of the state and the state derivatives. This solver requires fewer computations than a higher order solver. However, it provides comparatively less accuracy.

`ode14x (extrapolation)`

Uses a combination of Newton's method and extrapolation from the current value to compute the model's state at the next time step, as an

*implicit*function of the state and the state derivative at the next time step. In the following example,*X*is the state,*dX*is the state derivative, and*h*is the step size:*X*(*n*+1) -*X*(*n*)-*h**dX*(*n*+1) = 0This solver requires more computation per step than an explicit solver, but is more accurate for a given step size.

`ode1be (Backward Euler)`

The ode1be solver is a Backward Euler type solver that uses a fixed number of Newton iterations, and incurs only a fixed cost. You can use the

`ode1be`

solver as a computationally inexpensive fixed-step alternative to the`ode14x`

solver.

#### Variable-step Solvers

**Default:**
`VariableStepAuto`

`auto`

Computes the state of the model using a variable-step solver that auto solver selects. At the time the model compiles,

`auto`

changes to a variable-step solver that auto solver selects based on the model dynamics. Click on the solver hyperlink in the lower right corner of the model to accept or change this selection.`ode45 (Dormand-Prince)`

Computes the model's state at the next time step using an explicit Runge-Kutta (4,5) formula (the Dormand-Prince pair) for numerical integration.

`ode45`

is a one-step solver, and therefore only needs the solution at the preceding time point.Use

`ode45`

as a first try for most problems.`Discrete (no continuous states)`

Computes the time of the next step by adding a step size that varies depending on the rate of change of the model's states.

Use this solver for models with no states or discrete states only, using a variable step size.

`ode23 (Bogacki-Shampine)`

Computes the model's state at the next time step using an explicit Runge-Kutta (2,3) formula (the Bogacki-Shampine pair) for numerical integration.

`ode23`

is a one-step solver, and therefore only needs the solution at the preceding time point.`ode23`

is more efficient than`ode45`

at crude tolerances and in the presence of mild stiffness.`ode113 (Adams)`

Computes the model's state at the next time step using a variable-order Adams-Bashforth-Moulton PECE numerical integration technique.

`ode113`

is a multistep solver, and thus generally needs the solutions at several preceding time points to compute the current solution.`ode113`

can be more efficient than`ode45`

at stringent tolerances.`ode15s (stiff/NDF)`

Computes the model's state at the next time step using variable-order numerical differentiation formulas (NDFs). These are related to, but more efficient than the backward differentiation formulas (BDFs), also known as Gear's method.

`ode15s`

is a multistep solver, and thus generally needs the solutions at several preceding time points to compute the current solution.`ode15s`

is efficient for stiff problems. Try this solver if`ode45`

fails or is inefficient.`ode23s (stiff/Mod. Rosenbrock)`

Computes the model's state at the next time step using a modified Rosenbrock formula of order 2.

`ode23s`

is a one-step solver, and therefore only needs the solution at the preceding time point.`ode23s`

is more efficient than`ode15s`

at crude tolerances, and can solve stiff problems for which`ode15s`

is ineffective.`ode23t (Mod. stiff/Trapezoidal)`

Computes the model's state at the next time step using an implementation of the trapezoidal rule with a “free” interpolant.

`ode23t`

is a one-step solver, and therefore only needs the solution at the preceding time point.Use

`ode23t`

if the problem is only moderately stiff and you need a solution with no numerical damping.`ode23tb (stiff/TR-BDF2)`

Computes the model's state at the next time step using a multistep implementation of TR-BDF2, an implicit Runge-Kutta formula with a trapezoidal rule first stage, and a second stage consisting of a backward differentiation formula of order two. By construction, the same iteration matrix is used in evaluating both stages.

`ode23tb`

is more efficient than`ode15s`

at crude tolerances, and can solve stiff problems for which`ode15s`

is ineffective.`odeN (fixed step with zero crossings)`

Uses an

*N*order fixed step integration formula to compute the model state as an explicit function of the current value of the state and the state derivatives approximated at intermediate points.^{th}While the solver itself is a fixed step solver, Simulink

^{®}will reduce the step size at zero crossings for accuracy.`daessc (Solver for Simscape™)`

Computes the model's state at the next time step by solving systems of differential-algebraic equations resulting from Simscape models.

`daessc`

provides robust algorithms specifically designed to simulate differential-algebraic equations arising from modeling physical systems.`daessc`

is only available with Simscape products.

### Tips

Identifying the optimal solver for a model requires experimentation. For an in-depth discussion, see Solver Selection Criteria.

With fast restart, you do not need to recompile the model if you change the solver. You can pick appropriate solvers during runtime without having to go through an expensive recompilation process.

The optimal solver balances acceptable accuracy with the shortest simulation time.

Simulink software uses a discrete solver for a model with no states or discrete states only, even if you specify a continuous solver.

A smaller step size increases accuracy, but also increases simulation time.

The degree of computational complexity increases for

`ode`

, as`n`

increases.`n`

As computational complexity increases, the accuracy of the results also increases.

### Dependencies

Selecting the `ode1 (Euler)`

, ```
ode2
(Huen)
```

, `ode 3 (Bogacki-Shampine)`

,
`ode4 (Runge-Kutta)`

, ```
ode 5
(Dormand-Prince)
```

, ```
ode 8 (Dormand Prince
RK8(7))
```

or `Discrete (no continuous states)`

fixed-step solvers enables the following parameters:

**Fixed-step size (fundamental sample time)****Periodic sample time constraint****Treat each discrete rate as a separate task****Automatically handle rate transition for data transfers****Higher priority value indicates higher task priority**

Selecting `odeN (fixed step with zero crossings)`

variable-step solver enables the following parameters:

**Max step size****Integration method**

Selecting `ode14x (extrapolation)`

enables the following
parameters:

**Fixed-step size (fundamental sample time)****Extrapolation order****Number of Newton's iterations****Periodic sample time constraint****Treat each discrete rate as a separate task****Automatically handle rate transition for data transfers****Higher priority value indicates higher task priority**

Selecting `ode1be (Backward Euler)`

enables the following
parameters:

**Fixed-step size (fundamental sample time)****Number of Newton's iterations****Periodic sample time constraint****Treat each discrete rate as a separate task****Automatically handle rate transition for data transfers****Higher priority value indicates higher task priority**

Selecting the `Discrete (no continuous states)`

variable-step
solver enables the following parameters:

**Max step size****Automatically handle rate transition for data transfers****Higher priority value indicates higher task priority****Zero-crossing control****Time tolerance****Number of consecutive zero crossings****Algorithm**

Selecting `ode45 (Dormand-Prince)`

, ```
ode23
(Bogacki-Shampine)
```

, `ode113 (Adams)`

, or
`ode23s (stiff/Mod. Rosenbrock)`

enables the following
parameters:

**Max step size****Min step size****Initial step size****Relative tolerance****Absolute tolerance****Shape preservation****Number of consecutive min steps****Automatically handle rate transition for data transfers****Higher priority value indicates higher task priority****Zero-crossing control****Time tolerance****Number of consecutive zero crossings****Algorithm**

Selecting `ode15s (stiff/NDF)`

, ```
ode23t (Mod.
stiff/Trapezoidal
```

`)`

, or ```
ode23tb
(stiff/TR-BDF2)
```

enables the following parameters:

**Max step size****Min step size****Initial step size****Solver reset method****Number of consecutive min steps****Relative tolerance****Absolute tolerance****Shape preservation****Maximum order****Automatically handle rate transition for data transfers****Higher priority value indicates higher task priority****Zero-crossing control****Time tolerance****Number of consecutive zero crossings****Algorithm**

### Command-Line Information

Parameter: `SolverName` or
`Solver` |

Value: ```
'VariableStepAuto' |
'VariableStepDiscrete' | 'ode45' | 'ode23' | 'ode113' | 'ode15s' | 'ode23s' |
'ode23t' | 'ode23tb' | 'daessc' | 'FixedStepAuto' | 'FixedStepDiscrete' |'ode8'|
'ode5' | 'ode4' | 'ode3' | 'ode2' | 'ode1' | 'ode14x'
``` |

Default:
`'VariableStepAuto` |