Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 36 ยท Continuous and Discrete Systems

Simulink Integrator Block: Modeling Differential Equations

Model differential equations in Simulink with Integrator blocks: initial conditions, the spring-mass-damper example, limits and reset, and how to check the result against RK4 and the exact solution.

The heart of continuous-time Simulink is the Integrator block. If a quantity changes over time at a known rate, integrating that rate gives the quantity. A differential equation such as x' = f(x, u) becomes a loop: compute the derivative from the current state, integrate it to get the state, and feed the state back. This is the modeling technique behind almost every physical system in Simulink, from circuits to vehicles.

Simulink is not available on this site, so the diagrams are described in words and a diagram, and the Python stand-ins solve the same equations with the same ideas (state, derivative, step).

The Integrator block

The block lives in Continuous and computes y(t) = y(t0) + integral of u. Its output is the state. Key parameters:

Parameter Meaning
Initial condition source internal (a value in the dialog) or external (an extra input port)
Initial condition The value at the start time; can be a variable such as x0 or a vector
Limit output Saturate the state between lower and upper limits (models end stops)
External reset rising, falling, either, level: reset the state with a signal
Show state port Adds an output that exposes the state, used to avoid algebraic loops when resetting
Absolute tolerance Error tolerance for this state, if you do not want the model default

Because the output is the state, an Integrator has no direct feedthrough, so feedback loops through it are fine (see Execution Order and Algebraic Loops).

From equation to diagram: a recipe

  1. Write the equation with the highest derivative alone on the left.
  2. Draw that expression as the signal that comes out of a Sum block.
  3. Feed it into an Integrator to get the next lower derivative.
  4. Chain integrators until you reach the unknown itself.
  5. Take the signals you need (position, velocity) back to the Sum via Gain blocks.

Example: a first-order system x' = -a x + b u needs one integrator whose input is -a*x + b*u.

Spring-mass-damper

A mass m on a spring (stiffness k) with damping c, pushed by force F(t), obeys

m x'' + c x' + k x = F so x'' = (F - c x' - k x) / m.

Two integrators turn acceleration into velocity and then position. The diagram:

flowchart LR
    F["F(t) Step"] --> S(("Sum +,-,-"))
    S --> G["Gain 1/m"]
    G --> I1["Integrator (v)"]
    I1 --> I2["Integrator (x)"]
    I1 -- "c * v" --> C["Gain c"]
    C --> S
    I2 -- "k * x" --> K["Gain k"]
    K --> S
    I2 --> Scope["Scope"]

The two feedback paths subtract damping force c v and spring force k x from the applied force.

Parameters: m = 1, c = 0.5, k = 4. The initial conditions are x(0) = 0 and v(0) = 0. A Step input of 1 at time 1 pushes the mass; the final position settles at F/k = 0.25. The damping ratio c / (2*sqrt(k*m)) = 0.125 is small, so the response overshoots and rings.

Equation to blocks

Isolate x'' Highest derivative alone
Sum the terms F minus c v minus k x
Integrate twice Acceleration, velocity, position
Close the loop Feed back v and x

Every ODE can be drawn this way.

1 / 2

Solve the same system in code

The stand-in uses the classical fourth-order Runge-Kutta method (the idea behind the ode4 fixed-step solver). The state is the pair (x, v), and the function returns the derivatives, exactly what the Sum and Gain blocks compute.

Python Stand-in: spring-mass-damper with RK4 (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.

Expect a peak near 0.42 (about 67 % overshoot for this light damping) and a final value close to 0.25 as the oscillation dies out.

Checking accuracy: Euler versus RK4

You can test a solver choice by comparing with a case that has an exact answer. For x' = -x, x(t) = e^-t. See how the fixed-step solvers differ for the same step.

Python Stand-in: Euler (ode1) versus RK4 (ode4) (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.

Higher-order methods cost more per step but reach accuracy that Euler could only match with a much smaller step.

Practical features

  • Limited integrator: tick Limit output to model a valve that cannot go below 0% or above 100% (a position stop). Add Show saturation port to detect when it limits.
  • Reset: use a Reset signal to clear an integrator, for example to restart a timer or wind-up protection.
  • Initial condition from a vector: if the Integrator receives a vector input, its initial condition can be a vector as well, giving one state per element.
  • State-space shortcut: for linear systems, a single State-Space block replaces the whole diagram: see Transfer Functions and State-Space.
  • Derivative blocks: the Derivative block approximates du/dt but amplifies noise; prefer to reformulate the model with integrators.

When a model has many states, the Model Explorer and the Continuous states logging option (Model Settings > Data Import/Export > States) let you record all integrator states as xout for later analysis.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why can a feedback loop through an Integrator avoid an algebraic loop?

    An Integrator outputs its state, which is known at the start of the step.
  2. 2. To model x'' = (F - c x' - k x)/m, how many Integrator blocks are needed?

    One integrator converts acceleration to velocity and a second converts velocity to position.
  3. 3. What does Limit output do on an Integrator?

    It models a state that cannot leave a range, such as a physical end stop.
  4. 4. With m=1, c=0.5, k=4 and a unit force, what final position does the mass reach?

    At rest the spring force balances the applied force: k x = F, so x = 0.25.

Summary

  • The Integrator block holds a continuous state; chain integrators to reach the variable you want.
  • Isolate the highest derivative, build it with a Sum and Gains, then integrate and feed back.
  • Initial conditions, limits and resets are set in the block dialog.
  • Higher-order solvers reach a given accuracy with larger steps; check against known solutions.

Next: Transfer Functions and State-Space