1 | function dplti_1 |
---|
2 | |
---|
3 | % Data |
---|
4 | A = [2 -1;1 0];nx = 2; |
---|
5 | B = [1;0];nu = 1; |
---|
6 | C = [0.5 0.5]; |
---|
7 | |
---|
8 | % Prediction horizon |
---|
9 | N = 5; |
---|
10 | |
---|
11 | % States x(k), ..., x(k+N) |
---|
12 | x = sdpvar(repmat(nx,1,N),repmat(1,1,N)); |
---|
13 | |
---|
14 | % Inputs u(k), ..., u(k+N) (last one not used) |
---|
15 | u = sdpvar(repmat(nu,1,N),repmat(1,1,N)); |
---|
16 | |
---|
17 | % MPT implementation |
---|
18 | sysStruct.A= A; |
---|
19 | sysStruct.B= B; |
---|
20 | sysStruct.C= C; |
---|
21 | sysStruct.D= [0]; |
---|
22 | |
---|
23 | %set constraints on output |
---|
24 | sysStruct.ymin = -1; |
---|
25 | sysStruct.ymax = 1; |
---|
26 | |
---|
27 | %set constraints on input |
---|
28 | sysStruct.umin = -1; |
---|
29 | sysStruct.umax = 1; |
---|
30 | |
---|
31 | sysStruct.xmin = [-5;-5]; |
---|
32 | sysStruct.xmax = [5;5]; |
---|
33 | |
---|
34 | probStruct.norm=1; |
---|
35 | probStruct.Q=eye(2); |
---|
36 | probStruct.R=1; |
---|
37 | probStruct.N=N-1; |
---|
38 | probStruct.P_N=zeros(2); |
---|
39 | probStruct.subopt_lev=0; |
---|
40 | probStruct.y0bounds=1; |
---|
41 | probStruct.Tconstraint=0; |
---|
42 | ctrl=mpt_control(sysStruct,probStruct) |
---|
43 | |
---|
44 | % States x(k), ..., x(k+N) |
---|
45 | x = sdpvar(repmat(nx,1,N),repmat(1,1,N)); |
---|
46 | |
---|
47 | % Inputs u(k), ..., u(k+N) (last one not used) |
---|
48 | u = sdpvar(repmat(nu,1,N),repmat(1,1,N)); |
---|
49 | |
---|
50 | % Value functions |
---|
51 | J = cell(1,N); |
---|
52 | |
---|
53 | % Initialize value function at stage N |
---|
54 | J{N} = 0; |
---|
55 | F = set([]); |
---|
56 | obj = 0; |
---|
57 | for k = N-1:-1:1 |
---|
58 | % Feasible region |
---|
59 | F = F + set(-1 < u{k} < 1); |
---|
60 | F = F + set(-1 < C*x{k} < 1); |
---|
61 | F = F + set(-5 < x{k} < 5); |
---|
62 | F = F + set(-1 < C*x{k+1} < 1); |
---|
63 | F = F + set(-5 < x{k+1} < 5); |
---|
64 | |
---|
65 | % LTI Dynamics |
---|
66 | F = F + set(x{k+1} == A*x{k}+B*u{k}); |
---|
67 | |
---|
68 | % Compute value function for one step backwards |
---|
69 | obj = obj + norm([x{k};u{k}],1); |
---|
70 | end |
---|
71 | mpsol{1} = solvemp(F,obj,[],x{k},u{k}); |
---|
72 | |
---|
73 | mbg_asserttolequal(mpt_isPWAbigger(mpsol{1}{1},ctrl),0); |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | |
---|