i am trying to find the lqr controller system Transfer function, but getting error as “Arrays have incompatible sizes for this operation.”
% Define system matrices
A = [0 20.95; -709.22 -106.85];
B = [3771.21; 12765.96];
C = [1 0];
D = 0;
% Define the LQR weighting matrices
Q = [0.0057312 0; 0 1]; % Weighting matrix for states
R = 1; % Weighting matrix for control inputs
% Compute LQR gain matrix
K = lqr(A, B, Q, R);
% Augment the system
[n, ~] = size(A);
AA = [A, zeros(n, 1); -C, 0];
BB = [B; 0];
% Construct the closed-loop system
Ac = AA – BB * K;
Bc = BB;
Cc = C;
Dc = D;
% Create state-space model of the closed-loop system
sys_cl = ss(Ac, Bc, Cc, Dc);
% Convert state-space model to transfer function
sys_tf = tf(sys_cl);
% Display the transfer function
disp(‘Transfer Function of the Closed-Loop System with LQR Controller:’);
disp(sys_tf);% Define system matrices
A = [0 20.95; -709.22 -106.85];
B = [3771.21; 12765.96];
C = [1 0];
D = 0;
% Define the LQR weighting matrices
Q = [0.0057312 0; 0 1]; % Weighting matrix for states
R = 1; % Weighting matrix for control inputs
% Compute LQR gain matrix
K = lqr(A, B, Q, R);
% Augment the system
[n, ~] = size(A);
AA = [A, zeros(n, 1); -C, 0];
BB = [B; 0];
% Construct the closed-loop system
Ac = AA – BB * K;
Bc = BB;
Cc = C;
Dc = D;
% Create state-space model of the closed-loop system
sys_cl = ss(Ac, Bc, Cc, Dc);
% Convert state-space model to transfer function
sys_tf = tf(sys_cl);
% Display the transfer function
disp(‘Transfer Function of the Closed-Loop System with LQR Controller:’);
disp(sys_tf); % Define system matrices
A = [0 20.95; -709.22 -106.85];
B = [3771.21; 12765.96];
C = [1 0];
D = 0;
% Define the LQR weighting matrices
Q = [0.0057312 0; 0 1]; % Weighting matrix for states
R = 1; % Weighting matrix for control inputs
% Compute LQR gain matrix
K = lqr(A, B, Q, R);
% Augment the system
[n, ~] = size(A);
AA = [A, zeros(n, 1); -C, 0];
BB = [B; 0];
% Construct the closed-loop system
Ac = AA – BB * K;
Bc = BB;
Cc = C;
Dc = D;
% Create state-space model of the closed-loop system
sys_cl = ss(Ac, Bc, Cc, Dc);
% Convert state-space model to transfer function
sys_tf = tf(sys_cl);
% Display the transfer function
disp(‘Transfer Function of the Closed-Loop System with LQR Controller:’);
disp(sys_tf); lqr controller transfer function MATLAB Answers — New Questions