LQR Simulink Block Model

14 views (last 30 days)
Muhammad Alifuddin
Muhammad Alifuddin on 6 Jul 2025
Answered: Altaïr on 9 Jul 2025
Curently I'm trying to use LQR block function from Simulink Block of LQR - File Exchange - MATLAB Central because I need to calculate LQR feedback gain in real time when Q is a function of the state. I'm trying to run the simulink example in that exchange file but got error as below:
Error:Simulink unable to determine sizes and/or types of the outputs for block 'LQR/LQR/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Error:Error in port widths or dimensions. 'Output Port 1' of 'LQR/LQR/MATLAB Function/X' has 5 elements. This port does not accept the dimensions (or orientation) specified by the output signal.
Anyone know how to fix this?

Answers (1)

Altaïr
Altaïr on 9 Jul 2025
The LQR masked subsystem available from the File Exchange addresses the Algebraic Riccati Equation (ARE) within Simulink. This can be seen in the MATLAB Function block code shown below:
The LQR subsystem's output X evolves over time to provide the solution to the ARE. This variable X corresponds to the matrix S that is produced as output by the lqr function.
The mask input Xo serves as the initial guess for the ARE solution matrix X. The steady-state value of X is used to obtain the LQR gain. Within the LQR subsystem, it is possible to observe the derivative of X approaching zero as time progresses, indicating convergence to the steady-state solution.
To compute the LQR gain at each time step for an updated plant, the ARE must be solved at every step. Additional clarification on this process can be found in the following discussion:

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!