📄 mp.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>YALMIP Example : Multiparametric programming</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link href="yalmip.css" type="text/css" rel="stylesheet">
<base target="_self">
</head>
<body leftMargin="0" topMargin="0">
<div align="left">
<table border="0" cellpadding="4" cellspacing="3" style="border-collapse: collapse" bordercolor="#000000" width="100%" align="left" height="100%">
<tr>
<td width="100%" align="left" height="100%" valign="top">
<h2>Multiparametric programming</h2>
<hr noShade SIZE="1">
<p>
<img border="0" src="exclamationmark.jpg" align="left" width="16" height="16">This
example requires the <a href="solvers.htm#mpt">Multi-Parametric
Toolbox (MPT)</a>. </p>
<p>YALMIP can be used to calculate explicit solutions of linear and quadratic
programs by interfacing the <a href="solvers.htm#mpt">Multi-Parametric
Toolbox (MPT)</a>.</p>
<p>The following lines of code defines the basic numerical components of a
simple model predictive control (MPC) problem (essentially a constrained least-squares
problem).</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>A = [2 -1;1 0];
B = [1;0];
C = [0.5 0.5];
N = 5;
[H,S] = create_CHS(A,B,C,N)</pre>
</td>
</tr>
</table>
<p>The variables in an MPC problem are the current state <b>x</b> and the
control sequence<b> U</b>.</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>x = sdpvar(2,1);
U = sdpvar(N,1);</pre>
</td>
</tr>
</table>
<p>The output predictions are linear in the current state and the
control sequence.</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>Y = H*x+S*U;</pre>
</td>
</tr>
</table>
<p>We wish to minimize the quadratic cost</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>objective = Y'*Y+U'*U;</pre>
</td>
</tr>
</table>
<p>Both input and output are constrained</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>F = set(1 > U > -1);
F = F+set(1 > Y(N) > -1); </pre>
</td>
</tr>
</table>
<p>We seek the explicit solution <b><font face="Tahoma,Arial,sans-serif">U(x)</font></b> over the set <b>
<font face="Tahoma,Arial,sans-serif">|x|≤1</font></b>. The set
<font face="Tahoma,Arial,sans-serif"> <b>|x|≤1 </b>is called the
exploration set and is defined using a standard constraint.</font></p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>F = F + set(5 > x > -5);</pre>
</td>
</tr>
</table>
<p>The explicit solution <b>U(x)</b> is obtained by calling
<a href="reference.htm#solvemp">solvemp</a> with the parametric variable <b>x</b> as the fourth argument.</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>mpsol = solvemp(F,objective,[],x);</pre>
</td>
</tr>
</table>
<p>The explicit solution can, e.g, be plotted (see the <a href="solvers.htm#mpt">MPT</a>
manual for how to use the solution)</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>mpsol
<font color="#000000">
ans =
Pn: [1x13 polytope]
Fi: {1x13 cell}
Gi: {1x13 cell}
activeConstraints: {1x13 cell}
Phard: [1x1 polytope]</font></pre>
<pre>plot(mpsol.Pn)</pre>
</td>
</tr>
</table>
<p>The following piece of code calculates the explicit MPC controller with
an L<sub><font face="Arial">∞</font></sub> cost instead.</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>A = [2 -1;1 0];
B = [1;0];
C = [0.5 0.5];
N = 5;
[H,S] = create_CHS(A,B,C,N);
t = sdpvar(1,1);
x = sdpvar(2,1);
U = sdpvar(N,1);
Y = H*x+S*U;
F = set(-1 < U < 1);
F = F+set(-1 < Y(N) < 1);
F = F + set(-5 < x < 5);
F = F + set(-t < [Y;U] < t);
mpsol = solvemp(F,t,[],x);
plot(mpsol.Pn)</pre>
</td>
</tr>
</table>
<p>This example enables us to introduce the overloading of the projection
functionality in <a href="solvers.htm#mpt">MPT</a>. In MPC,
only the first input, <b>U(1)</b>, is of interest. What we can do is to
project the whole problem to the parametric variable <b>x</b>, the
objective function <b>t</b>, and the variable of interest, <b>U(1)</b>.
The following piece of code projects the problem to the reduced set of
variables, and solves the multi-parametric LP in this reduced space (not
necessarily an efficient approach though, projection is very expensive,
and we can easily end up with a problem with many constraints in the
reduced variables).</p>
<table cellPadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>A = [2 -1;1 0];
B = [1;0];
C = [0.5 0.5];
N = 5;
[H,S] = create_CHS(A,B,C,N);
t = sdpvar(1,1);
x = sdpvar(2,1);
U = sdpvar(N,1);
Y = H*x+S*U;
F = set(-1 < U < 1);
F = F+set(-1 < Y(N) < 1);
F = F + set(-5 < x < 5);
F = F + set(-t < [Y;U] < t);
F = projection(F,[x;t;U(1)]);
mpsol = solvemp(F,t,[],x);
plot(mpsol.Pn)</pre>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -