- Add a MATLAB ‘Function Block’ in your Simulink model.
- Write the following code in the MATLAB ‘Function block’:
Simulink Integral with variable bounds
5 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Aniket
on 17 Sep 2024
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:
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!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!