<span id="sdp-mode"></span><h1>Semidefinite programming mode<a class="headerlink" href="#semidefinite-programming-mode" title="Permalink to this headline">¶</a></h1>
<p>Those who are familiar with <em>semidefinite programming</em> (SDP) know that
the constraints that utilize the set <tt class="docutils literal"><span class="pre">semidefinite(n)</span></tt> in the discussion
on <a class="reference internal" href="basics.html#sets"><em>Set membership</em></a> above are, in practice, typically expressed using
<em>linear matrix inequality</em> (LMI) notation. For example, given
<span class="math">\(X=X^T\in\mathbf{R}^{n \times n}\)</span>, the constraint
<span class="math">\(X\succeq 0\)</span> denotes that <span class="math">\(X\in\mathbf{S}^n_+\)</span>; that is,
that <span class="math">\(X\)</span> is positive semidefinite.</p>
<p>CVX provides a special <em>SDP mode</em> that allows this LMI notation
to be employed inside CVX models using Matlab’s standard inequality
operators <tt class="docutils literal"><span class="pre">>=</span></tt>, <tt class="docutils literal"><span class="pre"><=</span></tt>. In order to use it, one simply
begins a model with the statement <tt class="docutils literal"><span class="pre">cvx_begin</span> <span class="pre">sdp</span></tt> or <tt class="docutils literal"><span class="pre">cvx_begin</span> <span class="pre">SDP</span></tt>
instead of simply <tt class="docutils literal"><span class="pre">cvx_begin</span></tt>.</p>
<p>When SDP mode is engaged, CVX
interprets certain inequality constraints in a different manner. To be
specific:</p>
<ul>
<li><p class="first">Equality constraints are interpreted the same (<em>i.e.</em>, elementwise).</p>
</li>
<li><p class="first">Inequality constraints involving vectors and scalars are interpreted
the same; <em>i.e.</em>, elementwise.</p>
</li>
<li><p class="first">Inequality constraints involving non-square matrices are
<em>disallowed</em>; attempting to use them causes an error. If you wish to
do true elementwise comparison of matrices <tt class="docutils literal"><span class="pre">X</span></tt> and <tt class="docutils literal"><span class="pre">Y</span></tt>, use a
<li><p class="first">There is one additional restriction: both <tt class="docutils literal"><span class="pre">X</span></tt> and <tt class="docutils literal"><span class="pre">Y</span></tt> must be the
same size, or one must be the scalar zero. For example, if <tt class="docutils literal"><span class="pre">X</span></tt> and
<tt class="docutils literal"><span class="pre">Y</span></tt> are matrices of size <tt class="docutils literal"><span class="pre">n</span></tt>,</p>
CVX does not extract the symmetric part for you: you must take
care to insure symmetry yourself. Since CVX supports the
declaration of symmetric matrices, this is reasonably
straightforward. If CVX cannot determine that an LMI is symmetric
to within a reasonable numeric tolerance, a warning will be issued.
We have provided a function <tt class="docutils literal"><span class="pre">sym(X)</span></tt> that extracts the symmetric
part of a square matrix; that is, <tt class="docutils literal"><span class="pre">sym(X)</span> <span class="pre">=</span> <span class="pre">0.5*(X+X')</span></tt>.</p>
</li>
<li><p class="first">A dual variable, if supplied, will be applied to the converted
equality constraint. It will be given a positive semidefinite value
if an optimal point is found.</p>
</li>
</ul>
<p>So, for example, the CVX model found in the file
<p>Many other examples in the CVX example library utilize semidefinite
constraints; and all of them use SDP mode. To find them, simply search
for the text <tt class="docutils literal"><span class="pre">cvx_begin</span> <span class="pre">sdp</span></tt> in the <tt class="docutils literal"><span class="pre">examples/</span></tt> subdirectory tree
using your favorite file search tool. One of these examples is
reproduced in <a class="reference internal" href="advanced.html#indexed-dual"><em>Indexed dual variables</em></a>.</p>
<p>Since semidefinite programming is popular, some may wonder why SDP mode
is not the default behavior. The reason for this is that we place a
strong emphasis on maintaining consistency between Matlab’s native
behavior and that of CVX. Using the <tt class="docutils literal"><span class="pre">>=</span></tt>, <tt class="docutils literal"><span class="pre"><=</span></tt>, <tt class="docutils literal"><span class="pre">></span></tt>,
<tt class="docutils literal"><span class="pre"><</span></tt> operators to create LMIs represents a deviation from that ideal.
For example, the expression <tt class="docutils literal"><span class="pre">Z</span> <span class="pre">>=</span> <span class="pre">0</span></tt> in the example above constrains
the variable <tt class="docutils literal"><span class="pre">Z</span></tt> to be positive semidefinite. But after the model has
been solved and <tt class="docutils literal"><span class="pre">Z</span></tt> has been replaced with a numeric value, the
expression <tt class="docutils literal"><span class="pre">Z</span> <span class="pre">>=</span> <span class="pre">0</span></tt> will test for the <em>elementwise</em> nonnegativity of
<tt class="docutils literal"><span class="pre">Z</span></tt>. To verify that the numeric value of <tt class="docutils literal"><span class="pre">Z</span></tt> is, in fact, positive
semidefinite, you must perform a test like <tt class="docutils literal"><span class="pre">min(eig(Z))</span> <span class="pre">>=</span> <span class="pre">0</span></tt>.</p>