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 R2017a or newer on linux64x86, win64x86 and osx64x86 and R2022b Beta or newer on osxaarch64 (see next paragraph).

Apple M1/M2 platform

On the M1/M2 platform (osxaarch64) the choice of toolbox is determined by the architecture of your MATLAB, rather than of the hardware:

  • If you use a MATLAB installation native for Apple Silicon (MACA64, officially available from R2023b, earlier R2022b Beta) then use the osxaarch64 installation of MOSEK and the toolbox from there.

  • If you use a MATLAB installation for Intel (MACI64, runs via Rosetta) then install and use the toolbox form the osx64x86 distribution of MOSEK.

Please check your MATLAB architecture (MACI64 vs. MACA64) to choose the correct MOSEK version for use in MATLAB.

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/10.1/toolbox/<TOOLBOXVER>

Toolbox

<TOOLBOXDIR>

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

Toolbox (without overloading)

<TOOLBOXOMDIR>

<MSKHOME>/mosek/10.1/toolbox/examples

Examples

<EXDIR>

<MSKHOME>/mosek/10.1/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

    • r2017a on linux64x86, win64x86 and osx64x86.

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/10.1/toolbox/r2017a         (linux64x86, osx64x86)
addpath <MSKHOME>/mosek/10.1/toolbox/r2022b         (osxaarch64)
addpath <MSKHOME>\mosek\10.1\toolbox\r2017a         (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/10.1/toolbox/r2017aom         (linux64x86, osx64x86)
addpath <MSKHOME>/mosek/10.1/toolbox/r2022bom         (osxaarch64)
addpath <MSKHOME>\mosek\10.1\toolbox\r2017aom         (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\10.1\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.