Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Choosing a Solver

What Is a Solver?

A solver is a component of the Simulink software that determines the next simulation time step. In making this determination, the solver satisfies the target accuracy requirements that you specify. The Simulink product provides an extensive set of solvers, each adept at choosing the next time step for specific types of applications. The following sections explain how to choose the solver best suited to your application. For information on tailoring the selected solver to your model, see Improving Simulation Accuracy.

Choosing a Solver Type

Solvers are divided into two types: fixed-step and variable-step. Both types of solvers compute the next simulation time as the sum of the current simulation time and a quantity known as the step size. With a fixed-step solver, the step size remains constant throughout the simulation. In contrast, with a variable-step solver, the step size can vary from step to step, depending on the model dynamics. In particular, a variable-step solver reduces the step size when the model states are changing rapidly to maintain accuracy. Similarly, the variable-step solver increases the step size when the model states are changing slowly and thus avoids unnecessary steps. The Type control on the Simulink Solver configuration pane allows you to select either of these two types of solvers (see Solver Pane).

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 real-time computer system, choose a fixed-step solver to simulate the model. The rational for this decision is that real-time computer systems operate at fixed-size signal sample rates. A variable-step solver may cause the simulation to miss error conditions that can occur on a real-time computer system.

If you do not plan to deploy your model as generated code, the choice between a variable-step and a fixed-step solver depends on the dynamics of your model. A variable-step solver can shorten the time required to simulate your model significantly. A variable-step solver allows such savings because, for a given level of accuracy, the variable-step solver can dynamically adjust the step size as necessary and thus reduce the number of steps required. Whereas the fixed-step solver must use a single step size throughout the simulation based upon the accuracy requirements. In order to satisfy such requirements throughout the simulation, the solver might require a very small step.

The following model illustrates how a variable-step 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 fixed-step 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 ...]

By contrast, the variable-step solver needs to take a step only when the model actually generates an output.

[0.0 0.5 0.75 1.0 1.5 2.0 2.25 ...]

This significantly reduces the number of time steps required to simulate the model.

The variable-step discrete solver uses zero-crossing detection (see Zero-Crossing Detection) to handle continuous signals. Simulink uses this solver by default if you specify a continuous solver and if your model has no continuous states.

Choosing a Fixed-Step Solver

When you set the Type control of the Solver configuration pane to fixed-step, the adjacent Solver control allows you to choose one of the fixed-step solvers provided. The set of fixed-step solvers comprises two types of solvers: discrete and continuous. Both of these types rely upon the model blocks to compute the values of any discrete states. Blocks that define discrete states compute the values of those states at each time step. Unlike the discrete solvers, the continuous solvers compute the continuous states defined by blocks through numerical integration. Therefore, the very first step is to decide whether you need to use a discrete or a continuous solver.

If your model has no states or discrete states only, choose the fixed-step discrete solver. If your model has continuous states, you must choose either one of the explicit fixed-step continuous solvers (ode1, ode2, ode3, ode4, ode5, ode8), Explicit Fixed-Step Continuous Solversor the implicit fixed-step continuous solver (ode14x), Implicit Fixed-Step Continuous Solvers. Compared to the explicit fixed-step solvers, the ode14x implicit solver provides for high accuracy and stability but is computationally expensive.

About the Fixed-Step Discrete Solver

The fixed-step 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 size (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.

About Fixed-Step Continuous Solvers

The fixed-step continuous solvers, like the fixed-step discrete solver, compute the next simulation time by adding a fixed-size time step to the current time. For each of these steps, the continuous solvers employ 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 fixed-step continuous solvers can therefore handle models that contain both continuous and discrete states.

The two distinct types of fixed-step continuous solvers provided are: explicit and implicit solvers. Explicit solvers (see Explicit Fixed-Step Continuous 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:

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

where X is the state, DX is the state derivative, and h is the step size, and n indicates the current time step. An implicit solver (see Implicit Fixed-Step Continuous Solvers) 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,

X(n+1) - X(n) - h*DX(n+1) = 0

This type of solver requires more computation per step than an explicit solver but is also more accurate for a given step size. This solver thus can be faster than explicit fixed-step solvers for certain types of stiff systems.

Explicit Fixed-Step Continuous Solvers.   Simulink provides a set of explicit fixed-step 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 of the available solvers and the integration technique it uses.

SolverIntegration Technique

ode1

Euler's Method

ode2

Heun's Method

ode3

Bogacki-Shampine Formula

ode4

Fourth-Order Runge-Kutta (RK4) Formula

ode5

Dormand-Prince (RK5) Formula

ode8

Dormand-Prince RK8(7) Formula

The integration techniques used by the fixed-step continuous solvers trade accuracy for computational effort. 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).

As with the fixed-step discrete solver, the accuracy and the duration of a simulation driven by a fixed-step continuous solver depends 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 fixed-step solver type for a model, then by default, Simulink selects the ode3 solver which is capable of handling 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 or that the model cannot be simulated in less time with a less complex solver. Depending on the dynamics of your model, you might need to choose another solver and/or a different sample time to achieve both acceptable accuracy and an acceptable simulation time.

Implicit Fixed-Step Continuous Solvers.   This category provides one solver : ode14x. This solver uses a combination of Newton's method and extrapolation from the current value to compute the value of a model 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 Fixed-step 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.

Process for Choosing a Fixed-Step Continuous Solver

Any of the fixed-step 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 thus generally requires experimentation.

Here is the most efficient way to choose the best fixed-step solver for your model experimentally. First, use one of the variable-step solvers to simulate your model to the level of accuracy that you desire. These results will give you a good approximation of the correct simulation results. Next, use ode1 to simulate your model at the default step size for your model. Compare the results of simulating your model with ode1 with the results of simulating with the variable-step solver. If the results are the same for the specified level of accuracy, you have found the best fixed-step solver for your model, namely ode1. You can draw this conclusion because the ode1 is the simplest of the fixed-step solvers and hence yields the shortest simulation time for the current step size.

If ode1 does not give accurate results, repeat the preceding steps with each of the other fixed-step 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. First, try ode3. If it 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.

Choosing a Variable-Step Solver

When you set the Type control of the Solver configuration pane to variable-step, the Solver control allows you to choose one of the variable-step solvers. As with fixed-step solvers, the set of variable-step solvers comprises a discrete solver and a subset of continuous solvers. However, unlike the fixed-step solvers, the step size varies dynamically with the rate of change of the model states. The choice between the two types of 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.

About Variable-Step Continuous Solvers

The variable-step solvers in the Simulink product dynamically vary the step size during the simulation. They reduce the step size to increase the accuracy when the model states are changing rapidly and increase the step size to avoid unnecessary steps when the model states are changing slowly. Computing the step size at each time step adds to the computational overhead but can reduce the total number of steps, and hence the simulation time required to maintain a specified level of accuracy. This capability is particularly important for models with rapidly changing or piecewise continuous states.

Following are the variable-step continuous solvers provided. They comprise both one-step and multistep solvers.

Specifying Variable-Step Solver Error Tolerances

The solvers use standard local error control techniques to monitor the 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 state, the solver reduces the step size and tries again.

The solvers require the error for the ith state, ei, 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.

If you specify auto (the default), Simulink initially sets the absolute tolerance for each state to 1e-6. As the simulation progresses, the absolute tolerance for each state is reset to the maximum value that the state has assumed, thus far, times the relative tolerance for that state. Thus, if a state changes from 0 to 1 and the reltol is 1e-3, then by the end of the simulation the abstol is set to 1e-3 also. If a state goes from 0 to 1000, then the abstol is set 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.

The Integrator, Transfer Fcn, State-Space, and Zero-Pole 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 in this way. For example, if the global setting does not provide sufficient error control for all of your model states because they vary widely in magnitude, then you might want to set the value yourself.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS