-
Notifications
You must be signed in to change notification settings - Fork 0
/
example3_1.m
89 lines (71 loc) · 1.71 KB
/
example3_1.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
clear all;
clc;
close all;
%system
A{1}=[-10 30;0 -20];
A{2}=[-10 -30;0 -20];
n=2;
h{1} = @(x1,x2) (x1.^2+x2.^2)/50;
h{2} = @(x1,x2) 1-(x1.^2+x2.^2)/50;
dh{1} = @(x1,x2) [ 2.*x1/50, 2.*x2/50];
dh{2} = @(x1,x2) [-2.*x1/50, -2.*x2/50];
G=[1];
b=0.35;
l=0.2;
Rset=1:n;
Z=-5:0.05:5;
%LMI calculations
LMIS=[];
for j=G
P{j} = sdpvar(n,n,'symmetric');
R{j} = sdpvar(n,n,'full');
L{j} = sdpvar(n,n,'full');
end
for j=Rset
for k=G
Upsilon{k,j} = [L{k}*A{j}+A{j}'*L{k}', (P{k}-L{k}'+R{k}*A{j})';
P{k}-L{k}'+R{k}*A{j}, -R{k}-R{k}'];
LMIS = [LMIS, Upsilon{k,j} <= 0];
end
end
opts=sdpsettings;
opts.solver='sedumi';
opts.verbose=0;
sol = solvesdp(LMIS,[],opts);
p=min(checkset(LMIS));
if p > 0
for k = G
P{k} = double(P{k})
R{k} = double(R{k})
L{k} = double(L{k})
end
else
display('Infeasible')
P=[];
end
% Set estimation
V = @(x1,x2) sum(arrayfun(@(k) [x1;x2]'*h{k}(x1,x2)*P{k}*[x1;x2],G));
hdot = @(x1,x2,k) sum(arrayfun(@(j) dh{k}(x1,x2)*h{j}(x1,x2)*A{j}*[x1;x2],Rset));
Dset = @(x1,x2) sum(arrayfun(@(k) [x1;x2]'*hdot(x1,x2,k)*P{k}*[x1;x2],G));
%calculate V and D
meshPoints=500;
tol=10/meshPoints;
x = linspace(-5,5,meshPoints);
y = linspace(-5,5,meshPoints);
[X,Y]=meshgrid(x,y);
for i=1:length(x)
for j = 1:length(y)
Ve(i,j) = V(X(i,j),Y(i,j));
De(i,j) = Dset(X(i,j),Y(i,j));
end
end
%calculate b
b=min([min(Ve(:,1)), min(Ve(:,end)), min(Ve(1,:)), min(Ve(end,:))])
b=fix(b*1e2)/1e2;
figure(1);
[~,c]=contour(X,Y,Ve,linspace(0,b,5),'r','ShowText','on','DisplayName','V')
hold on
[~,d]=contour(X,Y,De,[0,fix(max(max(De))*1e2)/1e2],'b','ShowText','on','DisplayName','D')
legend;
%from the graph
l = 0.18;