6.9 Quadratic Optimization¶
MOSEK can solve quadratic and quadratically constrained problems, as long as they are convex. This class of problems can be formulated as follows:
Without loss of generality it is assumed that
This implies that a non-symmetric
The problem is required to be convex. More precisely, the matrix
with a negative semi-definite
with a positive semi-definite
A matrix is positive semidefinite if all the eigenvalues of
If the convexity (i.e. semidefiniteness) conditions are not met MOSEK will not produce reliable results or work at all.
6.9.1 Example: Quadratic Objective¶
We look at a small problem with linear constraints and quadratic objective:
The matrix formulation of (6.30) has:
with the bounds:
Please note the explicit
Using mosekopt
In Listing 6.17 we show how to use mosekopt
to solve problem (6.30). This is the preferred way.
This sequence of commands looks much like the one that was used to solve the linear optimization example using mosekopt
except that the definition of the prob
. mosekopt
requires that qosubi
, qosubj
, and qoval
are used to specify the coefficients of
An important observation is that due to
Using mskqpopt
In Listing 6.18 we show how to use mskqpopt
to solve problem (6.30).
It should be clear that the format for calling mskqpopt
is very similar to calling msklpopt
except that the res.sol
field.
6.9.2 Example: Quadratic constraints¶
In this section we show how to solve a problem with quadratic constraints. Please note that quadratic constraints are subject to the convexity requirement (6.29).
Consider the problem:
This is equivalent to
where
The linear parts and quadratic objective are set up the way described in the previous tutorial.
Setting up quadratic constraints
function qcqo1()
clear prob;
% Specify the linear objective terms.
prob.c = [0, -1, 0];
% Specify the quadratic terms of the constraints.
prob.qcsubk = [1 1 1 1 ]';
prob.qcsubi = [1 2 3 3 ]';
prob.qcsubj = [1 2 3 1 ]';
prob.qcval = [-2.0 -2.0 -0.2 0.2]';
% Specify the quadratic terms of the objective.
prob.qosubi = [1 2 3 3 ]';
prob.qosubj = [1 2 3 1 ]';
prob.qoval = [2.0 0.2 2.0 -1.0]';
% Specify the linear constraint matrix
prob.a = [1 1 1];
% Specify the lower bounds
prob.blc = [1];
prob.blx = zeros(3,1);
[r,res] = mosekopt('minimize',prob);
% Display the solution.
fprintf('\nx:');
fprintf(' %-.4e',res.sol.itr.xx');
fprintf('\n||x||: %-.4e',norm(res.sol.itr.xx));