-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConvex_Ex2.m
112 lines (60 loc) · 1.3 KB
/
Convex_Ex2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
%% Question 1 : note : run each section seperately
clear all;
clc;
A = [-1 1;0 -2];
cvx_begin sdp
variable P(2,2) symmetric
% Contraints(Lyapanov LMI)
A'*P + P'*A <= -0.000001*eye(2); % A'*P + P*A < 0
P >= 0.000001*eye(2); % P > 0
cvx_end
cvx_status
P
% plotting the transient state for x = [1 1]'
tspan =[0 9];
X0 = [1;1];
[t,y] = ode45(@(t,X) A*X,tspan,X0);
figure(1);
plot(t,y)
%% Question 2 :
clear all;
clc;
A = [1 1;0 -2];
B = [0;1];
cvx_begin sdp
variable Q(2,2) symmetric
variable Y(1,2)
A*Q + Q*A' -B*Y-Y'*B' <= -0.000001*eye(2);
Q >= 0.000001*eye(2);
cvx_end
cvx_status
P = inv(Q)
K = Y * P
% plotting the transient state for x = [1 1]'
tspan =[0 9];
X0 = [1;1];
[t,y] = ode45(@(t,X) (A-B*K)*X,tspan,X0);
figure(2);
plot(t,y)
%% Question 3 :
clear all;
clc;
A1 = [1 1;0 -2];
A2 = [-1 1;0 -2];
B = [0;1];
cvx_begin sdp
variable Q(2,2) symmetric
variable Y(1,2)
A1*Q + Q*A1' -B*Y-Y'*B' <= -0.000001*eye(2);
A2*Q + Q*A2' -B*Y-Y'*B' <= -0.000001*eye(2);
Q >= 0.000001*eye(2);
cvx_end
cvx_status
P = inv(Q)
K = Y * P
% plotting the transient state for x = [1 1]'
tspan =[0 9];
X0 = [1;1];
[t,y] = ode45(@(t,X) sf_sys(K,X,t),tspan,X0);
figure(3);
plot(t,y)