Solver

Solver that computes states and outputs for simulation

Model Configuration Pane: Solver

Description

Select the solver you want to use to compute the states of the model during simulation and in generated code. In the process of solving the set of ordinary differential equations that represent the system, the solver also determines the next time step for the simulation. The software provides several types of fixed-step and variable-step solvers.

Variable-Step Solvers

A variable-step solver adjusts the interval between simulation time hits where the solver computes states and outputs based on the system dynamics and specified error tolerance. For most variable-step solvers, you can configure additional parameters, including:

Fixed-Step Solvers

In general, fixed-step solvers except for `ode14x` and `ode1be` calculate the next step using this formula:

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.

For most fixed-step solvers, you can configure additional parameters, including:

Settings

`auto (Automatic solver selection)` (default) | `discrete (no continuous states)` | ...

In general, the automatic solver selection chooses an appropriate solver for each model. The choice of solver depends on several factors, including the system dynamics and the stability of the solution. For more information, see Choose a Solver.

The options available for this parameter depend on the value you select for the solver Type.

Variable-Step Solvers
`auto (Automatic solver selection)`

The software selects the variable-step solver to compute the model states based on the model dynamics. For most models, the software selects an appropriate solver.

`discrete (no continuous states)`

Use this solver only for models that contain no states or only discrete states. The `discrete` variable-step solver computes the next simulation time hit by adding a step size that depends on the rate of change for states in the model.

`ode45 (Dormand-Prince)`

When you manually select a solver, `ode45` is an appropriate first choice for most systems. The `ode45` solver computes model states using an explicit Runge-Kutta (4,5) formula, also known as the Dormand-Prince pair, for numerical integration.

`ode23 (Bogacki-Shampine)`

The `ode23` solver computes the model states using an explicit Runge-Kutta (2,3) formula, also known as the Bogacki-Shampine pair, for numerical integration.

For crude tolerance and in the presence of mild stiffness, the `ode23` solver is more efficient than the `ode45` solver.

`ode113 (Adams)`

The `ode113` solver computes the model states using a variable-order Adams-Bashforth-Moulton PECE numerical integration technique.

The `ode113` solver uses the solutions from several preceding time points to compute the current solution.

The `ode113` solver can be more efficient than `ode45` for stringent tolerances.

`ode15s (stiff/NDF)`

The `ode15s` solver computes the model states using variable-order numerical differentiation formulas (NDFs). NDFs are related to but more efficient than the backward differentiation formulas (BDFs), also known as Gear's method.

The `ode15s` solver uses the solutions from several preceding time points to compute the current solution.

The `ode15s` solver is efficient for stiff problems. Try this solver if the `ode45` solver fails or is inefficient.

`ode23s (stiff/Mod. Rosenbrock)`

The `ode23s` solver computes the model states using a modified second-order Rosenbrock formula.

The `ode23s` solver uses only the solution from the preceding time step to compute the solution for the current time step.

The `ode23s` solver is more efficient than the `ode15s` solver for crude tolerances and can solve stiff problems for which `ode15s` is ineffective.

`ode23t (mod. stiff/Trapezoidal)`

The `ode23t` solver computes the model states using an implementation of the trapezoidal rule.

The `ode23t` solver uses only the solution from the preceding time step to compute the solution for the current time step.

Use the `ode23t` solver for problems that are moderately stiff and require a solution with no numerical damping.

`ode23tb (stiff/TR-BDF2)`

The `ode23tb`solver computes the model states using a multistep implementation of TR-BDF2, an implicit Runge-Kutta formula with a trapezoidal rule first stage and a second stage that consists of a second-order backward differentiation formula. By construction, the same iteration matrix is used in both stages.

The `ode23tb` solver is more efficient than `ode15s` for crude tolerances and can solve stiff problems for which the `ode15s` solver is ineffective.

`odeN (Nonadaptive)`

The `odeN` solver uses a nonadaptive fixed-step integration formula to compute the model states as an explicit function of the current value of the state and the state derivatives approximated at intermediate points.

The nonadaptive `odeN` solver does not adjust the simulation step size to satisfy error constraints but does reduce step size in some cases for zero-crossing detection and discrete sample times.

`daessc (DAE solver for Simscape™)`

The `daessc` solver computes the model states by solving systems of differential algebraic equations modeled using Simscape. The `daessc` solver provides robust algorithms specifically designed to simulate differential algebraic equations that arise from modeling physical systems.

The `daessc` solver is available only with Simscape products.

Fixed-Step Solvers
`auto (Automatic solver selection)`

The software selects a fixed-step solver to compute the model states based on the model dynamics. For most models, the software selects an appropriate solver.

`discrete (no continuous states)`

Use this solver only for models that contain no states or only discrete states. The `discrete` fixed-step solver relies on blocks in the model to update discrete states

The discrete fixed-step solver does not support zero-crossing detection.

`ode8 (Dormand-Prince)`

The `ode8` solver uses the eighth-order Dormand-Prince 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.

`ode5 (Dormand-Prince)`

The `ode5` solver uses the fifth-order Dormand-Prince 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.

`ode4 (Runge-Kutta)`

The `ode4` solver uses the fourth-order Runge-Kutta (RK4) formula to compute the model state as an explicit function of the current value of the state and the state derivatives.

`ode3 (Bogacki-Shampine)`

The `ode3` solver computes the state of the model as an explicit function of the current value of the state and the state derivatives. The solver uses the Bogacki-Shampine Formula integration technique to compute the state derivatives.

`ode2 (Heun)`

The `ode2` solver uses the Heun integration method to compute the model state as an explicit function of the current value of the state and the state derivatives.

`ode1 (Euler)`

The `ode1` solver uses the Euler integration method to compute the model state 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 but provides comparatively less accuracy.

`ode14x (extrapolation)`

The `ode14x` solver uses a combination of Newton's method and extrapolation from the current value to compute the model state as an implicit function of the state and the state derivative at the next time step. In this 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) = 0

This 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 a fixed computational cost. You can use the `ode1be` solver as a computationally efficient fixed-step alternative to the `ode14x` solver.

Examples

expand all

Open the model `vdp`.

```mdl = "vdp"; open_system(mdl)```

To allow the software to select the solver to use for the model, specify the Type parameter as `Fixed-step` or `Variable-step`, and set the Solver parameter to `auto`. For this example, configure the software to select a variable-step solver for the model.

1. To open the Configuration Parameters dialog box, on the Modeling tab, click Model Settings.

2. On the Solver pane, set the solver Type to `Variable-step` and the Solver parameter to `auto (Automatic solver selection)`.

3. Click OK.

Alternatively, use the `set_param` function to set the parameter values programmatically.

```set_param(mdl,"SolverType","Variable-step", ... "SolverName","VariableStepAuto")```

Simulate the model. On the Simulation tab, click Run. Alternatively, use the `sim` function.

`out = sim(mdl);`

As part of initializing the simulation, the software analyzes the model to select the solver. The status bar on the bottom of the Simulink Editor indicates the selected solver on the right. For this model, the software selects the `ode45` solver.

To view more information about the selected solver parameters, click the text in the status bar that indicates the selected solver. The Solver Information menu shows the selected solver and the selected value for the Max step size parameter. For this simulation, the solver uses a maximum step size of `0.4`.

If you want to lock down the solver selection and maximum step size, explicitly specify the solver parameter values. In the Solver information menu, click Accept suggested settings .

Alternatively, you can use the `set_param` function to specify the parameter values programmatically.

`set_param(mdl,"SolverName","ode45","MaxStep","0.4")`

After you explicitly specify the parameter values, the solver information in the status bar and Solver information menu no longer indicate that the parameter values are automatically selected.

Tips

• The optimal solver balances acceptable accuracy with the shortest simulation time. Identifying the optimal solver for a model requires experimentation. For more information, see Choose a Solver.

• When you configure a referenced model to use a local solver, the top solver can be a variable-step or fixed-step solver, and the local solver must be a fixed-step solver. For more information, see Use Local Solvers in Referenced Models.

• When you use fast restart, you can change the solver for the simulation without having to recompile the model.

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

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 precaution`Discrete (no continuous states)`

Programmatic Use

 Parameter: `SolverName` or `Solver` Type: string | character vector Variable-Step Solver Values: `'VariableStepAuto'` | `'VariableStepDiscrete'` | `'ode45'` | `'ode23'` | `'ode113'` | `'ode15s'` | `'ode23s'` | `'ode23t'` | `'ode23tb'` | `'odeN'` | `'daessc'` Fixed-Step Solver Values: `'FixedStepAuto'` | ` 'FixedStepDiscrete'` | `'ode8'` | `'ode5'` | `'ode4'` |` 'ode3'` | `'ode2'` | `'ode1'` | `'ode14x'` | `'ode1be'` Default: `'VariableStepAuto'`

Version History

Introduced before R2006a