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

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

Added original make3d

File size: 3.0 KB
Line 
1yalmip('clear')
2clc
3echo on
4%*********************************************************
5%
6% Multi-parametric programing
7%
8%*********************************************************
9%
10% This example requires the MPT-Toolbox
11%
12% We return to the MPC-problem.
13% This time however, we seek the explicit solution as a
14% function of the current state x
15pause
16
17% Create numerics for a discretized double integrator
18N = 5;
19A = [2 -1;1 0];
20B = [1;0];
21C = [0.5 0.5];
22[H,S] = create_CHS(A,B,C,N);
23pause
24
25% Variables
26x = sdpvar(2,1);
27U = sdpvar(N,1);
28pause
29
30% Parameterized predictions
31Y = H*x+S*U;
32
33%Control constraints
34F = set(-1 < U < 1);
35
36% Terminal constraint
37F = F+set(-1 < Y(N) < 1);
38pause
39
40% Exploration space
41F = F + set(-5 < x < 5);
42pause
43
44% Call solvemp (same syntax as solvesdp, except additional
45% fourth argument to specify the parametric variable)
46mpsol = solvemp(F,Y'*Y+U'*U,[],x);
47pause
48
49% We can, e.g., plot the solution
50plot(mpsol{1}.Pn)
51pause
52
53% Solve the problem with a L1 cost
54mpsol = solvemp(F,norm([Y;U],1),[],x);
55pause
56
57% Plot the value function
58clf
59mpt_plotPWA(mpsol{1}.Pn,mpsol{1}.Bi,mpsol{1}.Ci)
60pause
61
62
63% Solve the problem with a L1 cost, but this time
64% only request U(1) in the returned solution
65mpsol = solvemp(F,norm([Y;U],1),[],x,U(1));
66pause
67
68% Plot the optimizer
69clf
70mpt_plotPWA(mpsol{1}.Pn,mpsol{1}.Fi,mpsol{1}.Gi)
71pause
72
73% Extract value of optimizer at point [0.1;0.2]
74[ii,jj] = isinside(mpsol{1}.Pn,[0.1;0.3]);
75mpsol{1}.Fi{jj}*[0.1;0.3] + mpsol{1}.Gi{jj}
76pause
77
78% To avoid learning MPT commands, simply use
79% some more outputs from SOLVEMP, and YALMIP PWA
80% functions will be generated automatically
81[mpsol,diagnost,Z,Valuefunction,Optimizer] = solvemp(F,norm([Y;U],1),[],x,U(1));
82clf
83plot(Valuefunction)
84pause
85
86clf
87plot(Optimizer)
88pause
89
90assign(x,[0.1;0.3]);
91double(Optimizer)
92pause
93
94clc
95% The Valuefunction and Optmizer are standard
96% variables in YALMIP (so called nonlinear operators)
97% which we can use as variables when setting up other
98% optmimization problem
99%
100% Here we solve the silly problem of finding the state
101% with maximal x(1) coordinate, while having an optmial
102% cost less than 10.
103%
104% Since the value function for a simple parametric LP
105% is convex and can be written as the maximum of a set
106% of linear functions, the problem will be an LP, and
107% YALMIP keeps track of convexity etc, since the value
108% function behind the scenes is described with a so
109% called convexity-aware nonlinear operator.
110pause
111solvesdp(set(Valuefunction < 10),-x(1)),
112double(x)
113double(Valuefunction)
114pause
115
116% Why not solve a nonconvex problem and find the maximum
117% of the convex value function. Note that this will generate
118% a binary LP problem, so you need to have an MILP solver
119pause
120solvesdp([],-Valuefunction)
121double(x)
122double(Valuefunction)
123pause
124
125% Note that the transparant use of the value functions and the
126% optimizer as standard piecewise YALMIP variables still is
127% under development. Quadratic functions are for instance
128% not fully supported yet.
129%
130% Learn a lot more in the HTML manual...
131
132pause
133echo off
Note: See TracBrowser for help on using the repository browser.