Berikut ini yaitu script MATLAB untuk LQR (Linear-Quadratic Regulator) controller.
clear all, close all, clc;
%% Define the system
A = [1 0 2;
2 3 0;
1 2 3]
% the state matrix
B = [1; 0; 0]
% the input vector
eig(A)
% the eigenvalues are
% 4.7511 + 0.0000i
% 1.1244 + 1.0251i
% 1.1244 - 1.0251i
% it is not stable
%% LQR design
Q = eye(size(A))
R = 1
K = lqr(A,B,Q,R)
% K =
% 14.5461 24.4004 41.9475
%% State feedback controller
sys = ss(A-B*K, eye(size(A)), eye(size(A)), eye(size(A)))
eig(sys.a)
% the eigenvalues are
% -4.7742 + 0.0000i
% -1.3860 + 1.1477i
% -1.3860 - 1.1477i
% it is stable
x0 = [5; 5; 5]
% initial state
t = 0:0.01:5;
% the time duration
x = initial(sys,x0,t);
% response of the state-space
% with initial condition x0
% and time duration t
x1 = [1 0 0]*x';
x2 = [0 1 0]*x';
x3 = [0 0 1]*x';
% the state variables
%% Plot the state variables
subplot(3,1,1); plot(t,x1), grid
title('Response to initial condition')
ylabel('x1')
subplot(3,1,2); plot(t,x2), grid
ylabel('x2')
subplot(3,1,3); plot(t,x3), grid
ylabel('x3')
xlabel('t (seconds)')
%% Define the system
A = [1 0 2;
2 3 0;
1 2 3]
% the state matrix
B = [1; 0; 0]
% the input vector
eig(A)
% the eigenvalues are
% 4.7511 + 0.0000i
% 1.1244 + 1.0251i
% 1.1244 - 1.0251i
% it is not stable
%% LQR design
Q = eye(size(A))
R = 1
K = lqr(A,B,Q,R)
% K =
% 14.5461 24.4004 41.9475
%% State feedback controller
sys = ss(A-B*K, eye(size(A)), eye(size(A)), eye(size(A)))
eig(sys.a)
% the eigenvalues are
% -4.7742 + 0.0000i
% -1.3860 + 1.1477i
% -1.3860 - 1.1477i
% it is stable
x0 = [5; 5; 5]
% initial state
t = 0:0.01:5;
% the time duration
x = initial(sys,x0,t);
% response of the state-space
% with initial condition x0
% and time duration t
x1 = [1 0 0]*x';
x2 = [0 1 0]*x';
x3 = [0 0 1]*x';
% the state variables
%% Plot the state variables
subplot(3,1,1); plot(t,x1), grid
title('Response to initial condition')
ylabel('x1')
subplot(3,1,2); plot(t,x2), grid
ylabel('x2')
subplot(3,1,3); plot(t,x3), grid
ylabel('x3')
xlabel('t (seconds)')
Berikut ini ialah plot response dari state variable.
Lihat juga tentang.
Kendali state space MATLAB.
Sumber http://lang8088.blogspot.com
EmoticonEmoticon