source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/demos/bmiex2.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 3.9 KB
Line 
1echo on
2clc
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%
22pause
23clc
24
25% Create system data
26A = [-1    -1    -1;
27     1     0     0;
28     0     1     0];
29B = [1;0;0];
30C = [0 0 1];
31G = [-1;-1;-1];
32
33% Define decision variables
34P = sdpvar(3,3);
35L = sdpvar(1,3);
36t = sdpvar(1,1);
37pause
38
39% A reasonble initial guess is valuable
40[L0,P0]=lqr(A,B,eye(3),1);
41setsdpvar(P,P0);
42setsdpvar(L,-L0);
43setsdpvar(t,100);
44pause
45clc
46
47% Recover all involved decision variables
48% in one single variable (simplifies code later)
49x = recover(getvariables([P(:);L(:);t]))
50pause
51
52% Define the nonlinear matrix (simplifies the code)
53H = -[(A+B*L)'*P+P*(A+B*L)+C'*C P*G;G'*P -t];
54pause
55
56% Save old iterates and old objective function
57x0 = double(x);
58t0 = double(t);
59pause
60
61% Linearized constraints
62F = set(linearize(H)>0) + set(P>0)   
63pause
64
65% add a trust region
66F = F + set(cone(x-x0,0.5*norm(x0)));
67pause
68
69% Solve linearized problem
70solvesdp(F,t)
71pause
72
73% Optimal decision variables for linearized problem
74xnew = double(x);
75pause
76
77% Original problem is not guaranteed to be feasible
78% Line-search for feasible (and improving) solution
79pause
80alpha = 1;
81while (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));
84end
85
86% Current (squared) gain
87double(t)
88pause
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
118pause
119
120echo off
121for 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;
140while (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))])
145end
146clc
147echo 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
153F = set(H>0) + set(P>0)
154pause
155% Solve linearized problem
156solvesdp(linearize(F),t)
157while (min(eig(double(H)))<0) | (double(t)>t0*0.9999)
158    alpha = alpha*0.5;
159    setsdpvar(x,x0+alpha*(xnew-x0));
160end
161double(t)
162
163pause
164% The rest is done similarily...
165pause
166clc
167
168% In fact, all this can be done automatically
169% by using the solver bmilin (coded using high-level YALMIP)
170pause
171solvesdp(F,t,sdpsettings('solver','bmilin','usex0',1));
172pause
173echo off
174
175
Note: See TracBrowser for help on using the repository browser.