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

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

Added original make3d

File size: 1.3 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
19J{N} = 0;
20F = set([]);
21for k = N-1:-1:1
22
23    % Feasible region
24    F = set(-1 < u{k}     < 1);
25    F = F + set(-1 < C*x{k}   < 1);
26    F = F + set(-5 < x{k}     < 5);
27    F = F + set(-1 < C*x{k+1} < 1);
28    F = F + set(-5 < x{k+1}   < 5);
29    % Dynamics
30    F = F + set(x{k+1} == A*x{k}+B*u{k});
31    % Cost in value iteration
32    %  obj = obj + x{k}'*x{k} + u{k}'*u{k}
33    obj = x{k}'*x{k} + u{k}'*u{k} + J{k+1};
34    % Solve one-step problem
35    [sol{k},diagnost{k},Uz{k},J{k},Optimizer{k}] = solvemp(F,obj,sdpsettings('solver','mpt'),x{k},u{k});   
36end
37
38assign(x{k},[1;0.5])
39mbg_asserttrue(diagnost{1}.problem == 0);
40mbg_asserttolequal(double(J{k}),3.82456140350877,1e-5);
41mbg_asserttolequal(double(Optimizer{k}),-1,1e-5);
42
43assign(x{k},[0.5;1])
44mbg_asserttolequal(double(J{k}), 1.6140350,1e-5);
45
46assign(x{k},[0;1.9])
47mbg_asserttolequal(double(J{k}), 8.755,1e-5);
48
49assign(x{k},[-0.1;-1.85])
50mbg_asserttolequal(double(J{k}),  6.61825,1e-5);
51
52
Note: See TracBrowser for help on using the repository browser.