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

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

Added original make3d

File size: 1.1 KB
Line 
1function testmpdpqp
2
3yalmip('clear')
4
5% Model data
6A = [2 -1;1 0];
7B = [1;0];
8C = [0.5 0.5];
9nx = 2; % Number of states
10nu = 1; % Number of inputs
11
12% Prediction horizon
13N = 5;
14% States x(k), ..., x(k+N)
15x = sdpvar(repmat(nx,1,N),repmat(1,1,N));
16% Inputs u(k), ..., u(k+N) (last one not used) u = sdpvar(repmat(nu,1,N),repmat(1,1,N));
17u = sdpvar(repmat(nu,1,N),repmat(1,1,N));
18
19F = set([]);
20obj = 0;
21for k = N-1:-1:1
22    % Feasible region
23    F = F + set(-1 < u{k}     < 1);
24    F = F + set(-1 < C*x{k}   < 1);
25    F = F + set(-5 < x{k}     < 5);
26    F = F + set(-1 < C*x{k+1} < 1);
27    F = F + set(-5 < x{k+1}   < 5);
28    % Dynamics
29    F = F + set(x{k+1} == A*x{k}+B*u{k});
30    % Cost in value iteration
31    obj = obj + x{k}'*x{k} + u{k}'*u{k};
32end
33
34[sol{k},diagnost{k},Uz{k},J{k},Optimizer{k}] = solvemp(F,obj,[],x{k},u{k});
35assign(x{k},[1;0.5])
36
37mbg_asserttrue(diagnost{1}.problem == 0);
38mbg_asserttolequal(double(J{k}),3.82456140350877,1e-5);
39mbg_asserttolequal(double(Optimizer{k}),-0.99122807017544,1e-5);
40assign(x{k},[0;1.7])
41mbg_asserttolequal(double(Optimizer{k}),1,1e-5);
42mbg_asserttolequal(double(J{k}),6.19300000000000,1e-5);
43
44
Note: See TracBrowser for help on using the repository browser.