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

3 次查看(过去 30 天)
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.

采纳的回答

Paul
Paul 2025-7-24
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 个评论
PEDRO
PEDRO 2025-7-24
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 2025-7-24
编辑:Paul 2025-7-24
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 General Applications 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by