-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcalcInvariantXf.m
52 lines (46 loc) · 1.36 KB
/
calcInvariantXf.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
function [Xf_set_H, Xf_set_h, k_star] = calcInvariantXf(A_K,C_aug,F,f,s,dim)
% Algorithm implementation
exit_flag = 0;
k = 0;
A = [];
while (exit_flag == 0)
fprintf('%i',k);
% Set the constraints for the optimization problem
% A=[];
% for t=1:k+1
% for j=1:s
% A_aux(j,:) = F(j,:)*C_aug*A_K^(k);
% end
% A=[A; A_aux];
% clear A_aux
% end
A_aux = F(:,:)*C_aug*A_K^(k);
A = [A; A_aux];
b = repmat(f,k+1,1);
for i = 1:s
% Set the optimization problem: objective function and constraints
h = F(i,:)*C_aug*A_K^(k+1);
% Solve the optimization problem with CVX
cvx_precision best
cvx_begin quiet
variable x_opt(dim.nx)
maximize(h*x_opt-f(i))
subject to
A*x_opt - b <= 0;
cvx_end
% disp(k);
% Save optimal value
opt_val(i)=cvx_optval;
end
% Evaluating optimality condition
if (sum(opt_val <= 0 - eps) == s && strcmp(cvx_status,'Unbounded') == 0)
exit_flag = 1;
k_star = k;
Xf_set_H = A;
Xf_set_h = b;
else
clear opt_val b h
k=k+1;
end
end
end