📄 reference.htm
字号:
</td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Related commands</th>
</tr>
<tr>
<td class="tabxpl"><a href="reference.htm#set">set</a>,
<a href="reference.htm#solvesdp">solvesdp</a>,
<a href="reference.htm#sdpvar">sdpvar</a></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" bordercolor="#FF9933">
<tr>
<td class="tableheader">
<p class="tableheader"><a name="dualize">DUALIZE</a></p>
</td>
</tr>
<tr>
<td>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Syntax</th>
<td class="code" valign="top" nowrap width="100%"><code>
[Fd,objd,X,free] = dualize(F,obj)</code></td>
</tr>
<tr>
<td class="tabxpl">
<table border="0">
<tr>
<td>
<p align="right"><font face="Courier New" size="2">F:</font></p>
</td>
<td>set object in primal SDP form</td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">obj:</font></p>
</td>
<td>sdpvar object (primal cost)</td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">Fd:</font></p>
</td>
<td>set object in dual SDP form</td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New">objd</font><font face="Courier New" size="2">:</font></p>
</td>
<td>sdpvar object (dual cost)</td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">X:</font></p>
</td>
<td>cell of sdpvar object (primal cone variables)</td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">free:</font></p>
</td>
<td>sdpvar objects (free primal variables)</td>
</tr>
</table>
</td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Description</th>
</tr>
<tr>
<td class="tabxpl">dualize is used to convert a SDP problem given
in primal form to the corresponding dual problem.</td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Examples</th>
</tr>
<tr>
<td class="tabxpl">Consider the following SDP problem in primal
form.<table cellpadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>X = sdpvar(3,3);
Y = sdpvar(3,3);
F = set(X>0) + set(Y>0);
F = F + set(X(1,3)==9) + set(Y(1,1)==X(2,2)) + set(sum(sum(X))+sum(sum(Y)) == 20);
obj = trace(X)+trace(Y);</pre>
</td>
</tr>
</table>
<p>We can solve this in the given format. This will however be
very inefficient in YALMIP, since the matrices X and Y will be
explicitely parameterized, and the problem will be solved in a
dual form with equality constraints. Instead, we note that the
problem is an SDP in standard primal form. We therefor let YALMIP
extract this primal model, and return the dual of this. If we
solve this problem, the dual of this will be the original primal.
Confused yet? (note that the dual objective should be maximized)</p>
<table cellpadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>[Fd,objd,XX,y] = dualize(F,obj);
solvesdp(Fd,-objd);</pre>
</td>
</tr>
</table>
<p>To obtain our original variables, we extract the duals</p>
<table cellpadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>assign(XX{1},dual(Fd(1));
assign(XX{2},dual(Fd(2));</pre>
</td>
</tr>
</table>
<p>Check out the tutorial for more <a href="dual.htm#dualize">
examples</a></td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Related commands</th>
</tr>
<tr>
<td class="tabxpl">
<a href="reference.htm#dual">dual</a>,
<a href="reference.htm#set">set</a>,
<a href="reference.htm#solvesdp">solvesdp</a>,
<a href="reference.htm#sdpvar">sdpvar</a></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" bordercolor="#FF9933">
<tr>
<td class="tableheader">
<p class="tableheader"><a name="export">EXPORT</font></a></p>
</td>
</tr>
<tr>
<td>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Syntax<p> </p>
</th>
<td class="code" valign="top" nowrap width="100%"><code>[model,recoverymodel]
= export(F,h,ops)</code></td>
</tr>
<tr>
<td class="tabxpl">
<table border="0">
<tr>
<td>
<p align="right"><font face="Courier New" size="2">model:</font></p>
</td>
<td>Output structure.</td>
</tr>
<tr>
<td>
<font face="Courier New" size="2">recoverymodel:</font></td>
<td>Output structure.</td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">F:</font></p>
</td>
<td>set object describing the constraints. </td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">h:</font></p>
</td>
<td>sdpvar-object describing the objective function.</td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">ops:</font></p>
</td>
<td>options structure from sdpsettings.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Description</th>
</tr>
<tr>
<td class="tabxpl">export is used to export YALMIP models to
various solver formats (<font color="#FF0000">note : not all
solvers are supported yet</font>)</td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Examples</th>
</tr>
<tr>
<td class="tabxpl"><p>Consider a Lyapunov stability problem</p><table cellpadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>A = randn(5,5);A = -A*A';
P = sdpvar(5,5);
F = set(A'*P+P*A < 0) + set(P>eye(5));
obj = trace(P);</pre>
</td>
</tr>
</table>
<p>Exporting this to a model in SeDuMi format is done by
specifying the solver as <code>'sedumi'</code> and calling export in the same way
as <a href="reference.htm#solvesdp">solvesdp</a> would have ben called.</p>
<table cellpadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>[model,recoverymodel] = export(F,obj,sdpsettings('solver','sedumi'));</pre>
<pre><font color="#000000">model = </font></pre>
<pre><font color="#000000"> A: [50x15 double]
b: [15x1 double]
C: [50x1 double]
K: [1x1 struct]
pars: [1x1 struct]</font></pre>
</td>
</tr>
</table>
<p>The data in <code>recoverymodel</code> can be used to relate a solution
obtained from using the exported model, to the actual variables in
YALMIP. </p>
<table cellpadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>[x,y] = sedumi(model.A,model.b,model.C,model.K);
assign(recover(recoverymodel.used_variables),y);</pre>
</td>
</tr>
</table>
<p>Some solvers do not support equality constraints. One way to
handle this in YALMIP is to use <code>sdpsettings('remove',1)</code>.
If this is done, YALMIP derives basis and
solves the problem in the reduced variables. This basis is
communicated through the structure <code>recoverymodel</code>.</p>
<table cellpadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>ops = sdpsettings('solver','sedumi','remove',1);
[model,recoverymodel] = export(F+set(trace(P)==10),obj,ops);
[x,y] = sedumi(model.A,model.b,model.C,model.K);
assign(recover(recoverymodel.used_variables),recoverymodel.x_equ + recoverymodel.H*y);</pre>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Related commands</th>
</tr>
<tr>
<td class="tabxpl"><a href="reference.htm#solvesdp">solvesdp</a></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" bordercolor="#FF9933">
<tr>
<td class="tableheader">
<p class="tableheader"><a name="hessian">HESSIAN</a></p>
</td>
</tr>
<tr>
<td>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Syntax</th>
<td class="code" valign="top" nowrap width="100%"><code>H = hessian(f,x)</code></td>
</tr>
<tr>
<td class="tabxpl">
<table border="0">
<tr>
<td>
<p align="right"><font face="Courier New" size="2">H:</font></p>
</td>
<td>sdpvar object</td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">f:</font></p>
</td>
<td>scalar sdpvar object </td>
</tr>
<tr>
<td>
<p align="right"><font face="Courier New" size="2">x:</font></p>
</td>
<td>sdpvar object</td>
</tr>
</table>
</td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Description</th>
</tr>
<tr>
<td class="tabxpl">Hessian calculates d2f/dx2</td>
</tr>
<tr>
<th class="doc" valign="top" nowrap align="left" bgcolor="#eeeeee" rowspan="2">
Examples</th>
</tr>
<tr>
<td class="tabxpl">With only 1 argument, the differentiation is performed
with respect to all involved variables<table cellpadding="10" width="100%">
<tr>
<td class="xmpcode">
<pre>x1 = sdpvar(1,1);
x2 = sdpvar(1,1);
f = x1^4+5*x2^2;
sdisplay(hessian(f))</pre>
<pre><font
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -