4 Installation

In this section we discuss how to install and setup the MOSEK Optimization Toolbox for MATLAB.

Important

Before running this MOSEK interface please make sure that you:

  • Installed MOSEK correctly. Some operating systems require extra steps. See the Installation guide for instructions and common troubleshooting tips.

  • Set up a license. See the Licensing guide for instructions.

Compatibility

The Optimization Toolbox for MATLAB can be used with MATLAB version R2019b or newer on linux64x86, win64x86 and R2022b Beta or newer on osxaarch64 (see next paragraph). On the Apple Sillicon (M1/M2/M3) platform you must be using the Apple Sillicon release of MATLAB (MATLAB architecture tag MACA64).

Locating files in the MOSEK Optimization Suite

The relevant files of the Optimization Toolbox for MATLAB are organized as reported in Table 4.1.

Table 4.1 Relevant files for the Optimization Toolbox for MATLAB.

Relative Path

Description

Label

<MSKHOME>/mosek/11.0/toolbox/<TOOLBOXVER>

Toolbox

<TOOLBOXDIR>

<MSKHOME>/mosek/11.0/toolbox/<TOOLBOXVER>om

Toolbox (without overloading)

<TOOLBOXOMDIR>

<MSKHOME>/mosek/11.0/toolbox/examples

Examples

<EXDIR>

<MSKHOME>/mosek/11.0/toolbox/data

Additional data

<MISCDIR>

where

  • <MSKHOME> is the folder in which the MOSEK Optimization Suite has been installed,

  • <TOOLBOXVER> denotes the toolbox version string:

    • r2022b on osxaarch64

    • r2019b on linux64x86, win64x86.

Setting up the paths

To use Optimization Toolbox for MATLAB the path to the toolbox directory must be added via the addpath command in MATLAB. Use the command

addpath <MSKHOME>/mosek/11.0/toolbox/r2019b         (linux64x86)
addpath <MSKHOME>/mosek/11.0/toolbox/r2022b         (osxaarch64)
addpath <MSKHOME>\mosek\11.0\toolbox\r2019b         (win64x86)

or, if you do not want to overload functions such as linprog and quadprog from the MATLAB Optimization Toolbox with their MOSEK versions, then write

addpath <MSKHOME>/mosek/11.0/toolbox/r2019bom         (linux64x86)
addpath <MSKHOME>/mosek/11.0/toolbox/r2022bom         (osxaarch64)
addpath <MSKHOME>\mosek\11.0\toolbox\r2019bom         (win64x86)

Alternatively, the path to Optimization Toolbox for MATLAB may be set from the command line or it can be added to MATLAB permanently using the configuration file startup.m or from the FileSet Path menu item. We refer to MATLAB documentation for details.

4.1 Testing the installation

You can verify that Optimization Toolbox for MATLAB works by executing

mosekdiag

in MATLAB. This should produce a message similar to this:

>> mosekdiag
Matlab version   : 9.2.0.538062 (R2017a)
Architecture     : GLNXA64
mosekopt path    : /home/user/somepath/toolbox/r2017a/mosekopt.mexa64
MOSEK version    : 10.0.18
Test linear solve: Success
mosekopt works OK. You can use MOSEK in MATLAB.

Debug and license path information can also be obtained with:

mosekopt('debug(10)')

4.2 Troubleshooting

Missing library files such as libmosek64.10.0.dylib or similar

If you are using macOS and get an error such as

Library not loaded: libmosek64.10.0.dylib
Referenced from:
/Users/.../mosek/10.0/toolbox/r2017a/mosekopt.mexmaci64
Reason: image not found.

Error in callmosek>doCall (line 224)
[res,sol] = mosekopt('minimize info',prob,param);

then most likely you did not run the MOSEK installation script install.py found in the bin directory. See also the Installation guide for details.

Windows, invalid MEX-file, cannot find shared libraries

If you are using Windows and get an error such as

Invalid MEX-file <MSKHOME>\Mosek\10.0\toolbox\r2017a\mosekopt.mexw64: The specified module could not be found.

then MATLAB cannot load the MOSEK shared libraries, because the folder containing them is not in the system search path for DLLs. This can happen if MOSEK was installed manually and not using the MSI installer. The solution is to add the path <MSKHOME>\mosek\11.0\tools\platform\<PLATFORM>\bin to the system environment variable PATH. This can also be done per MATLAB session by using the setenv command in MATLAB before using MOSEK, for example:

setenv('PATH', [getenv('PATH') ';C:\Users\username\mosek\10.0\tools\platform\win64x86\bin']);

See also the Installation guide for details.

MATLAB String type is not supported

From R2017a MATLAB provides a new string type (with double quotes). It is not supported by the Optimization Toolbox for MATLAB and may cause confusing error messages. For example the following will give an error:

mosekopt("minimize", prob)

Return code - 1200 [MSK_RES_ERR_IN_ARGUMENT] [A function argument is incorrect.]

Always use old-fashioned character arrays (strings in single quotes).

MOSEK does not see new license file

If you updated your license file but MOSEK does not detect it then restart MATLAB. MOSEK is caching the license and it will not notice the change in the license file on disk.

Undefined Function or Variable mosekopt

If you get the MATLAB error message

Undefined function or variable 'mosekopt'

you have not added the path to the Optimization Toolbox for MATLAB correctly as described above.

Invalid MEX-file

For certain versions of Windows and MATLAB, the path to MEX files cannot contain spaces. Therefore, if you have installed MOSEK in C:\Program Files\Mosek and get a MATLAB error similar to:

Invalid MEX-file <MSKHOME>\Mosek\10.0\toolbox\r2017a\mosekopt.mexw64

try installing MOSEK in a different directory, for example C:\Users\<someuser>\ .

Output Arguments not assigned

If you encounter an error like

Error in ==> mosekopt at 1
function [r,res] = mosekopt(cmd,prob,param,callback)

Output argument "r" (and maybe others) not assigned during call to
"C:\Users\username\mosek\10.0\toolbox\r2017a\mosekopt.m>mosekopt".

then a mismatch between 32 and 64 bit versions of MOSEK and MATLAB is likely. From MATLAB type

which mosekopt

which (for a successful installation) should point to a MEX file,

<MSKHOME>\mosek\10.0\toolbox\r2017a\mosekopt.mexw64

and not to a MATLAB .m file,

<MSKHOME>\mosek\10.0\toolbox\r2017a\mosekopt.m

Security exception in MacOS 10.15+ (Catalina)

If an attempt to run MOSEK on Mac OS 10.15 (Catalina) and later produces security exceptions (developer cannot be verified and similar) then use xattr to remove the quarantine attribute from all MOSEK executables and binaries. This can be done in one go with

xattr -dr com.apple.quarantine mosek

where mosek is the folder which contains the full MOSEK installation or MOSEK binaries. See https://themosekblog.blogspot.com/2019/12/macos-1015-catalina-mosek-installation.html for more information. If that does not help, use the system settings to allow running arbitrary unverified applications.