Documentation Center 
On this page… 

A solver is a component of the Simulink^{®} software. The Simulink product provides an extensive library of solvers, each of which determines the time of the next simulation step and applies a numerical method to solve the set of ordinary differential equations that represent the model. In the process of solving this initial value problem, the solver also satisfies the accuracy requirements that you specify. To help you choose the solver best suited for your application, Choosing a Solver Type provides background on the different types of solvers while Choosing a FixedStep Solver and Choosing a VariableStep Solver provide guidance on choosing a specific fixedstep or variablestep solver, respectively.
The following table summarizes the types of solvers in the Simulink library and provides links to specific categories. All of these solvers can work with the algebraic loop solver.
Discrete  Continuous  VariableOrder  

FixedStep  Explicit  Not Applicable  Explicit FixedStep Continuous Solvers  Not Applicable 
Implicit  Not Applicable  Implicit FixedStep Continuous Solvers  Not Applicable  
VariableStep  Explicit  Choosing a VariableStep Solver  Explicit Continuous VariableStep Solvers  VariableOrder Solvers 
Implicit  Implicit Continuous VariableStep Solvers  VariableOrder Solvers 
Note:

For information on tailoring the selected solver to your model, see Improve Simulation Accuracy
The Simulink library of solvers is divided into two major types in the Solver Pane: fixedstep and variablestep. You can further divide the solvers within each of these categories as: discrete or continuous, explicit or implicit, onestep or multistep, and singleorder or variableorder.
Both fixedstep and variablestep solvers compute the next simulation time as the sum of the current simulation time and a quantity known as the step size. With a fixedstep solver, the step size remains constant throughout the simulation. In contrast, with a variablestep solver, the step size can vary from step to step, depending on the model dynamics. In particular, a variablestep solver increases or reduces the step size to meet the error tolerances that you specify. The Type control on the Simulink Solver configuration pane allows you to select either of these two types of solvers.
The choice between the two types depends on how you plan to deploy your model and the model dynamics. If you plan to generate code from your model and run the code on a realtime computer system, choose a fixedstep solver to simulate the model because you cannot map the variablestep size to the realtime clock.
If you do not plan to deploy your model as generated code, the choice between a variablestep and a fixedstep solver depends on the dynamics of your model. A variablestep solver might shorten the simulation time of your model significantly. A variablestep solver allows this savings because, for a given level of accuracy, the solver can dynamically adjust the step size as necessary and thus reduce the number of steps. Whereas the fixedstep solver must use a single step size throughout the simulation based upon the accuracy requirements. To satisfy these requirements throughout the simulation, the fixedstep solver might require a very small step.
The following modelmodel shows how a variablestep solver can shorten simulation time for a multirate discrete model.
This model generates outputs at two different rates: every 0.5 s and every 0.75 s. To capture both outputs, the fixedstep solver must take a time step every 0.25 s (the fundamental sample time for the model).
[0.0 0.25 0.5 0.75 1.0 1.25 1.5 ...]
By contrast, the variablestep solver needs to take a step only when the model generates an output.
[0.0 0.5 0.75 1.0 1.5 ...]
This scheme significantly reduces the number of time steps required to simulate the model.
If you wish to achieve evenly spaced steps, you must use the format 0.4*[0.0: 100.0] rather than [0.0:0.4:40].
When you set the Type control of the Solver configuration pane to fixedstep or to variablestep, the adjacent Solver control allows you to choose a specific solver. Both sets of solvers comprise two types: discrete and continuous. Discrete and continuous solvers rely on the model blocks to compute the values of any discrete states. Blocks that define discrete states are responsible for computing the values of those states at each time step. However, unlike discrete solvers, continuous solvers use numerical integration to compute the continuous states that the blocks define . Therefore, when choosing a solver, you must first determine whether you need to use a discrete solver or a continuous solver.
If your model has no continuous states, then Simulink switches to either the fixedstep discrete solver or the variablestep discrete solver. If instead your model has continuous states, you must choose a continuous solver from the remaining solver choices based on the dynamics of your model. Otherwise, an error occurs.
While you can apply either an implicit or explicit continuous solver, the implicit solvers are designed specifically for solving stiff problems whereas explicit solvers are used to solve nonstiff problems. A generally accepted definition of a stiff system is a system that has extremely different time scales. Compared to the explicit solvers, the implicit solvers provide greater stability for oscillatory behavior, but they are also computationally more expensive; they generate the Jacobian matrix and solve the set of algebraic equations at every time step using a Newtonlike method. To reduce this extra cost, the implicit solvers offer a Solver Jacobian method parameter that allows you to improve the simulation performance of implicit solvers. See Choosing a Jacobian Method for an Implicit Solver for more information.
The Simulink solver library provides both onestep and multistep solvers. The onestep solvers estimate y(t_{n}) using the solution at the immediately preceding time point, y(t_{n1}), and the values of the derivative at a number of points between t_{n} and t_{n1}. These points are minor steps.
The multistep solvers use the results at several preceding time steps to compute the current solution. Simulink provides one explicit multistep solver, ode113, and one implicit multistep solver, ode15s. Both are variablestep solvers.
Two variableorder solvers, ode15s and ode113, are part of the solver library. These solvers use multiple orders to solve the system of equations. Specifically, the implicit, variablestep ode15s solver uses firstorder through fifthorder equations while the explicit, variablestep ode113 solver uses firstorder through thirteenthorder. For ode15s, you can limit the highest order applied via the Maximum Order parameter. For more information, see Maximum Order.
The fixedstep discrete solver computes the time of the next simulation step by adding a fixed step size to the current time. The accuracy and the 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 are but the longer the simulation takes. You can allow the Simulink software to choose the size of the step (the default) or you can choose the step size yourself. If you choose the default setting of auto, and if the model has discrete sample times, then Simulink sets the step size to the fundamental sample time of the model. Otherwise, if no discrete rates exist, Simulink sets the size to the result of dividing the difference between the simulation start and stop times by 50.
Note If you try to use the fixedstep discrete solver to update or simulate a model that has continuous states, an error message appears. Thus, selecting a fixedstep solver and then updating or simulating a model is a quick way to determine whether the model has continuous states. 
The fixedstep continuous solvers, like the fixedstep discrete solver, compute the next simulation time by adding a fixedsize time step to the current time. For each of these steps, the continuous solvers use numerical integration to compute the values of the continuous states for the model. These values are calculated using the continuous states at the previous time step and the state derivatives at intermediate points (minor steps) between the current and the previous time step. The fixedstep continuous solvers can, therefore, handle models that contain both continuous and discrete states.
Note In theory, a fixedstep continuous solver can handle models that contain no continuous states. However, that would impose an unnecessary computational burden on the simulation. Consequently, Simulink uses the fixedstep discrete solver for a model that contains no states or only discrete states, even if you specify a fixedstep continuous solver for the model. 
Two types of fixedstep continuous solvers that Simulink provides are: explicit and implicit. (See Explicit versus Implicit Solvers for more information). The difference between these two types lies in the speed and the stability. An implicit solver requires more computation per step than an explicit solver but is more stable. Therefore, the implicit fixedstep solver that Simulink provides is more adept at solving a stiff system than the fixedstep explicit solvers.
Explicit FixedStep Continuous Solvers. Explicit solvers compute the value of a state at the next time step as an explicit function of the current values of both the state and the state derivative. Expressed mathematically for a fixedstep explicit solver:
where x is the state, Dx is a solverdependent function that estimates the state derivative, h is the step size, and n indicates the current time step.
Simulink provides a set of explicit fixedstep continuous solvers. The solvers differ in the specific numerical integration technique that they use to compute the state derivatives of the model. The following table lists each solver and the integration technique it uses.
Solver  Integration Technique  Order of Accuracy 

ode1  Euler's Method  First 
ode2  Heun's Method  Second 
ode3  BogackiShampine Formula  Third 
ode4  FourthOrder RungeKutta (RK4) Formula  Fourth 
ode5  DormandPrince (RK5) Formula  Fifth 
ode8  DormandPrince RK8(7) Formula  Eighth 
The table lists the solvers in order of the computational complexity of the integration methods they use, from the least complex (ode1) to the most complex (ode8).
None of these solvers has an error control mechanism. Therefore, the accuracy and the duration of a simulation depends directly on the size of the steps taken by the solver. As you decrease the step size, the results become more accurate, but the simulation takes longer. Also, for any given step size, the more computationally complex the solver is, the more accurate are the simulation results.
If you specify a fixedstep solver type for a model, then by default, Simulink selects the ode3 solver, which can handle both continuous and discrete states with moderate computational effort. As with the discrete solver, if the model has discrete rates (sample times), then Simulink sets the step size to the fundamental sample time of the model by default. If the model has no discrete rates, Simulink automatically uses the result of dividing the simulation total duration by 50. Consequently, the solver takes a step at each simulation time at which Simulink must update the discrete states of the model at its specified sample rates. However, it does not guarantee that the default solver accurately computes the continuous states of a model. Therefore, you might need to choose another solver, a different fixed step size, or both to achieve acceptable accuracy and an acceptable simulation time.
Implicit FixedStep Continuous Solvers. An implicit fixedstep solver computes the state at the next time step as an implicit function of the state at the current time step and the state derivative at the next time step. In other words:
Simulink provides one implicit fixedstep solver : ode14x. This solver uses a combination of Newton's method and extrapolation from the current value to compute the value of a state at the next time step. You can specify the number of Newton's method iterations and the extrapolation order that the solver uses to compute the next value of a model state (see Fixedstep size (fundamental sample time)). The more iterations and the higher the extrapolation order that you select, the greater the accuracy you obtain. However, you simultaneously create a greater computational burden per step size.
Any of the fixedstep continuous solvers in the Simulink product can simulate a model to any desired level of accuracy, given a small enough step size. Unfortunately, it generally is not possible, or at least not practical, to decide a priori which combination of solver and step size will yield acceptable results for the continuous states in the shortest time. Determining the best solver for a particular model generally requires experimentation.
Following is the most efficient way to choose the best fixedstep solver for your model experimentally.
Choose error tolerances. For more information, see Specifying Error Tolerances for VariableStep Solvers.
Use one of the variablestep solvers to simulate your model to the level of accuracy that you desire. Start with ode45. If your model runs slowly, your problem might be stiff and need an implicit solver. The results of this step give a good approximation of the correct simulation results and the appropriate fixed step size.
Use ode1 to simulate your model at the default step size for your model. Compare the simulation results for ode1 with the simulation for the variablestep solver. If the results are the same for the specified level of accuracy, you have found the best fixedstep solver for your model, namely ode1. You can draw this conclusion because ode1 is the simplest of the fixedstep solvers and hence yields the shortest simulation time for the current step size.
If ode1 does not give satisfactory results, repeat the preceding steps with each of the other fixedstep solvers until you find the one that gives accurate results with the least computational effort. The most efficient way to perform this task is to use a binary search technique:
Try ode3.
If ode3 gives accurate results, try ode2. If ode2 gives accurate results, it is the best solver for your model; otherwise, ode3 is the best.
If ode3 does not give accurate results, try ode5. If ode5 gives accurate results, try ode4. If ode4 gives accurate results, select it as the solver for your model; otherwise, select ode5.
If ode5 does not give accurate results, reduce the simulation step size and repeat the preceding process. Continue in this way until you find a solver that solves your model accurately with the least computational effort.
When you set the Type control of the Solver configuration pane to Variablestep, the Solver control allows you to choose one of the variablestep solvers. As with fixedstep solvers, the set of variablestep solvers comprises a discrete solver and a subset of continuous solvers. However, unlike the fixedstep solvers, the step size varies dynamically based on the local error.
The choice between the two types of variablestep solvers depends on whether the blocks in your model define states and, if so, the type of states that they define. If your model defines no states or defines only discrete states, select the discrete solver. In fact, if a model has no states or only discrete states, Simulink uses the discrete solver to simulate the model even if you specify a continuous solver. If the model has continuous states, the continuous solvers use numerical integration to compute the values of the continuous states at the next time step.
The variablestep solvers in the Simulink product dynamically vary the step size during the simulation. Each of these solvers increases or reduces the step size using its local error control to achieve the tolerances that you specify. Computing the step size at each time step adds to the computational overhead but can reduce the total number of steps, and the simulation time required to maintain a specified level of accuracy.
You can further categorize the variablestep continuous solvers as: onestep or multistep, singleorder or variableorder, and explicit or implicit. (See Choosing a Solver Type for more information.)
The explicit variablestep solvers are designed for nonstiff problems. Simulink provides three such solvers: ode45, ode23, and ode113.
ODE Solver  OneStep Method  Multistep Method  Order of Accuracy  Method 

ode45  X  Medium  RungeKutta, DormandPrince (4,5) pair  
ode23  X  Low  RungeKutta (2,3) pair of Bogacki & Shampine  
ode113  X  Variable, Low to High  PECE Implementation of AdamsBashforthMoutlon 
If your problem is stiff, try using one of the implicit variablestep solvers: ode15s, ode23s, ode23t, or ode23tb.
ODE Solver  OneStep Method  Multistep Method  Order of Accuracy  Solver Reset Method  Max. Order  Method 

ode15s  X  Variable, Low to Medium  X  X  Numerical Differentiation Formulas (NDFs)  
ode23s  X  Low  Secondorder, modified Rosenbrock formula  
ode23t  X  Low  X  Trapezoidal rule using a "free" interpolant  
ode23tb  X  Low  X  TRBDF2 
Solver Reset Method. For three of the stiff solvers — ode15s, ode23t, and ode23tb— a dropdown menu for the Solver reset method appears on the Solver Configuration pane. This parameter controls how the solver treats a reset caused, for example, by a zerocrossing detection. The options allowed are Fast and Robust. The former setting specifies that the solver does not recompute the Jacobian for a solver reset, whereas the latter setting specifies that the solver does. Consequently, the Fast setting is faster computationally but might use a small step size for certain cases. To test for such cases, run the simulation with each setting and compare the results. If there is no difference, you can safely use the Fast setting and save time. If the results differ significantly, try reducing the step size for the fast simulation.
Maximum Order. For the ode15s solver, you can choose the maximum order of the numerical differentiation formulas (NDFs) that the solver applies. Since the ode15s uses first through fifthorder formulas, the Maximum order parameter allows you to choose 1 through 5. For a stiff problem, you may want to start with order 2.
Tips for Choosing a VariableStep Implicit Solver. The following table provides tips relating to the application of variablestep implicit solvers. For an example comparing the behavior of these solvers, see sldemo_solverssldemo_solvers.
Both the variablestep discrete and continuous solvers use zerocrossing detection (see ZeroCrossing Detection) to handle continuous signals.
Local Error. The variablestep solvers use standard control techniques to monitor the local error at each time step. During each time step, the solvers compute the state values at the end of the step and determine the local error—the estimated error of these state values. They then compare the local error to the acceptable error, which is a function of both the relative tolerance (rtol) and the absolute tolerance (atol). If the local error is greater than the acceptable error for any one state, the solver reduces the step size and tries again.
The Relative tolerance measures the error relative to the size of each state. The relative tolerance represents a percentage of the state value. The default, 1e3, means that the computed state is accurate to within 0.1%.
Absolute tolerance is a threshold error value. This tolerance represents the acceptable error as the value of the measured state approaches zero.
The solvers require the error for the ith state, e_{i}, to satisfy:
The following figure shows a plot of a state and the regions in which the relative tolerance and the absolute tolerance determine the acceptable error.
Absolute Tolerances. Your model has a global absolute tolerance that you can set on the Solver pane of the Configuration Parameters dialog box. This tolerance applies to all states in the model. You can specify auto or a real scalar. If you specify auto (the default), Simulink initially sets the absolute tolerance for each state to 1e6. As the simulation progresses, the absolute tolerance for each state resets to the maximum value that the state has assumed so far, times the relative tolerance for that state. Thus, if a state changes from 0 to 1 and reltol is 1e3, then by the end of the simulation, abstol becomes 1e3 also. If a state goes from 0 to 1000, then abstol changes to 1.
If the computed setting is not suitable, you can determine an appropriate setting yourself. You might have to run a simulation more than once to determine an appropriate value for the absolute tolerance.
Several blocks allow you to specify absolute tolerance values for solving the model states that they compute or that determine their output:
The absolute tolerance values that you specify for these blocks override the global settings in the Configuration Parameters dialog box. You might want to override the global setting if, for example, the global setting does not provide sufficient error control for all of your model states because they vary widely in magnitude. The block absolute tolerance can be set to:
auto
–1 (same as auto)
real scalar
real vector (having a dimension equal to the number of corresponding continuous states in the block)
Tips. If you do choose to set the absolute tolerance, keep in mind that too low of a value causes the solver to take too many steps in the vicinity of nearzero state values. As a result, the simulation is slower.
On the other hand, if you choose too high of an absolute tolerance, your results can be inaccurate as one or more continuous states in your model approach zero.
Once the simulation is complete, you can verify the accuracy of your results by reducing the absolute tolerance and running the simulation again. If the results of these two simulations are satisfactorily close, then you can feel confident about their accuracy.
For implicit solvers, Simulink must compute the solver Jacobian, which is a submatrix of the Jacobian matrix associated with the continuous representation of a Simulink model. In general, this continuous representation is of the form:
The Jacobian, J, formed from this system of equations is:
In turn, the solver Jacobian is the submatrix, .
Sparsity of Jacobian. For many physical systems, the solver Jacobian J_{x} is sparse, meaning that many of the elements of J_{x} are zero.
Consider the following system of equations:
From this system, you can derive a sparsity pattern that reflects the structure of the equations. The pattern, a Boolean matrix, has a 1 for each that appears explicitly on the righthand side of an equation. You thereby attain:
As discussed in Full and Sparse Perturbation Methods and Full and Sparse Analytical Methods respectively, the Sparse Perturbation Method and the Sparse Analytical Method may be able to take advantage of this sparsity pattern to reduce the number of computations necessary and thereby improve performance.
When you choose an implicit solver from the Solver pane of the Configuration Parameters dialog box, a parameter called Solver Jacobian method and a dropdown menu appear. This menu has five options for computing the solver Jacobian: auto, Sparse perturbation, Full perturbation, Sparse analytical, and Full analytical.
Note: If you set Automatic solver parameter selection to warning or error in the Solver Diagnostics pane, and you choose a different solver method than Simulink, you might receive a warning or an error. 
Limitations. The solver Jacobian methods have the following limitations associated with them.
If you select an analytical Jacobian method, but one or more blocks in the model do not have an analytical Jacobian, then Simulink applies a perturbation method.
If you select sparse perturbation and your model contains data store blocks, Simulink applies the full perturbation method.
The default setting for the Solver Jacobian method is auto. Selecting this choice causes Simulink to perform a heuristic to determine which of the remaining four methods best suits your model. This algorithm is depicted in the following flowchart.
Because the sparse methods are beneficial for models having a large number of states, the heuristic chooses a sparse method if more than 50 states exist in your model. The logic also leads to a sparse method if you specify ode23s because, unlike other implicit solvers, ode23s generates a new Jacobian at every time step. A sparse analytical or a sparse perturbation method is, therefore, highly advantageous. The heuristic also ensures that the analytical methods are used only if every block in your model can generate an analytical Jacobian.
The full perturbation method was the standard numerical method that Simulink used to solve a system. For this method, Simulink solves the full set of perturbation equations and uses LAPACK for linear algebraic operations. This method is costly from a computational standpoint, but it remains the recommended method for establishing baseline results.
The sparse perturbation method attempts to improve the runtime performance by taking mathematical advantage of the sparse Jacobian pattern. Returning to the sample system of three equations and three states,
The solver Jacobian is:

It is, therefore, necessary to perturb each of the three states three times and to evaluate the derivative function three times. For a system with n states, this method perturbs the states n times.
By applying the sparsity pattern and perturbing states x_{1} and x _{2} together, this matrix reduces to:

The solver can now solve columns 1 and 2 in one sweep. While the sparse perturbation method saves significant computation, it also adds overhead to compilation. It might even slow down the simulation if the system does not have a large number of continuous states. A tipping point exists for which you obtain increased performance by applying this method. In general, systems having a large number of continuous states are usually sparse and benefit from the sparse method.
The sparse perturbation method, like the sparse analytical method, uses UMFPACK to perform linear algebraic operations. Also, the sparse perturbation method supports both RSim and Rapid Accelerator mode.
The full and sparse analytical methods attempt to improve performance by calculating the Jacobian using analytical equations rather than the perturbation equations. The sparse analytical method, also uses the sparsity information to accelerate the linear algebraic operations required to solve the ordinary differential equations.
For details on how to access and interpret the sparsity pattern in MATLAB^{®}, see sldemo_metrosldemo_metro.
While the sparse perturbation method supports RSim, the sparse analytical method does not. Consequently, regardless of which sparse method you select, any generated code uses the sparse perturbation method. This limitation applies to Rapid Accelerator mode as well.