# 15.2 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 easy-to-use but less flexible interface than the `mosekopt`

function. They are just wrappers around the `mosekopt`

interface written in MATLAB.

Options

Functions for manipulating parameter values.

`mskoptimget`

: Get the solver parameters.`mskoptimset`

: Set the solver parameters.

MATLAB Optimization Toolbox compatible functions.

Functions that override standard functions from the MATLAB Optimization Toolbox (the user may choose not to install those).

`linprog`

: Solves linear optimization problems.`quadprog`

: Solves quadratic optimization problems.`intlinprog`

: Solves linear optimization problems with integer variables.`lsqlin`

: Solves least-squares with linear constraints.`lsqnonneg`

: Solves least-squares with non-negativity constraints.

## 15.2.1 Main Interface¶

- rcode, res = mosekopt(cmd, prob, param, callback, optserver)¶
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 it possible to write a file and provides other functionalities.

The behavior is specified by the

`cmd`

parameter which recognizes the following commands:`anapro`

: Runs the problem analyzer.`echo(n)`

: Controls how much log information is printed to the screen.`n`

must be a nonnegative integer, where 0 means silent. See Sec. 7.3.1 (Stream logging).`info`

: Return the complete task information database in`res.info`

. See Sec. 7.5 (Retrieving information items).`param`

: Return the complete parameter database in`res.param`

. See Sec. 7.4 (Setting solver parameters).`primalrepair`

: Performs a primal feasibility repair. See Sec. 14.2 (Automatic Repair of Infeasible Problems).`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`

: Release resources related to the**MOSEK**environment. In particular, check in all the licenses currently checked out, see Sec. 10.4 (The license system).`read(name)`

: Request that data is read from a file`name`

. See Sec. 7.3.4 (Reading a problem from a file).`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 list of symbolic constants in`res.symbcon`

.`write(name)`

: Write problem to the file`name`

. See Sec. 7.3.3 (Saving a problem to a file).`log(name)`

: Write solver log output to the file`name`

. See Sec. 7.3.1 (Stream logging).`version`

: Return the**MOSEK**version numbers in`res.version`

.`debug(n)`

: Prints debug information including license paths.`n`

must be a nonnegative integer which determines how much to print.`toconic prob`

: Deprecated! Convert a quadratic problem to conic form.`lic`

: Provide a license code as the last argument.

- Parameters
`cmd`

(string) – The commands to be executed. By default it takes the value`minimize`

.`prob`

(`prob`

) – A structure containing the problem data. (optional)`param`

(struct) – A structure specifying**MOSEK**parameters. See Sec. 7.4 (Setting solver parameters). (optional)`callback`

(`callback`

) – A MATLAB structure defining call-back data and functions. See Sec. 7.6 (Progress and data callback). (optional)`optserver`

(`optserver`

) – A MATLAB structure specifying the OptServer to be used for remote optimization. (optional)

- Return
`rcode`

(`rescode`

) – A response code. See also Sec. 7.1 (Accessing the solution).`res`

(`res`

) – A structure containing solutions and other results from the call. See Sec. 7.1 (Accessing the solution).

## 15.2.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} {lc} \mbox{minimize} & c^T x \\ \mbox{subject to} & l^c \leq Ax \leq u^c,\\ & l^x \leq x \leq u^x. \end{array}\end{split}\]`blc=[]`

and`buc=[]`

mean that the lower and upper bounds are \(-\infty\) and \(+\infty\), respectively. The same interpretation is used for`blx`

and`bux`

. The value`-inf`

is allowed in`blc`

and`blx`

. Similarly,`inf`

is allowed in buc and bux.- Parameters
`c [in]`

(double[]) – The objective function vector.`a [in]`

(double[][]) – A (preferably sparse) matrix.`blc [in]`

(double[]) – Constraints lower bounds.`buc [in]`

(double[]) – Constraints upper bounds.`blx [in]`

(double[]) – Variables lower bounds.`bux [in]`

(double[]) – Variables upper bounds.`param [in]`

(struct) –**MOSEK**parameters. (optional)`cmd [in]`

(string) – The command list. See`mosekopt`

for a list of available commands. (optional)

- Return
`res`

(`res`

) – Solution information.

- res = mskqpopt(q, c, a, blc, buc, blx, bux, param, cmd)¶
Solves the optimization problem

\[\begin{split}\begin{array}{lc} \mbox{minimize} & \half x^T Q x + c^T x\\ \mbox{subject to} & l^c \leq Ax \leq u^c,\\ & l^x\leq x \leq u^x. \end{array}\end{split}\]`blc=[]`

and`buc=[]`

mean that the lower and upper bounds are \(-\infty\) and \(+\infty\), respectively. The same interpretation is used for`blx`

and`bux`

. The value`-inf`

is allowed in`blc`

and`blx`

. Similarly,`inf`

is allowed in buc and bux.- Parameters
`q`

(double[]) – The matrix \(Q\), which must be symmetric positive semidefinite.`c [in]`

(double[]) – The objective function vector.`a`

(double[][]) – A (preferably) sparse matrix.`blc [in]`

(double[]) – Constraints lower bounds.`buc [in]`

(double[]) – Constraints upper bounds`blx [in]`

(double[]) – Variables lower bounds`bux [in]`

(double[]) – Variables upper bounds`param [in]`

(struct) –**MOSEK**parameters. (optional)`cmd [in]`

(string) – The command list. See`mosekopt`

for a list of available commands. (optional)

- Return
`res`

(`res`

) – Solution information.

## 15.2.3 Options¶

- val = mskoptimget(options, param, default)¶
Obtains the value of an optimization parameter. See the

`mskoptimset`

function for which parameters that can be set.- Parameters
`options [in]`

(struct) – The optimization options structure.`param [in]`

(string) – Name of the optimization parameter for which the value should be obtained.`default [in]`

(string) – If`param`

is not defined, the value of`default`

is returned instead. (optional)

- Return
`val`

(list) – Value of the required option. If the option does not exist, then`[]`

is returned unless the value`default`

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. 15.5 (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 file name to write the problem to. If equal to the empty string no file is written. E.g the option`Write(myfile.opf)`

writes the file`myfile.opf`

in the`opf`

format.

- Parameters
`arg1 [in]`

(None) –Is allowed to be any of the following two things (optional):

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.

`param1 [in]`

(string) – A string containing the name of a parameter that should be modified. (optional)`value1 [in]`

(None) – The new value assigned to the parameter with the name`param1`

. (optional)`param2 [in]`

(None) – See`param1`

. (optional)`value2 [in]`

(None) – See`value1`

. (optional)

- Return
`options`

(struct) – The updated optimization options structure.

## 15.2.4 MATLAB Optimization Toolbox Compatible Functions.¶

- x, fval, exitflag, output = intlinprog(f, intcon, A, b, B, c, l, u, options)¶
- x, fval, exitflag, output = intlinprog(problem)
Solves the mixed-integer 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,\\ & x(\mathrm{intcon}) \in \integral. \end{array}\end{split}\]- Parameters
`f [in]`

(double[]) – The objective function.`intcon [in]`

(int[]) – The list of variables constrained to the set \(\integral\).`A [in]`

(double[][]) – Constraint matrix for the inequalities. Use`A=[]`

if there are no inequalities.`b [in]`

(double[]) – Right-hand side for the inequalities. Use`b=[]`

if there are no inequalities.`B [in]`

(double[][]) – Constraint matrix for the equalities. (optional)`c [in]`

(double[]) – Right-hand side for the equalities. (optional)`l [in]`

(double[]) – Lower bounds for variables. Use`-inf`

to represent infinite lower bounds. (optional)`u [in]`

(double[]) – Upper bounds for variables. Use`inf`

to represent infinite upper bounds. (optional)`options [in]`

(struct) –An optimization options structure. See the

`mskoptimset`

function for the definition of the optimization options structure (optional). This function uses the options`.Diagnostics`

`.Display`

`.MaxTime`

Time limit in seconds.`.MaxNodes`

The maximum number of branch-and-bounds allowed.`.Write`

Name of file to save the problem.

`problem [in]`

(struct) – A structure containing the fields`f, intcon, A, b, B, c, l, u`

and`options`

.

- Return
`x`

(double[]) – The solution \(x\).`fval`

(double) – The objective \(f^T x\).`exitflag`

(int) –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, 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
`f [in]`

(double[]) – The objective function.`A [in]`

(double[][]) – Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.`b [in]`

(double[]) – Right-hand side for the inequalities. Use \(b=[]\) if there are no inequalities.`B [in]`

(double[][]) – Constraint matrix for the equalities. (optional)`c [in]`

(double[]) – Right-hand side for the equalities. (optional)`l [in]`

(double[]) – Lower bounds on the variables. Use`-inf`

to represent infinite lower bounds. (optional)`u [in]`

(double[]) – Upper bounds on the variables. Use`inf`

to represent infinite upper bounds. (optional)`options [in]`

(struct) –An optimization options structure (optional). See the

`mskoptimset`

function for the definition of the optimization options structure. This function uses the options`.Diagnostics`

`.Display`

`.MaxIter`

`.Simplex`

Choose the simplex algorithm:`'on'`

— the optimizer chooses wither primal or dual simplex (as in`"MSK_OPTIMIZER_FREE_SIMPLEX"`

),`'primal'`

— use primal simplex,`'dual'`

— use dual simplex. The`'primal'`

and`'dual'`

values are specific for the**MOSEK**interface, and not present in the standard MATLAB version.`.Write`

Name of file to save the problem.

`problem [in]`

(struct) – structure containing the fields`f`

,`A`

,`b`

,`B`

,`c`

,`l`

,`u`

and`options`

.`output [in]`

(struct) –A structure with the following fields

`.iterations`

Number of interior-point iterations spent to reach the optimum.`.algorithm`

Always defined as`'MOSEK'`

.

`lambda [in]`

(struct) –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
`x`

(double[]) – The optimal \(x\) solution.`fval`

(double) – The optimal objective value, i.e. \(f^T x\).`exitflag`

(int) –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:

\[\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
`C [in]`

(double[][]) – The matrix in the objective.`d [in]`

(double[]) – The vector in the objective.`A [in]`

(double[][]) – Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.`b [in]`

(double[]) – Right-hand side for the inequalities. Use \(b=[]\) if there are no inequalities.`B [in]`

(double[][]) – Constraint matrix for the equalities. (optional)`c [in]`

(double[]) – Right-hand side for the equalities. (optional)`l [in]`

(double[]) – Lower bounds on the variables. Use`-inf`

to represent infinite lower bounds. (optional)`u [in]`

(double[]) – Upper bounds on the variables. Use`inf`

to represent infinite upper bounds. (optional)`x0 [in]`

(double[]) – Ignored by**MOSEK**. (optional)`options [in]`

(struct) –An optimization options structure (optional). See the function

`mskoptimset`

function for the definition of the optimization options structure. This function uses the options`.Diagnostics`

`.Display`

`.MaxIter`

`.Write`

- Return
`x`

(double[]) – The optimal \(x\) solution.`resnorm`

(double) – The squared norm of the optimal residuals, i.e. \(\left\| Cx-d \right\|_2^2\) evaluated at the optimal solution.`residual`

(double) – The residual \(C x - d\).`exitflag`

(int) –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.

`output`

(struct) –`.iterations`

Number of iterations spent to reach the optimum.`.algorithm`

Always defined as`'MOSEK'`

.

`lambda`

(struct) –`.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:

\[\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}\]- Parameters
`C [in]`

(double[][]) – The matrix in the objective.`d [in]`

(double[]) – The vector in the objective.`x0 [in]`

(double[]) – Ignored by**MOSEK**. (optional)`options [in]`

(struct) –An optimization options structure (optional). See the

`mskoptimset`

function for the definition of the optimization options structure. This function uses the options`.Diagnostics`

`.Display`

`.MaxIter`

`.Write`

- Return
`x`

(double[]) – The \(x\) solution.`resnorm`

(double) – The squared norm of the optimal residuals, i.e. \(\left\| Cx-d \right\|_2^2\) evaluated at the optimal solution.`exitflag`

(int) –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.

`output`

(struct) –`.iterations`

Number of iterations spend to reach the optimum.`.algorithm`

Always defined to be`'MOSEK'`

.

`lambda`

(struct) –`.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:

\[\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
`H [in]`

(double[][]) – Hessian of the objective function. The matrix \(H\) must be symmetric positive semidefinite. 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.`f [in]`

(double[]) – The linear term of the objective.`A [in]`

(double[][]) – Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.`b [in]`

(double[]) – Right-hand side for the inequalities. Use \(b=[]\) if there are no inequalities.`B [in]`

(double[][]) – Constraint matrix for the equalities. (optional)`c [in]`

(double[]) – Right-hand side for the equalities. (optional)`l [in]`

(double[]) – Lower bounds on the variables. Use`-inf`

to represent infinite lower bounds. (optional)`u [in]`

(double[]) – Upper bounds on the variables. Use`inf`

to represent infinite upper bounds. (optional)`x0 [in]`

(double[]) – Ignored by**MOSEK**. (optional)`options [in]`

(struct) –An optimization options structure (optional). See the

`mskoptimset`

function for the definition of the optimizations options structure. This function uses the options`.Diagnostics`

`.Display`

`.MaxIter`

`.Write`

- Return
`x`

(double[]) – The \(x\) solution.`fval`

(double) – The optimal objective value i.e. \(\half x^T H x + f^T x\).`exitflag`

(int) –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.

`output`

(struct) –A structure with the following fields

`.iterations`

Number of iterations spent to reach the optimum.`.algorithm`

Always defined as`'MOSEK'`

.

`lambda`

(struct) –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.