There are two ways to use MOSEK from MATLAB:
The optimization toolbox is the simplest to use for models that are expressed on matrix form whereas the Fusion API is more advantageous for complicated models. In particular this is the case for many semi-definite optimization problems.
Users that are accustomed with ane like the MathWorks optimization toolbox are likely to prefer the MOSEK optimization toolbox.
The optimization toolbox provides a number of functions that allows the user to:
Solve linear optimization problems using either an interior-point or a simplex optimizer.
Solve conic optimization problems involving quadratic and semi-definite cones.
Solve convex quadratic optimization problems possible having quadratic constraints.
Solve mixed-integer linear and conic optimization problems.
Solve linear least squares problems. The problem may have arbitrary linear side constraints.
Solve linearly constrained entropy optimization problems.
Solve geometric programming problems (posynomial programming).
Solve separable convex optimization problems.
The optimization toolbox is matrix oriented and fairly similar to optimization toolbox by MathWorks. Moreover, the MOSEK optimization toolbox provides several functions that are compatible with optimization toolbox available from MathWorks.
The Fusion API provides a model-oriented API with objects for representing variables and constraints, and mechanisms for handling sparse and multi-dimensional variable sets. The Fusion API is more restrictive than the optimizer API: Some properties of variables and constraints are immutable once created, and it is not possible to delete them.
The Fusion API allows a simple declaration of variables

as well as affine functions

where

and

are simple predefined convex sets. For example, for a given matrix

and vector

we may have
where
is a standard quadratic cone. More generally, variables and affine functions of variables are specified as belonging to either
The following sections discuss a simple model implemented using the MOSEK Fusion API.
The following simple portfolio selection model, “alan”, comes from the
GAMS online model collection. The objective is to invest the total wealth of 1.0 in a number of assets such that we minimize the risk, while requiring a certain expected return

.
We operate with 4 assets, hardware, software, show-biz and the risk-less treasure bill. The risk is defined by the covariance matrix
and the expected returns
respectively. A mathematical description of the model is then given as the quadratic optimization problem:
This is not directly applicable to Fusion, which requires a conic formulation. To that end, let
be a Cholesky factorization with Cholesky factor
An equivalent formulation is then
which we can write explicitly in conic form as
where
is a standard rotated quadratic cone.
To implement the model, we first define the data for the problem:
-
- securities = [ 'hardware', 'software', 'show-biz', 't-bills' ];
-
- meanreturn = [ 8.0; 9.0; 12.0; 7.0 ];
-
- target = 10.0;
-
-
- U_data = [ 2.0 , 1.5 , -0.5 , 0.0 ; ...
- 0.0 , 1.93649167, 0.90369611 , 0.0 ; ...
- 0.0 , 0.0 , 2.98886824 , 0.0 ; ...
- 0.0 , 0.0 , 0.0 , 0.0 ];
-
- numsec = size(meanreturn,1);
- U = DenseMatrix(U_data);
Then we can create the Model object:
- M = Model('alan');
Then we define the variables as
- x = M.variable('x', numsec, Domain.greaterThan(0.0));
- v = M.variable('variance', 1, Domain.greaterThan(0.0));
- w = M.variable('w', 1, Domain.equalsTo(1.0));
- t = M.variable('t', 1, Domain.unbounded());
and the two linear constraints
-
- M.constraint('wealth', Expr.sum(x), Domain.equalsTo(1.0));
-
- M.constraint('dmean', Expr.dot(meanreturn', x), Domain.greaterThan(target));
and the conic constraint
-
- M.constraint('cone', Expr.vstack(t, ...
- 1.0, ...
- Expr.mul(U,x)), ...
- Domain.inRotatedQCone());
We optimize the model using
- disp('Solve...');
- M.solve();
and extract the

-solution as
- solx = x.level();
- function alan()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- import mosek.fusion.*
-
-
-
-
- securities = [ 'hardware', 'software', 'show-biz', 't-bills' ];
-
- meanreturn = [ 8.0; 9.0; 12.0; 7.0 ];
-
- target = 10.0;
-
-
- U_data = [ 2.0 , 1.5 , -0.5 , 0.0 ; ...
- 0.0 , 1.93649167, 0.90369611 , 0.0 ; ...
- 0.0 , 0.0 , 2.98886824 , 0.0 ; ...
- 0.0 , 0.0 , 0.0 , 0.0 ];
-
- numsec = size(meanreturn,1);
- U = DenseMatrix(U_data);
-
- M = Model('alan');
- x = M.variable('x', numsec, Domain.greaterThan(0.0));
- v = M.variable('variance', 1, Domain.greaterThan(0.0));
- w = M.variable('w', 1, Domain.equalsTo(1.0));
- t = M.variable('t', 1, Domain.unbounded());
-
-
- M.constraint('wealth', Expr.sum(x), Domain.equalsTo(1.0));
-
- M.constraint('dmean', Expr.dot(meanreturn', x), Domain.greaterThan(target));
-
-
- M.constraint('cone', Expr.vstack(t, ...
- 1.0, ...
- Expr.mul(U,x)), ...
- Domain.inRotatedQCone());
-
- M.objective('minvar', ObjectiveSense.Minimize, t);
-
- disp('Solve...');
- M.solve();
- disp('... Solved.');
-
- solx = x.level();
- disp([ 'Solution = ' mat2str(solx) ]);