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 Center および File ExchangeNumerical 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