Check Stability of A: Appendix MATLAB Code
Check Stability of A: Appendix MATLAB Code
MATLAB Code:
1. Check stability of A
clear all;
clc;
% system description
A = [0 1 0 0; 20.601 0 0 0; 0 0 0 1; -0.4905 0 0 0];
disp(eig(A)); % Calulate and display the Eigen Values of A
Solution:
A= 0 1.0000 0 0
20.6010 0 0 0
0 0 0 1.0000
-0.4905 0 0 0
eig(A) = 0
0
4.5388
-4.5388
Matrix A is Unstable
2. Check Controllability of AB
clear all;
clc;
% system description
A = [0 1 0 0; 20.601 0 0 0; 0 0 0 1; -0.4905 0 0 0];
B = [0; -1; 0; 0.5];
Solution:
unco = 0
clear all;
clc;
% system description
A = [0 1 0 0; 20.601 0 0 0; 0 0 0 1; -0.4905 0 0 0];
B = [0; -1; 0; 0.5];
% performance matrices
Q = [200 0 0 0; 0 2 0 0; 0 0 2 0; 0 0 0 2];
R = 2;
% LMI flow
setlmis([])
X = lmivar(1, [4,1]); % Decision variable
LMIs = getlmis;
[TMIN,XFEAS] = feasp (LMIs); % feasibility of LMI (TMIN<0 implies feasible)
Solution:
Solver for LMI feasibility problems L(x) < R(x)
This solver minimizes t subject to L(x) < R(x) + t*I
The best value of t should be negative for feasibility
Iteration : Best value of t so far
1 0.030747
2 0.015314
3 0.015314
4 3.103825e-03
5 3.103825e-03
*** new lower bound: -0.080638
6 3.103825e-03
*** new lower bound: -0.014184
7 6.389709e-04
8 -5.522330e-04
*** new lower bound: -0.011082
System has stable closed loop poles, hence K is optimal Controller gain
Clc;
clear;
close all;
% System matrix
A = [0 1 0 0; 20.601 0 0 0; 0 0 0 1; -0.4905 0 0 0];
% Control matrix
B = [0; -1; 0; 0.5];
% Controller gain
K = [-80.1449 -17.7407 -2.3320 -6.2538];
% Output matrix
C = [1 0 0 0;0 1 0 0; 0 0 1 0; 0 0 0 1];
% Initial state
x0 = [0.1; 0; 0; 0];
figure
subplot(2,2,1) % Plot of Angular Position of Pendulum w.r.t.time
plot(t,x(:,1),'k') % Plot color to be black
xlabel('Time (t)')
ylabel('\theta(t)')
title('Angular position')
grid on
set(gca,'FontSize',12)
figure
plot(t,x) % Plot of all states w.r.t.time
xlabel('Time')
ylabel('States')
legend('x_1','x_2','x_3','x_4')
set(gca,'FontSize',18)