Clone this wiki locally
Note: this guide is provided to compile the front-end from sources; you may wish to try out the binaries instead
A front-end MATLAB is under development in CasADi. Below you find instructions about how to install the front-end as well as current limitations. Note that the front-end is still very rudimentary and the recommendation is to instead use the (stable) Python front-end.
CasADi's MATLAB front-end uses an extension of SWIG - the software used to generate CasADi's Python front-end. The work on extending the SWIG to support MATLAB is a collaborate effort and we refer to the swig-devel mailing list (cf. this page) for detailed discussions on how this work is progressing.
To be able to generate the effort, it is therefore necessary to compile the SWIG extension, which can be done as follows:
- Make sure that no other SWIG installation is in your path. On Ubuntu, you can uninstall your current SWIG installation with the command
sudo apt-get remove swig. On OS X and Homebrew, you should be able to keep your existing SWIG installation, just removing it from the path by issuing
brew unlink swig.
- Clone the repository https://github.com/jaeandersson/swig and check out the branch matlab.
- In the SWIG repo, issue
sh autogen.shin the root to update the configure files.
- Compile SWIG using the standard configure-make-make install procedure as described in the installation instructions in the SWIG repo. Make sure the installation was successful and that the compiled swig is in your path.
- Check out the latest revision of the develop branch of CasADI, cf. https://github.com/casadi/casadi/commits/develop.
- Compile CasADi from sources as described on the page https://github.com/casadi/casadi/wiki/InstallationInstructions, but setting
the flags WITH_MATLAB=ON, e.g.
cmake -DWITH_MATLAB=ON -DWITH_PYTHON=ON (+other arguments) ... For LINUX build, the additional flag
-DWITH_DEEPBIND=ONmight be needed to avoid symbol conflicts between MATLAB and plugins such as IPOPT. Inspect the generated CMakeCache.txt and make sure the MATLAB/MEX related variables point to your MATLAB installation. The MATLAB interface will be installed to
- Start MATLAB and run the command
pathtool. Add the path to the MATLAB interface (e.g. /home/myname/local/matlab).
Syntax and usage
The syntax of the MATLAB interface follows the Python interface closely. The major differences are summarized in the user guide: http://casadi.sourceforge.net/users_guide/html/node9.html
To convert a CasADi matrix to a MATLAB dense or sparse matrix, use the syntax
- Solve the Rosenbrock problem: rosenbrock.m