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