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 \(Q^o\) and \(Q^k\) are all symmetric because
This implies that a non-symmetric \(Q\) can be replaced by the symmetric matrix \(\half(Q+Q^T)\).
The problem is required to be convex. More precisely, the matrix \(Q^o\) must be positive semi-definite and the \(k\)th constraint must be of the form
with a negative semi-definite \(Q^k\) or of the form
with a positive semi-definite \(Q^k\). This implies that quadratic equalities are not allowed. Specifying a non-convex problem will result in an error when the optimizer is called.
A matrix is positive semidefinite if all the eigenvalues of \(Q\) are nonnegative. An alternative statement of the positive semidefinite requirement is
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 \(\half\) in the objective function of (6.28) which implies that diagonal elements must be doubled in \(Q\), i.e. \(Q_{11}=2\) even though \(1\) is the coefficient in front of \(x_1^2\) in (6.30).
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 \(Q\) matrix in prob
. mosekopt
requires that \(Q\) is specified in a sparse format. Indeed the vectors qosubi
, qosubj
, and qoval
are used to specify the coefficients of \(Q\) in the objective using the principle
An important observation is that due to \(Q\) being symmetric, only the lower triangular part of \(Q\) should be specified.
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 \(Q\) matrix is included as the first argument of the call. Similarly, the solution can be inspected by viewing 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));