Solver
Solver that computes states and outputs for simulation
Model Configuration Pane: Solver
Description
The Solver parameter specifies the solver that computes 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 model implements, the solver also determines the next time step for the simulation.
When you enable the Use local solver when referencing model parameter for a referenced model, the Solver parameter for the referenced model specifies the solver to use as a local solver. The local solver solves the referenced model as a separate set of differential equations. While the top solver can be a fixed-step or variable-step solver, the local solver must be a fixed-step solver. For more information, see Use Local Solvers in Referenced Models.
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.
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. Theode45
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 theode45
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 thanode45
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 theode45
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 theode15s
solver for crude tolerances and can solve stiff problems for whichode15s
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 thanode15s
for crude tolerances and can solve stiff problems for which theode15s
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. Thedaessc
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.
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 statesThe 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 theode1be
solver as a computationally efficient fixed-step alternative to theode14x
solver.
Examples
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 use fast restart, you can change the solver for the simulation without having to recompile the model. (since R2021b)
The software uses a discrete solver for models that have no states or have only discrete states, even if you specify a continuous solver.
Recommended Settings
The table summarizes recommended values for this parameter based on considerations related to code generation.
Application | Setting |
---|---|
Debugging | No impact |
Traceability | No impact |
Efficiency | No 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