source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/demos/mpcex.m @ 37

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

Added original make3d

File size: 1.7 KB
Line 
1clc
2echo on
3clc
4echo on
5%*********************************************************
6%
7% Model predictive control example
8%
9%*********************************************************
10%
11% In this example, we solve quadratic problems using
12% semidefinite programming, second order cone programming
13% and quadratic programming.
14
15% MPC settings
16N = 5;
17pause % Strike any key to continue.
18
19% Create numerics for a discretized double integrator
20A = [2 -1;1 0];
21B = [1;0];
22C = [0.5 0.5];
23
24[H,S] = create_CHS(A,B,C,N)
25pause % Strike any key to continue.
26
27% Initial state
28x = [2;0];
29
30% Define free variables
31t = sdpvar(1,1);
32U = sdpvar(N,1);   
33pause % Strike any key to continue.
34
35% Define the prediction vector
36Y = H*x+S*U;
37pause % Strike any key to continue.
38
39% Control constraints
40F = set(-1 < U < 1);
41
42% Terminal constraint
43F = F+set(-1 < Y(N) < 1); 
44pause % Strike any key to continue.
45
46% Our goal is to minimize the quadratic function Y'*Y+U'*U
47%
48% Performance constraint written as an SDP using Schur complement
49% (very inefficient way to solve a QP...)
50F = F+set([t Y' U';Y eye(N) zeros(N,N);U zeros(N,N) eye(N)]>0)
51pause % Strike any key to continue.
52
53% Solve
54sol = solvesdp(F,t);
55pause % Strike any key to continue.
56
57% Look at solution
58double(U)
59double(Y(N))
60pause % Strike any key to continue.
61clc
62% More efficient implementation using SOCP... (if SOCP solver available)
63F =  set(-1 < U < 1) + set(-1 < Y(N) < 1) + set(cone([Y;U],t));
64sol = solvesdp(F,t);
65pause % Strike any key to continue.
66clc
67
68% Even more efficient implementation if QP solver is available
69F =  set(-1 < U < 1) + set(-1 < Y(N) < 1);
70sol = solvesdp(F,Y'*Y+U'*U);
71pause % Strike any key to continue.
72
73
74echo off
Note: See TracBrowser for help on using the repository browser.