Simulink Integral with variable bounds

조회 수: 5 (최근 30일)
Philipps
Philipps 2021년 12월 12일
답변: Aniket 2024년 9월 17일
Hey,
I need to implement a integral in my simulink model with a variable upper bound. The upper bound is a signal in my model which gets smaller every step.
I tried to put the variable in the workspace (simout-block) and solve the integral in matlab (syma sigma tf; f = .....; int(f, t0, tf);). Then i tried to take the solved integral with simin-block.
Im new to the simulink thing. Would this proceed will be the right for my problem? Im not sure if the integral will get solved for every step.
Besides that: i get a error for my simin-block because the input format of my solved integral is not supported.

답변 (1개)

Aniket
Aniket 2024년 9월 17일
I understand you are trying to use MATLAB's ‘int’ function to solve an integral with a variable upper bound directly in Simulink. Unfortunately, this approach might not work as expected because ‘int’ is designed for symbolic integration, which does not dynamically adapt to changing conditions during a Simulink simulation.
To address this, you can use a numerical approach within Simulink, which updates at each simulation step. A great way to achieve this is by using a MATLAB Function block with the ‘trapz’ function for numerical integration. Here's how you can do it:
  1. Add a MATLAB ‘Function Block’ in your Simulink model.
  2. Write the following code in the MATLAB ‘Function block’:
function y = variable_integral(u, t0, tf)
% u: input signal (e.g., sine wave)
% t0: lower bound (constant)
% tf: upper bound (variable signal)
% Define time vector for integration
t = linspace(t0, tf, 100); % 100 points between t0 and tf
% Evaluate the input signal over the time vector
u_eval = sin(t); % Assuming u = sin(t)
% Perform numerical integration
y = trapz(t, u_eval); % Trapezoidal integration
end
3. Connect the Inputs and Outputs appropriately as shown in figure below:
This method will dynamically compute the integral at each simulation step. Also, you may update the function code as per required integral.
For more detailed steps, you can refer to the following Simulink Documentation on MATLAB Function Blocks:
Hope it helps!

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by