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

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

Added original make3d

File size: 2.5 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;
24for k = N-1:-1:1
25   
26    % Feasible region       
27    bounds(x{k},-5,5);
28    bounds(u{k},-1,1);
29    bounds(x{k+1},-5,5);
30   
31    F =     set(-1 < u{k}     < 1);
32    F = F + set(-1 < C*x{k}   < 1);
33    F = F + set(-5 < x{k}     < 5);
34    F = F + set(-1 < C*x{k+1} < 1);
35    F = F + set(-5 < x{k+1}   < 5);
36
37    % LTI Dynamics
38    F = F + set(x{k+1} == A*x{k}+B*u{k});
39   
40    obj = norm(x{k},inf) + norm(u{k},inf);
41 
42    % Compute value function for one step backwards
43%    [mpsol{k},sol{k},Uz{k},J{k},U{k}] = solvemp(F,max(obj,J{k+1}),[],x{k},u{k});   
44    [mpsol{k},sol{k},Uz{k},J{k},U{k}] = solvemp(F,obj+J{k+1},[],x{k},u{k});       
45end
46
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=inf;
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% Prediction horizon
87N = 5;
88
89% States x(k), ..., x(k+N)
90x = sdpvar(repmat(nx,1,N),repmat(1,1,N));
91
92% Inputs u(k), ..., u(k+N) (last one not used)
93u = sdpvar(repmat(nu,1,N),repmat(1,1,N));
94
95% Value functions
96J = cell(1,N);
97
98% Initialize value function at stage N
99J{N} = 0;
100F = set([]);
101obj = 0;
102for k = N-1:-1:1
103    % Feasible region
104    F = F + set(-1 < u{k}     < 1);
105    F = F + set(-1 < C*x{k}   < 1);
106    F = F + set(-5 < x{k}     < 5);
107    F = F + set(-1 < C*x{k+1} < 1);
108    F = F + set(-5 < x{k+1}   < 5);
109
110    % LTI Dynamics
111    F = F + set(x{k+1} == A*x{k}+B*u{k});
112
113    % Compute value function for one step backwards
114    obj = max(obj,norm([x{k};u{k}],inf));
115
116end
117%F = F + set(norm(x{k+1},1) < norm(x{k},1))
118solvesdp(F+set(x{1}==[0.5;-1]),obj)
119
120[mpsol{k},xx,cc,vv,U{k}] = solvemp(F,obj,[],x{k},u{k});
121
122
123
124
125assign(x{k},[-0.5;-1]);
126xx = [-0.5;-1];
127for i = 1:10
128  xx = A*xx + B*double(U{k}) 
129  assign(x{k},xx);
130  double(x{k})
131  plot(xx(1),xx(2),'*k');drawnow
132end
133
134
135
136
Note: See TracBrowser for help on using the repository browser.