## What langauge is MATLAB written in?

As the resident MATLAB support guy (among other things) at The University of Manchester, I often get asked which language MATLAB is written in. Many people seem to argue over whether or not it is Fortran or C with the prevailing wisdom being ‘It was originally written in Fortran for the free version 1 and then was re-written in C when it went commercial’.

Well, I am not sure about the history but looking at moden MATLAB, the question should be which **languages**, rather than which **language**! The list I have so far is

- C (many built in compiled mex functions are written in C)
- C++ (MATLAB makes use of the Boost C++ libraries..thanks to M in the comments for this one)
- CIL (Common Intermediate Langauge, used to be called MSIL, – The windows version of MATLAB uses this for various .NET stuff. Thanks to ‘pmcs’ in the comments for this one)
- NVidia CUDA (Routines in the GPU part of the parallel computing toolbox)
- Bash shell script (On Linux, the startup ‘binary’ is a shell script)
- Fortran (MATLAB uses the MKL and I’m fairly sure this is written in Fortran)
- Java (Many of the ticks in Yair Altman’s excellent book, Undocumented Secrets of MATLAB-Java Programming make use of the Java elements in MATLAB
- MATLAB (many MATLAB functions are written in .m code)
- Perl (Many mex-related scripts are written in Perl)
- Windows batch files (I’ve seen some simple .bat files as part of the mex machinery)

It also appears to be using some C++ — notice the presence of several Boost DLLs in the binary directory, indicating the use of Boost C++ Libraries, http://www.boost.org/.

Thanks for that…added to the list.

In addition to C++, there’s also a fair bit of MSIL floating about in the Windows version. Presumably this is largely to help with .NET integration (which is, by the way, awesome, and even more useful than Matlab’s Java interop).

Added, thanks :). I’ve not used the .NET interop stuff. Do you have a link to info showing its usefulness?

I think one of MATLAB’s strengths is that so much of the language/features is built with the MATLAB language.

There is a lot to learn and build from.

Try doing that with R. If you don’t have experience in c or fortran, forget it.

StephenL

MATLAB interpreter is definitively C++, when it crashes you can see the stack dump in the command window (red). Many people think first about Java because MATLAB UI is made with it, but it is just the presentation layer, not the core.

As it is said in this document,

http://software.intel.com/en-us/articles/using-intel-math-kernel-library-and-intel-integrated-performance-primitives-in-the-microsoft-net-framework/

in the “Components – Implementation Details” section,

“Intel® MKL implements CBLAS – the C interface to the BLAS […]”

“LAPACK has only Fortran interfaces.” <– I assume it's written in Fortran then.

Other parts are written in FORTRAN 77:

http://software.intel.com/en-us/articles/using-cluster-mkl-pblasscalapack-fortran-routine-in-your-c-program/

though I don't know which parts of MKL does MATLAB use, this was just a rapid Google search. So maybe we could say the kernel of MATLAB is written mainly in Fortran, or Fortran + C.

For historical information, you can go back to the source. This Cleve’s Corner article is titled “The Origins of MATLAB” and in it Cleve discusses his original version of MATLAB (and the work that led up to it.)

http://www.mathworks.com/company/newsletters/articles/the-origins-of-matlab.html