17.1 Command Reference¶
The MOSEK toolbox provides a set of functions to interface to the MOSEK solver.
Main interface
mosekopt
is the main interface to MOSEK.
Helper functions
These functions provide an easytouse but less flexible interface than the mosekopt
function. In fact these procedures are just wrappers around the mosekopt
interface and they are defined in MATLAB mfiles.
msklpopt
: Solves linear optimization problems.mskqpopt
: Solves quadratic optimization problems.mskenopt
: Solves entropy optimization problems.mskgpopt
: Solves geometric optimization problems.mskscopt
: Solves separable convex optimization problems.
I/O
mskgpwri
: Write a geometric optimization problem to file.mskgpread
: Read a geometric optimization problem from file.
Options
mskoptimget
: Get the solver parameters.mskoptimset
: Set the solver parameters.
MATLAB optimization toolbox compatible functions.
linprog
: Solves linear optimization problems.quadprog
: Solves quadratic optimization problems.intlinprog
: Solves linear optimization problems with integer variables.lsqlin
: Solves leastsquares with linear constraints.lsqnonneg
: Solves leastsquares with nonnegativity constraints.
17.1.1 Main Interface¶

rcode
,res
=mosekopt
(cmd
,prob
,param
,callback
)¶ Solves an optimization problem. Data specifying the optimization problem can either be read from a file or be inputted directly from MATLAB. It also makes possible to write a file.
The following command strings are recognized for the cmd parameter:
anapro
: Runs the problem analyzer.echo(n)
: Controls how much information is echoed to the screen.n
must be a nonnegative integer, where 0 means that no information is displayed and 3 means that all information is displayed.info
: Return the complete task information database in the field info of ares
struct.param
: Return the complete parameter database in res.param.primalrepair
: Performs a primal feasibility repair. See Sec. 14 (Analyzing Infeasible Problems) for details.maximize
: Maximize the objective.max
: Sets the objective sense (similar to.maximize
), without performing an optimization.minimize
: Minimize the objective.min
: Sets the objective sense (similar to.minimize
), without performing an optimization.nokeepenv
: Delete the MOSEK environment after each run. This can increase the license checkout overhead significantly and is therefore only intended as a debug feature.read(name)
: Request that data is read from a filename
.statuskeys(n)
: Controls the format of status keys (problem status, solution status etc.) in the returned problem:statuskeys(0)
– all the status keys are returned as strings,statuskeys(1)
– all the status keys are returned as numeric codes.
symbcon
: Return the symbcon data structure inres.symbcon
. See structuresymbcon
for details.write(name)
: Write problem to the filename
.log(name)
: Write solver logoutput to the filename
.version
: Return the MOSEK version numbers inres.version
.
Parameters:
(string) – The commands to be executed. By default it takes the value minimize.cmd [in]
(prob) – [optional] a structure containing the problem data.prob [in]
(struct) – [optional] a structure which is used to specify algorithmic parameters to MOSEK. The fields ofparam [in]
param
must be valid MOSEK parameter names. Moreover, the values corresponding to the fields must be of a valid type, i.e. the value of a string parameter must be a string, the value of an integer paramter must be an integer etc.
(callback) – [optional] A MATLAB structure defining callback data and functions.callback [in]
Return:
(rescode) – Return code. The interpretation of the value of the return code is listed in Sec. 17.6 (Enumerations).rcode
(res) – [optional] Solution obtained by the interiorpoint algorithm.res
17.1.2 Helper Functions¶

res
=msklpopt
(c
,a
,blc
,buc
,blx
,bux
,param
,cmd
)¶ Solves a linear optimization problem of the form
\[\begin{split}\begin{array} {ll} min & c^T x \\ st. & \\ & blc \leq Ax \leq buc\\ & bux \leq x \leq bux. \end{array}\end{split}\]Note
lc=[] and buc=[] means that the lower and upper bounds are plus and minus infinite respectively. The same interpretation is used for
blx
andbux
. Noteinf
is allowed inblc
andblx
. Similarly, inf is allowed in buc and bux.Parameters:
(double[]) – The objective function vector.c [in]
(double[][]) – A (preferably sparse) matrix.a [in]
(double[]) – Constraints lower bounds.blc [in]
(double[]) – Constraints upper bounds.buc [in]
(double[]) – Variables lower bounds.blx [in]
(double[]) – Variables upper bounds.bux [in]
(list) – New MOSEK parameters.param [in]
(list) – [optional] The command list. Seecmd [in]
mosekopt
for a list of available commands.
Return:
(res) – [optional] Solution information.res

res
=mskqpopt
(q
,c
,a
,blc
,buc
,blx
,bux
,param
,cmd
)¶ Solves the optimization problem
\[\begin{split}\begin{array}{lc} \min & \half x^T Q x + c^T x\\ st. & \\ & blc \leq Ax \leq buc\\ & blx\leq x \leq bux\\ \end{array}\end{split}\]Note
blc=[] and buc=[] means that the lower and upper bounds are plus and minus infinite respectively. The same interpretation is used for blx and bux. Note inf is allowed in blc and blx. Similarly, inf is allowed in buc and bux.
Parameters:
(double[]) – It is assumed that q is a symmetric positive semidefinite matrix.q
(double[]) – A vector.c [in]
(float[][]) – A (preferably) sparse matrix.a
(double[]) – Constraints lower bounds.blc [in]
(double[]) – Constraints upper boundsbuc [in]
(double[]) – Variables lower boundsblx [in]
(double[]) – Variables upper boundsbux [in]
(list) – MOSEK parameters.param [in]
(string) – [optional] The command list. Seecmd [in]
mosekopt
for a list of available commands.
Return:
(res) – [optional] Solution information.res

res
=mskenopt
(d
,c
,a
,blc
,buc
,param
,cmd
)¶ Solves the entropy optimization problem
\[\begin{split}\begin{array}{lc} \min & d^T (\sum x_i ln(x_i))+c^T x \\ \text{s.t.} & blc \leq Ax \leq buc\\ & x\in \R^n_+ \end{array}\end{split}\]It is required that \(d \geq 0.0\).
Parameters:
(double[]) – A vector of non negative values.d [in]
(double[]) – A vector.c [in]
(double[][]) – A (preferably) sparse matrix.a [in]
(double[]) – [optional] Constraints lower bounds.blc [in]
(double[]) – [optional] Constraints Upper bounds.buc [in]
(list) – [optional] MOSEK parameters.param [in]
(list) – [optional] MOSEK commands. Seecmd [in]
mosekopt
for a list of available commands.
Return:
(res) – [optional] Solution information.res

res
=mskgpopt
(c
,a
,map
,param
,cmd
)¶ Solves the posynomial version of the geometric optimization problem in exponential form:
(1)¶\[\begin{split}\begin{array}{ll} \min & \log(sum(k \in find(map==0),c(k)*exp(a(k,:)*x))\\ st. & \log(sum(k \in find(map==i),c(k)*exp(a(k,:)*x)) <= 0, for k=1,...,max(map) \end{array}\end{split}\]It is required that \(c>0.0\). See Sec. 7.3 (Geometric Optimization).
Parameters:
(double[]) – A vector.c [in]
(double[][]) – A (preferably) sparse matrix.a [in]
(int[][]) – Corresponds to the set \(J\) in Sec. 7.3 (Geometric Optimization).map
(list) – [optional] MOSEK parameters.param [in]
(list) – [optional] The command list. Seecmd [in]
mosekopt
for a list of available commands.
Return:
(res) – [optional] Solution information.res
See also:

res
=mskscopt
(opr
,opri
,oprj
,oprf
,oprg
,c
,a
,blc
,buc
,blx
,bux
,param
,cmd
)¶ Solves separable convex optimization problems on the form
\[\begin{split}\begin{array} {ll} \min & c^T x + \sum_j f_j(x_j)\\ \text{s.t.} & blc \leq a_ x + \sum_j g_{kj}(x_j) \leq buc(k), k=1,...,size(a)\\ & blx \leq x \leq bux\\ \end{array}\end{split}\]The nonlinear functions \(f_j\) and \(g_{kj}\) are specified using
opr, opri, oprj oprf, oprg
as follows. For allk
between 1 andlength(opri)
then following nonlinear expressionif opr(k,:)=='ent' oprf(k) * x(oprj(k)) * log(x(oprj(k))) elseif if opr(k,:)=='exp' oprf(k) * exp(oprg(k)*x(oprj(k))) elseif if opr(k,:)=='log' oprf(k) * log(x(oprj(k))) elseif if opr(k,:)=='pow' oprf(k) * x(oprj(k))^oprg(k) else An invalid operator has been specified.
Is added to the objective if
opri(k)=0
. Otherwise it is added to constraintopri(k)
.Parameters:
(double[]) – Is a vector.c [in]
(double[][]) – Is a (preferably) sparse matrix.a [in]
(double[]) – [optional] Lower bounds on constraints.blc [in]
(double[]) – [optional] Upper bounds on constraints.buc [in]
(double[]) – [optional] Lower bounds on variables.blx [in]
(double[]) – [optional] Upper bounds on variables.bux [in]
(list) – [optional] MOSEK parameters.param [in]
(list) – [optional] The command list. Seecmd [in]
mosekopt
for a list of available commands.
Return:
(res) – [optional] Solution information.res
17.1.3 I/O¶

c
,a
,map
=mskgpread
(filename
)¶ This function reads a Geometric Programming (gp) problem from a file compatible with the
mskenopt
command tool.Parameters:
(string) – The name of the file to read.filename [in]
Return:
17.1.4 Options¶

val
=mskoptimget
(options
,param
,default
)¶ Obtains a value of an optimization parameter. See the
mskoptimset
function for which parameters that can be set.Parameters:
(struct) – The optimization options structure.options [in]
(string) – Name of the optimization parameter for which the value should be obtained.param [in]
(string) – [optional] Ifdefault [in]
param
is not defined, the value ofdefault
is returned instead.
Return:
(list) – Value of the required option. If the option does not exist, thenval
[]
is returned unless the valuedefault
is defined in which case the default value is returned.

options
=mskoptimset
(arg1
,arg2
,param1
,value1
,param2
,value2
,...
)¶ Obtains and modifies the optimization options structure. Only a subset of the fields in the optimization structure recognized by the MATLAB optimization toolbox is recognized by MOSEK. In addition the optimization options structure can be used to modify all the MOSEK specific parameters defined in Sec. 17.4 (Parameters (alphabetical list sorted by type)).
.Diagnostics
Used to control how much diagnostic information is printed. Following values are accepted:off
No diagnostic information is printed. on
Diagnostic information is printed. .Display
Defines what information is displayed. The following values are accepted:off
No output is displayed. iter
Some output is displayed for each iteration. final
Only the final output is displayed. .MaxIter
Maximum number of iterations allowed..Write
A filename to write the problem to. If equal to the empty string no file is written. E.g the optionWrite(myfile.opf)
writes the filemyfile.opf
in theopf
format.
Parameters:
(None) –arg1 [in]
[optional] Is allowed to be any of the following two things [in]:
 Any string The same as using no argument.
 A structure The argument is assumed to be a structure containing options, which are copied to the return options.
(string) – [optional] A string containing the name of a parameter that should be modified.param1 [in]
(None) – [optional] The new value assigned to the parameter with the namevalue1 [in]
param1
.
(None) – [optional] Seeparam2 [in]
param1
.
(None) – [optional] Seevalue2 [in]
value1
.
Return:
(struct) – The updated optimization options structure.options
17.1.5 MATLAB Optimization Toolbox Compatible Functions.¶

x
,fval
,exitflag
,output
=intlinprog
(f
,A
,b
,B
,c
,x0
,options
)¶ 
x
,fval
,exitflag
,output
=intlinprog
(problem
) Solves the binary linear optimization problem:
\[\begin{split}\begin{array} {lc} \mbox{minimize} & f^T x \\ \mbox{subject to} & A x \leq b,\\ & B x = c,\\ & x \in \{0,1\}^n \end{array}\end{split}\]Parameters:
(double[]) – The objective function.f [in]
(double[][]) – Constraint matrix for the inequalities. UseA [in]
A=[]
if there are no inequalities.
(double[]) – Righthand side for the inequalities. Useb [in]
b=[]
if there are no inequalities.
(double[][]) – [optional] Constraint matrix for the equalities. UseB [in]
B=[]
if there are no equalities.
(double[]) – [optional] Righthand side for the equalities. Usec [in]
c=[]
if there are no equalities.
(double[]) – [optional] A feasible starting point.x0 [in]
(struct) –options [in]
[optional] An optimization options structure. See the
mskoptimset
function for the definition of the optimization options structure.intlinprog
uses the options.Diagnostics
.Display
.MaxTime
The maximum number of seconds in the solutiontime.MaxNodes
The maximum number of branchandbounds allowed.Write
Filename of problem file to save.
(struct) – A structure containing the fieldsproblem [in]
f, A, b, B, c, x0
andoptions
.
Return:
(double[]) – The solution \(x\).x
(double) – The objective \(f^T x\).fval
(int) –exitflag
A number which has the interpretation:
 \(1\) The function returned an integer feasible solution.
 \(2\) The problem is infeasible.
 \(4\)
maxNodes
reached without converging.  \(5\)
maxTime
reached without converging.

x
,fval
,exitflag
,output
,lambda
=linprog
(f
,A
,b
,B
,c
,l
,u
,x0
,options
)¶ 
x
,fval
,exitflag
,output
,lambda
=linprog
(problem
) Solves the linear optimization problem:
\[\begin{split}\begin{array} {lc} \mbox{minimize} & f^T x \\ \mbox{subject to} & A x \leq b, \\ & B x = c, \\ & l \leq x \leq u. \end{array}\end{split}\]Parameters:
(double[]) – The objective function.f [in]
(double[][]) – Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.A [in]
(double[]) – Righthand side for the inequalities. Use \(b=[]\) if there are no inequalities.b [in]
(double[][]) – [optional] Constraint matrix for the equalities. Use \(B=[]\) if there are no equalities.B [in]
(double[]) – [optional] Righthand side for the equalities. Use \(c=[]\) if there are no equalities.c [in]
(double[]) – [optional] Lower bounds on the variables. Use \(\infty\) to represent infinite lower bounds.l [in]
(double[]) – [optional] Upper bounds on the variables. Use \(\infty\) to represent infinite upper bounds.u [in]
(double[]) – [optional] An initial guess for the starting point. Only used for the primal simplex algorithm. For more advanced warmstarting (e.g., using dual simplex), usex0 [in]
mosekopt
directly.
(struct) –options [in]
[optional] An optimization options structure. See the
mskoptimset
function for the definition of the optimization options structure.linprog
uses the options.Diagnostics
.Display
.MaxIter
.Simplex
Valid values are'on'
,'primal'
or'dual'
. IfSimplex
is'on'
then MOSEK will use either a primal or dual simplex solver (similar as specifying"MSK_OPTIMIZER_FREE_SIMPLEX"
inmosekopt
; otherwise either a primal or dual simplex algorithm is used. Note, that the'primal'
and'dual'
values are specific for the MOSEK interface, and not present in the standard MATLAB version..Write
Filename of problem file (e.g.,'prob.opf'
) to be saved. This is useful for reporting bugs or problems.
(struct) – structure containing the fieldsproblem [in]
f
,A
,b
,B
,c
,l
,u
,x0
andoptions
.
(struct) –output [in]
A struct with the following fields
.iterations
Number of iterations spent to reach the optimum..algorithm
Always defined as ’largescale [in]: interiorpoint’.
(struct) –lambda [in]
A struct with the following fields
.lower
Lagrange multipliers for lower bounds \(l\)..upper
Lagrange multipliers for upper bounds \(u\)..ineqlin
Lagrange multipliers for the inequalities..eqlin
Lagrange multipliers for the equalities.
Return:
(double[]) – The optimal \(x\) solution.x
(double) – The optimal objective value, i.e. \(f^T x\).fval
(int) –exitflag
A number which has the interpretation [in]:
 \(<0\) The problem is likely to be either primal or dual infeasible.
 \(=0\) The maximum number of iterations was reached.
 \(>0\) \(x\) is an optimal solution.

x
,resnorm
,residual
,exitflag
,output
,lambda
=lsqlin
(C
,d
,A
,b
,B
,c
,l
,u
,x0
,options
)¶ Solves the linear least squares problem:
(2)¶\[\begin{split}\begin{array} {lc} \mbox{minimize} & \half \left\ C x  d\right\_2^2 \\ \mbox{subject to} & A x \leq b, \\ & B x = c, \\ & l \leq x \leq u. \end{array}\end{split}\]Parameters:
(double[][]) – A matrix. See problem (2) for the purpose of the argument.C [in]
(double[]) – A vector. See problem (2) for the purpose of the argument.d [in]
(double[][]) – Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.A [in]
(double[]) – Righthand side for the inequalities. Use \(b=[]\) if there are no inequalities.b [in]
(double[][]) – [optional] Constraint matrix for the equalities. Use \(B=[]\) if there are no equalities.B [in]
(double[]) – [optional] Righthand side for the equalities. Use \(c=[]\) if there are no equalities.c [in]
(double[]) – [optional] Lower bounds on the variables. Use \(\infty\) to represent infinite lower bounds.l [in]
(double[]) – [optional] Upper bounds on the variables. Use \(\infty\) to represent infinite lower bounds.u [in]
(double[]) – [optional] An initial guess for the starting point. This information is ignored by MOSEKx0 [in]
(struct) –options [in]
[optional] An optimization options structure. See the function
mskoptimset
function for the definition of the optimization options structure.lsqlin
uses the options.Diagnostics
.Display
.MaxIter
.Write
Return:
(double[]) – The optimal \(x\) solution.x
(double) – The squared norm of the optimal residuals, i.e. \(\left\ Cxd \right\^2\) evaluated at the optimal solution.resnorm
(double) – The residual \(C x  d\).residual
(int) –exitflag
A scalar which has the interpretation:
 \(<0\) The problem is likely to be either primal or dual infeasible.
 \(=0\) The maximum number of iterations was reached.
 \(>0\) \(x\) is the optimal solution.
(struct) –output
.iterations
Number of iterations spent to reach the optimum..algorithm
Always defined as ’largescale: interiorpoint’.
(struct) –lambda
.lower
Lagrange multipliers for lower bounds \(l\)..upper
Lagrange multipliers for upper bounds \(u\)..ineqlin
Lagrange multipliers for inequalities..eqlin
Lagrange multipliers for equalities.

x
,resnorm
,residual
,exitflag
,output
,lambda
=lsqnonneg
(C
,d
,x0
,options
)¶ Solves the linear least squares problem:
(3)¶\[\begin{split}\begin{array} {lc} \mbox{minimize} & \half \left\C x  d \right\_2^2 \\ \mbox{subject to} & x \geq 0. \end{array}\end{split}\]This procedure just provides an easy interface to
lsqlin
. Indeed all the procedure does is to calllsqlin
with the appropriate arguments.Parameters:
(double[][]) – See problem (3).C [in]
(double[]) – See problem (3).d [in]
(double[]) – [optional] An initial guess for the starting point. This information is ignored by MOSEKx0 [in]
(struct) –options [in]
[optional] An optimizations options structure. See the
mskoptimset
function for the definition of the optimization options structure.lsqlin
uses the options.Diagnostics
.Display
.MaxIter
.Write
Return:
(double[]) – The \(x\) solution.x
(double) –resnorm
The squared norm of the optimal residuals, i.e. .. math:: left Cxd right^2
evaluated at the optimal solution.
(double) – The residual \(C x  d\).residual
(int) –exitflag
A number which has the interpretation:
 \(<0\) The problem is likely to be either primal or dual infeasible.
 \(=0\) The maximum number of iterations was reached.
 \(>0\) \(x\) is optimal solution.
(struct) –output
.iterations
Number of iterations spend to reach the optimum..algorithm
Always defined to be ’largescale: interiorpoint’.
(struct) –lambda
.lower
Lagrange multipliers for lower bounds \(l\)..upper
Lagrange multipliers for upper bounds \(u\)..ineqlin
Lagrange multipliers for inequalities..eqlin
Lagrange multipliers for equalities.

x
,fval
,exitflag
,output
,lambda
=quadprog
(H
,f
,A
,b
,B
,c
,l
,u
,x0
,options
)¶ Solves the quadratic optimization problem:
(4)¶\[\begin{split}\begin{array} {lc} \mbox{minimize} & \half x^T H x + f^T x \\ \mbox{subject to} & A x \leq b, \\ & B x = c, \\ & l \leq x \leq u. \end{array}\end{split}\]Parameters:
(double[][]) – Hessian of the objective function. \(H\) must be a symmetric matrix. Contrary to the MATLAB optimization toolbox, MOSEK handles only the cases where \(H\) is positive semidefinite. On the other hand MOSEK always computes a global optimum, i.e. the objective function has to be strictly convex.H [in]
(double[]) – See (4) for the definition.f [in]
(double[][]) – Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.A [in]
(double[]) – Righthand side for the nequalities. Use \(b=[]\) if there are no inequalities.b [in]
(double[][]) – [optional] Constraint matrix for the equalities. Use \(B=[]\) if there are no equalities.B [in]
(double[]) – [optional] Righthand side for the equalities. Use \(c=[]\) if there are no equalities.c [in]
(double[]) – [optional] Lower bounds on the variables. Use \(\infty\) to represent infinite lower bounds.l [in]
(double[]) – [optional] Upper bounds on the variables. Use \(\infty\) to represent infinite upper bounds.u [in]
(double[]) – [optional] An initial guess for the starting point. This information is ignored by MOSEKx0 [in]
(struct) –options [in]
[optional] An optimization options structure. See the
mskoptimset
function for the definition of the optimizations options structure.quadprog
uses the options.Diagnostics
.Display
.MaxIter
.Write
Return:
(double[]) – The \(x\) solution.x
(double) – The optimal objective value i.e. \(\half x^T H x + f^T x\).fval
(int) –exitflag
A scalar which has the interpretation:
 \(<0\) The problem is likely to be either primal or dual infeasible.
 \(=0\) The maximum number of iterations was reached.
 \(>0\) \(x\) is an optimal solution.
(struct) –output
A structure with the following fields
.iterations
Number of iterations spent to reach the optimum..algorithm
Always defined as ’largescale: interiorpoint’.
(struct) –lambda
A structure with the following fields
.lower
Lagrange multipliers for lower bounds \(l\)..upper
Lagrange multipliers for upper bounds \(u\)..ineqlin
Lagrange multipliers for inequalities..eqlin
Lagrange multipliers for equalities.