How to correct numerical errors when using a chain of integrators in simulink

3 views (last 30 days)
I've noticed that when I chain together a multiple integrators, a small linear term is introduced at some point resulting in a signal that diverges. Here is a small example using a sine wave:
Even thought the result should be sine-looking waves with different phases, the scope shows this:
There's clearly some error being introduced somewhere and the effect gets worse if I keep adding integrators.
Is there a way of getting rid of this? I've tried using different solvers and/or step sizes, but I can't find a solution.
Thank you.

Accepted Answer

Paul
Paul on 24 Jul 2025
The initial conditions on the integrators need to be set to appropriate values to yield the expected result.
Define the yellow curve
syms t
y(t) = sin(t);
The blue curve is the antiderivative of the yellow curve with some constant of integration to be determined
syms C1
b(t) = int(y(t),t) + C1
b(t) = 
Same for the red with respect to blue
syms C2
r(t) = int(b(t),t) + C2
r(t) = 
Now solve for the Ci based on the initial conditions for r(t) and b(t), which are both zero based on the scope plots
sol = solve([b(0)==0,r(0)==0],[C1,C2])
sol = struct with fields:
C1: 1 C2: 0
Sub back to get the final results for b(t) and r(t)
b(t) = subs(b(t),sol)
b(t) = 
r(t) = subs(r(t),sol)
r(t) = 
which looke like they match the plots in the scope.
  2 Comments
PEDRO
PEDRO on 24 Jul 2025
That you, that makes a lot of sense; in hindsight I should have noticed that the linear growth was the compound result of integrating constants.
Is there a way of configuring the integrator such that I can choose the value of the integration constants, e.g., C1 and C2 instead of the initial conditions?
Paul
Paul on 24 Jul 2025
Edited: Paul on 24 Jul 2025
Only the initial condition can be specified as a block parameter for the Integrator. Note that block parameters can be any valid Matlab expression. If you have a general expression for the initial condition you can enter that in the block dialog and Simulink will evaluate it when the diagram is updated and at simulation initialization.
Integrator block initial condition can also be specified as an external input to the block if that might help.

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!