source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/dev/tests-mbg/mpt/mpt_pwa_2.m @ 37

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

Added original make3d

File size: 1.9 KB
Line 
1function mpt_pwa_2
2
3% Data
4A = [2 -1;1 0];nx = 2;
5B = [1;0];nu = 1;
6C = [0.5 0.5];
7
8% Prediction horizon
9N = 4;
10
11% States x(k), ..., x(k+N)
12x = sdpvar(repmat(nx,1,N),repmat(1,1,N));
13
14% Inputs u(k), ..., u(k+N) (last one not used)
15u = sdpvar(repmat(nu,1,N),repmat(1,1,N));
16
17% Binary for PWA selection
18d = binvar(2,1);
19
20% Compare
21sysStruct.A{1} = A;
22sysStruct.B{1} = B;
23sysStruct.C{1} = C;
24sysStruct.D{1} = [0];
25sysStruct.A{2} = A;
26sysStruct.B{2} = B*pi;
27sysStruct.C{2} = C;
28sysStruct.D{2} = [0];
29sysStruct.guardX{1} = [-1 0];
30sysStruct.guardU{1} = [0];
31sysStruct.guardC{1} = [0];
32sysStruct.guardX{2} = [1 0];
33sysStruct.guardU{2} = [0];
34sysStruct.guardC{2} = [0];
35
36%set constraints on output
37sysStruct.ymin    =   -1;
38sysStruct.ymax    =    1;
39
40%set constraints on input
41sysStruct.umin    =   -1;
42sysStruct.umax    =   1;
43
44sysStruct.xmin    =   [-5;-5];
45sysStruct.xmax    =   [5;5];
46
47probStruct.norm=1;
48probStruct.Q=eye(2);
49probStruct.R=1;
50probStruct.N=N-1;
51probStruct.P_N=zeros(2);
52probStruct.subopt_lev=0;
53probStruct.y0bounds=1;
54probStruct.Tconstraint=0;
55ctrl=mpt_control(sysStruct,probStruct)
56
57% Online
58obj = 0;
59F = set([]);
60dd = [];
61for k = N-1:-1:1
62   
63    bounds(x{k},-5,5);
64    bounds(u{k},-1,1);
65    bounds(x{k+1},-5,5);
66   
67    % Feasible region
68    F = F + set(-1 < u{k}     < 1);
69    F = F + set(-1 < C*x{k}   < 1);
70    F = F + set(-5 < x{k}     < 5);
71    F = F + set(-1 < C*x{k+1} < 1);
72    F = F + set(-5 < x{k+1}   < 5);
73
74    % PWA Dynamics
75    d = binvar(2,1);dd = [dd;d];
76    F = F + set(implies(d(1),x{k+1} == (A*x{k}+B*u{k})));
77    F = F + set(implies(d(2),x{k+1} == (A*x{k}+pi*B*u{k})));
78    F = F + set(implies(d(1),x{k}(1) > 0));
79    F = F + set(implies(d(2),x{k}(1) < 0));
80    F = F + set(sum(d) == 1);
81    obj = obj + norm([x{k};u{k}],1);
82end
83mpsol{k} = solvemp(F,obj,sdpsettings('debug',1),x{k},u{k});
84mpsol{1} = mpt_removeOverlaps(mpsol{1})
85mbg_asserttolequal(mpt_isPWAbigger(mpsol{1},ctrl),0);
Note: See TracBrowser for help on using the repository browser.