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);
채택된 답변
추가 답변 (1개)
If fast-rising spike and the overshoot are undesired and you would like to eliminate it, I suggest adding a prefilter at the reference input path.
% 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 % no reason to augment it unless LQR not what you want
% [n, ~] = size(A);
% AA = [A, zeros(n, 1); -C, 0];
% BB = [B; 0];
% Construct the closed-loop system
Ac = A - B*K; % <-- fix it here
Bc = B; % <-- fix it here
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); % <-- fix it here
[n, d] = tfdata(sys_tf, 'v'); % <-- add it here
%% Pre-filter
Gf = tf(d(end), n) % <-- add it here
%% Display the transfer function of the Command Compensated System
disp('Transfer Function of the Command Compensated System:');
Gcc = minreal(Gf*sys_tf) % <-- fix it here
%% plot step response
S = stepinfo(Gcc) % <-- add it here
step(Gcc), grid on % <-- add it here
카테고리
도움말 센터 및 File Exchange에서 State-Space Control Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

