Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 36 ยท Getting Started

Simulation Time and Solvers: Fixed-Step vs Variable-Step

Understand Simulink simulation time, fixed-step and variable-step solvers, step size, ode45, ode3 and error tolerances, and see how step size changes accuracy.

A model describes how a system changes. The solver is the algorithm that actually computes that change, by moving a clock forward in small steps and updating the system's states at each step. Choosing the right solver and step size is one of the first practical skills in Simulink, because the wrong choice gives either wrong answers or painfully slow runs.

Simulink is not available on this site. The settings below are those of the real product; the Python stand-ins reproduce the numerical ideas.

Where the settings live

Open Modeling > Model Settings (or press Ctrl+E) and select Solver. The main controls are:

Setting Meaning Default
Start time / Stop time Simulated time span 0 / 10.0
Solver selection: Type Variable-step or Fixed-step Variable-step
Solver Algorithm (auto, ode45, ode23, ode15s, ode3, ode4, discrete...) auto
Max step size, Min step size Limits for variable-step solvers auto
Relative tolerance Allowed relative error 1e-3
Absolute tolerance Allowed error near zero auto
Fixed-step size Step for fixed-step solvers auto

The Stop time field on the Simulation tab changes the same value as the dialog.

Fixed-step versus variable-step

A fixed-step solver advances time by a constant amount h: t = 0, h, 2h, .... It is simple, predictable and required for real-time targets and generated code, because the work per step is the same every time.

A variable-step solver changes h as it goes. When signals change quickly it takes small steps; when nothing happens it takes large ones. It estimates the error at each step and shrinks h to stay within the tolerances. It is the best choice for desktop simulation of continuous or hybrid systems, and it can locate events (zero crossings) precisely.

Fixed-step vs variable-step

Fixed-step Same step every time
Variable-step Step adapts to the signal
Code generation Needs fixed-step
Desktop sims Variable-step shines

Pick by purpose, not by habit.

1 / 2

Choosing a solver

  • auto (the default): Simulink picks a suitable solver for the model. With only discrete blocks it chooses a discrete solver, otherwise typically ode45 (variable-step).
  • ode45 (Dormand-Prince): a good general-purpose choice for non-stiff problems.
  • ode23: lower order, can be better for crude tolerances or mildly stiff problems.
  • ode15s and ode23t: for stiff systems, where states evolve at very different speeds (fast electrical dynamics next to slow thermal ones).
  • ode1 (Euler), ode2 (Heun), ode3 (Bogacki-Shampine), ode4 (Runge-Kutta): fixed-step solvers. ode3 is the common default for fixed-step.
  • discrete (no continuous states): for models with no continuous blocks.

The number in odeN is the order: higher order is more accurate for the same step size but costs more evaluations per step.

Step size and accuracy

Take the simple system dx/dt = -x with x(0) = 1. The exact answer is x(t) = e^(-t). The Euler method updates x(k+1) = x(k) + h*f(x(k)). A smaller h gives a smaller error, at the price of more steps.

Python Stand-in: Euler step size versus accuracy (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With h = 1 Euler lands exactly on 0 (a very wrong answer), while h = 0.01 gets within about 2e-4 of the true value (a relative error of under 3%) with 500 steps. A model with fixed-step solver ode1 behaves the same way.

How a variable-step solver chooses h

A variable-step solver computes each step twice with methods of different order (ode45 uses 4th and 5th order). The difference estimates the local error. If the error exceeds the tolerance, the step is rejected and retried with a smaller h; if the error is much smaller, h grows.

Python Stand-in: adaptive step control (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The solver takes small steps during the first fraction of a second (fast transient), then lengthens h once the signal is smooth. This is what makes variable-step solvers efficient.

Practical advice

  • Use fixed-step for anything that will become generated code or run in real time; set the step to match your controller's sample time.
  • If results look wrong, tighten Relative tolerance (for example 1e-6) and see whether they change.
  • If a simulation seems frozen, the solver may be taking tiny steps. Look at Min step size and at discontinuities in your model. See Zero-Crossings and Hybrid Systems.
  • The Scope shows samples at solver steps. Lines between sparse points are interpolated, so small steps matter for smooth plots. You can set Refine output or a Max step size to make plots smoother.

Simulation time itself is never "real". For real-time testing you use Simulink Real-Time or Simulink Desktop Real-Time, which pace the fixed-step model against the wall clock.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which solver type is required when you generate code for an embedded controller?

    Generated code runs at fixed sample times, so a fixed-step (or discrete) solver is required.
  2. 2. What does a variable-step solver do when the estimated error is too large?

    Steps whose error estimate exceeds the tolerance are rejected and redone with a smaller step.
  3. 3. Which solver family is meant for stiff systems?

    ode15s (and ode23t) are stiff solvers; ode45 is for non-stiff problems.
  4. 4. Halving the fixed step size of Euler on a smooth problem generally...

    Smaller steps improve accuracy at the cost of more computations.

Summary

  • The solver advances simulated time and updates states; settings are in Modeling > Model Settings (Ctrl+E).
  • Fixed-step solvers use a constant step and are needed for code generation; variable-step solvers adapt to the signal.
  • ode45 suits non-stiff systems, ode15s suits stiff ones, ode3 and ode4 are common fixed-step choices.
  • Smaller steps and tighter tolerances give accuracy at a computing cost.

Next: Logging and Inspecting Results