source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/dev/regress_dplti_1.m @ 37

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

Added original make3d

File size: 2.3 KB
Line 
1yalmip('clear')
2%clear all
3
4% Data
5A = [2 -1;1 0];nx = 2;
6B = [1;0];nu = 1;
7C = [0.5 0.5];
8
9% Prediction horizon
10N = 3;
11
12% States x(k), ..., x(k+N)
13x = sdpvar(repmat(nx,1,N),repmat(1,1,N));
14
15% Inputs u(k), ..., u(k+N) (last one not used)
16u = sdpvar(repmat(nu,1,N),repmat(1,1,N));
17
18% Value functions
19J = cell(1,N);
20
21% Initialize value function at stage N
22J{N} = 0;
23U{N} = 0;
24k=N-1;
25
26for k = N-1:-1:1
27   
28    % Feasible region       
29    bounds(x{k},-5,5);
30    bounds(u{k},-1,1);
31    bounds(x{k+1},-5,5);
32   
33    F =     set(-1 < u{k}     < 1);
34    F = F + set(-1 < C*x{k}   < 1);
35    F = F + set(-5 < x{k}     < 5);
36    F = F + set(-1 < C*x{k+1} < 1);
37    F = F + set(-5 < x{k+1}   < 5); 
38 
39    % LTI Dynamics
40    F = F + set(x{k+1} == A*x{k}+B*u{k});
41   
42    obj = norm([x{k};u{k}],1);
43   
44    % Compute value function for one step backwards
45    [mpsol{k},sol{k},Uz{k},J{k}] = solvemp(F,obj + J{k+1},[],x{k},u{k});   
46end
47
48% MPT implementation
49sysStruct.A= A;
50sysStruct.B= B;
51sysStruct.C= C;
52sysStruct.D= [0];
53
54%set constraints on output
55sysStruct.ymin    =   -1;
56sysStruct.ymax    =    1;
57
58%set constraints on input
59sysStruct.umin    =   -1;
60sysStruct.umax    =   1;
61
62sysStruct.xmin    =   [-5;-5];
63sysStruct.xmax    =   [5;5];
64
65probStruct.norm=1;
66probStruct.Q=eye(2);
67probStruct.R=1;
68probStruct.N=N-1;
69probStruct.P_N=zeros(2);
70probStruct.subopt_lev=0;
71probStruct.y0bounds=1;
72probStruct.Tconstraint=0;
73ctrl=mpt_control(sysStruct,probStruct)
74mpt_isPWAbigger(mpsol{1}{1},ctrl)
75
76
77
78
79
80break
81
82
83
84
85
86% States x(k), ..., x(k+N)
87x = sdpvar(repmat(nx,1,N),repmat(1,1,N));
88
89% Inputs u(k), ..., u(k+N) (last one not used)
90u = sdpvar(repmat(nu,1,N),repmat(1,1,N));
91
92% Value functions
93J = cell(1,N);
94
95% Initialize value function at stage N
96J{N} = 0;
97F = set([]);
98obj = 0;
99for k = N-1:-1:1
100    % Feasible region
101    F = F + set(-1 < u{k}     < 1);
102    F = F + set(-1 < C*x{k}   < 1);
103    F = F + set(-5 < x{k}     < 5);
104    F = F + set(-1 < C*x{k+1} < 1);
105    F = F + set(-5 < x{k+1}   < 5);
106
107    % LTI Dynamics
108    F = F + set(x{k+1} == A*x{k}+B*u{k});
109
110    % Compute value function for one step backwards
111%    obj = obj + norm([x{k};u{k}],1);
112    obj = obj + x{k}'*x{k}+ u{k}'*u{k};%;u{k}],1);
113
114end
115[mpsol2{k},sol2{k},Uz2{k},J2{k},U2{k}]  = solvemp(F,obj,[],x{k},u{k});
116 
117 mpt_isPWAbigger(mpsol{1}{1},mpsol2{1}{1})
118
119assign(x{k},[1;0.5])
120double(J{k})
121solvesdp(F+set(x{1} == [1;0.5]),obj);
122
123
124
125
126
Note: See TracBrowser for help on using the repository browser.