1 | echo on |
---|
2 | clc |
---|
3 | % This example shows how to (locally) solve a small BMI using |
---|
4 | % a simple linearization-based algorithm. |
---|
5 | % |
---|
6 | % The main motivation of this example is not to describe a |
---|
7 | % particularily efficient solver, but to describe how easily |
---|
8 | % a BMI solver can be implemented using high-level YALMIP code. |
---|
9 | % |
---|
10 | % The problem is to find a feedback u = Lx so that the |
---|
11 | % L2 gain from w to y is minimized, for the system |
---|
12 | % |
---|
13 | % x' = Ax+Bu+Gw |
---|
14 | % y = Cx |
---|
15 | % |
---|
16 | % This can be formulated as the BMI |
---|
17 | % |
---|
18 | % min t |
---|
19 | % s.t P > 0 |
---|
20 | % [(A+BL)P+P(A+BL)+C'C PG; G'P -tI] < 0 |
---|
21 | % |
---|
22 | pause |
---|
23 | clc |
---|
24 | |
---|
25 | % Create system data |
---|
26 | A = [-1 -1 -1; |
---|
27 | 1 0 0; |
---|
28 | 0 1 0]; |
---|
29 | B = [1;0;0]; |
---|
30 | C = [0 0 1]; |
---|
31 | G = [-1;-1;-1]; |
---|
32 | |
---|
33 | % Define decision variables |
---|
34 | P = sdpvar(3,3); |
---|
35 | L = sdpvar(1,3); |
---|
36 | t = sdpvar(1,1); |
---|
37 | pause |
---|
38 | |
---|
39 | % A reasonble initial guess is valuable |
---|
40 | [L0,P0]=lqr(A,B,eye(3),1); |
---|
41 | setsdpvar(P,P0); |
---|
42 | setsdpvar(L,-L0); |
---|
43 | setsdpvar(t,100); |
---|
44 | pause |
---|
45 | clc |
---|
46 | |
---|
47 | % Recover all involved decision variables |
---|
48 | % in one single variable (simplifies code later) |
---|
49 | x = recover(getvariables([P(:);L(:);t])) |
---|
50 | pause |
---|
51 | |
---|
52 | % Define the nonlinear matrix (simplifies the code) |
---|
53 | H = -[(A+B*L)'*P+P*(A+B*L)+C'*C P*G;G'*P -t]; |
---|
54 | pause |
---|
55 | |
---|
56 | % Save old iterates and old objective function |
---|
57 | x0 = double(x); |
---|
58 | t0 = double(t); |
---|
59 | pause |
---|
60 | |
---|
61 | % Linearized constraints |
---|
62 | F = set(linearize(H)>0) + set(P>0) |
---|
63 | pause |
---|
64 | |
---|
65 | % add a trust region |
---|
66 | F = F + set(cone(x-x0,0.5*norm(x0))); |
---|
67 | pause |
---|
68 | |
---|
69 | % Solve linearized problem |
---|
70 | solvesdp(F,t) |
---|
71 | pause |
---|
72 | |
---|
73 | % Optimal decision variables for linearized problem |
---|
74 | xnew = double(x); |
---|
75 | pause |
---|
76 | |
---|
77 | % Original problem is not guaranteed to be feasible |
---|
78 | % Line-search for feasible (and improving) solution |
---|
79 | pause |
---|
80 | alpha = 1; |
---|
81 | while (min(eig(double(H)))<0) | (min(eig(double(P)))<0) | (double(t)>t0*0.9999) |
---|
82 | alpha = alpha*0.5; |
---|
83 | setsdpvar(x,x0+alpha*(xnew-x0)); |
---|
84 | end |
---|
85 | |
---|
86 | % Current (squared) gain |
---|
87 | double(t) |
---|
88 | pause |
---|
89 | |
---|
90 | % repeat.... |
---|
91 | % |
---|
92 | % for i = 1:15 |
---|
93 | % |
---|
94 | % % Save old iterates and old objective function |
---|
95 | % x0 = double(x); |
---|
96 | % t0 = double(t); |
---|
97 | % |
---|
98 | % % Linearized constraints |
---|
99 | % F = set(linearize(H)>0) + set(P>0); |
---|
100 | % % add a trust region |
---|
101 | % F = F + set(cone(x-x0,0.25*norm(x0))); |
---|
102 | % |
---|
103 | % % Solve linearized problem |
---|
104 | % solvesdp(F,t,sdpsettings('verbose',0)); |
---|
105 | % |
---|
106 | % % Optimal decision variables for linearized problem |
---|
107 | % xnew = double(x); |
---|
108 | % |
---|
109 | % % Original problem is not guaranteed to be feasible |
---|
110 | % % Line-search for feasible (and improving) solution |
---|
111 | % alpha = 1; |
---|
112 | % while (min(eig(double(H)))<0) | (double(t)>t0*0.9999) |
---|
113 | % alpha = alpha*0.5; |
---|
114 | % setsdpvar(x,x0+alpha*(xnew-x0)); |
---|
115 | % end |
---|
116 | % double(t) |
---|
117 | % end |
---|
118 | pause |
---|
119 | |
---|
120 | echo off |
---|
121 | for i = 1:15 |
---|
122 | % Save old iterates and old objective function |
---|
123 | x0 = double(x); |
---|
124 | t0 = double(t); |
---|
125 | |
---|
126 | % Linearized constraints |
---|
127 | F = set(linearize(H)>0) + set(P>0); |
---|
128 | % add a trust region |
---|
129 | F = F + set(cone(x-x0,0.5*norm(x0))); |
---|
130 | |
---|
131 | % Solve linearized problem |
---|
132 | solvesdp(F,t,sdpsettings('verbose',0)); |
---|
133 | |
---|
134 | % Optimal decision variables for linearized problem |
---|
135 | xnew = double(x); |
---|
136 | |
---|
137 | % Original problem is not guaranteed to be feasible |
---|
138 | % Line-search for feasible (and improving) solution |
---|
139 | alpha = 1; |
---|
140 | while (min(eig(double(H)))<0) | (min(eig(double(P)))<0) | (double(t)>t0*0.9999) |
---|
141 | alpha = alpha*0.5; |
---|
142 | setsdpvar(x,x0+alpha*(xnew-x0)); |
---|
143 | end |
---|
144 | disp(['#' num2str(i) ' L2 gain : ' num2str(double(t))]) |
---|
145 | end |
---|
146 | clc |
---|
147 | echo on |
---|
148 | % An alternativ is to work with the complete set of |
---|
149 | % constraints by linearizing the LMI object |
---|
150 | % |
---|
151 | % Define the constraints |
---|
152 | |
---|
153 | F = set(H>0) + set(P>0) |
---|
154 | pause |
---|
155 | % Solve linearized problem |
---|
156 | solvesdp(linearize(F),t) |
---|
157 | while (min(eig(double(H)))<0) | (double(t)>t0*0.9999) |
---|
158 | alpha = alpha*0.5; |
---|
159 | setsdpvar(x,x0+alpha*(xnew-x0)); |
---|
160 | end |
---|
161 | double(t) |
---|
162 | |
---|
163 | pause |
---|
164 | % The rest is done similarily... |
---|
165 | pause |
---|
166 | clc |
---|
167 | |
---|
168 | % In fact, all this can be done automatically |
---|
169 | % by using the solver bmilin (coded using high-level YALMIP) |
---|
170 | pause |
---|
171 | solvesdp(F,t,sdpsettings('solver','bmilin','usex0',1)); |
---|
172 | pause |
---|
173 | echo off |
---|
174 | |
---|
175 | |
---|