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 R2015a or newer on all 64-bit x86 platforms, that is win64x86, linux64x86 and osx64x86.

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/9.3/toolbox/r2015a

Toolbox

<TOOLBOXDIR>

<MSKHOME>/mosek/9.3/toolbox/r2015aom

Toolbox (without overloading)

<TOOLBOXOMDIR>

<MSKHOME>/mosek/9.3/toolbox/examples

Examples

<EXDIR>

<MSKHOME>/mosek/9.3/toolbox/data

Additional data

<MISCDIR>

where <MSKHOME> is the folder in which the MOSEK Optimization Suite has been installed.

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/9.3/toolbox/r2015a

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/9.3/toolbox/r2015aom

On the Windows platform the relevant paths are

addpath <MSKHOME>\mosek\9.3\toolbox\r2015a
addpath <MSKHOME>\mosek\9.3\toolbox\r2015aom

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/r2015a/mosekopt.mexa64
MOSEK version    : 9.0.97
Test linear solve: Success
mosekopt works OK. You can use MOSEK in MATLAB.

or to:

mosekopt: /home/user/somepath/toolbox/r2015a/mosekopt.mexa64
Found MOSEK version : major(9), minor(0), revision(97)
mosekopt is working correctly.

If you only want to use Optimization Toolbox for MATLAB then warnings about non-availability of the command-line interface can be ignored.

More advanced debug information can be obtained with:

mosekopt('debug(10)')

4.2 Troubleshooting

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

If you are using Mac OS and get an error such as

Library not loaded: libmosek64.9.0.dylib
Referenced from:
/Users/.../mosek/9.0/toolbox/r2015a/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\9.0\toolbox\r2015a\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\9.3\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\9.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\9.0\toolbox\r2015a\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\9.0\toolbox\r2015a\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\9.0\toolbox\r2015a\mosekopt.mexw64

and not to a MATLAB .m file,

<MSKHOME>\mosek\9.0\toolbox\r2015a\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.