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

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

Added original make3d

File size: 1.5 KB
Line 
1function dplti_1
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 = 3;
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% Value functions
18J = cell(1,N);
19
20% Initialize value function at stage N
21J{N} = 0;
22U{N} = 0;
23k=N-1;
24
25for k = N-1:-1:1
26   
27    % Feasible region       
28    bounds(x{k},-5,5);
29    bounds(u{k},-1,1);
30    bounds(x{k+1},-5,5);
31   
32    F =     set(-1 < u{k}     < 1);
33    F = F + set(-1 < C*x{k}   < 1);
34    F = F + set(-5 < x{k}     < 5);
35    F = F + set(-1 < C*x{k+1} < 1);
36    F = F + set(-5 < x{k+1}   < 5); 
37 
38    % LTI Dynamics
39    F = F + set(x{k+1} == A*x{k}+B*u{k});
40   
41    obj = norm([x{k};u{k}],1);
42   
43    % Compute value function for one step backwards
44    [mpsol{k},sol{k},Uz{k},J{k}] = solvemp(F,obj + J{k+1},[],x{k},u{k});   
45end
46
47% MPT implementation
48sysStruct.A= A;
49sysStruct.B= B;
50sysStruct.C= C;
51sysStruct.D= [0];
52
53%set constraints on output
54sysStruct.ymin    =   -1;
55sysStruct.ymax    =    1;
56
57%set constraints on input
58sysStruct.umin    =   -1;
59sysStruct.umax    =   1;
60
61sysStruct.xmin    =   [-5;-5];
62sysStruct.xmax    =   [5;5];
63
64probStruct.norm=1;
65probStruct.Q=eye(2);
66probStruct.R=1;
67probStruct.N=N-1;
68probStruct.P_N=zeros(2);
69probStruct.subopt_lev=0;
70probStruct.y0bounds=1;
71probStruct.Tconstraint=0;
72ctrl=mpt_control(sysStruct,probStruct)
73
74mbg_asserttolequal(mpt_isPWAbigger(mpsol{1}{1},ctrl),0);
Note: See TracBrowser for help on using the repository browser.