Jump to content

MATLAB

From Alfawiki
MathWorks, Inc.
Company typePrivate
IndustrySoftware
Founded1984
FounderCleve Moler, John N. Little, Steve Bangert
Headquarters
Natick, Massachusetts
,
United States
ProductsMATLAB, Simulink
Websitemathworks.com

MATLAB (an abbreviation for Matrix Laboratory) is a proprietary multi-paradigm programming language and numerical computing platform created by MathWorks. It enables users to perform matrix operations, visualize functions and datasets, develop algorithms, design user interfaces, and interface with software written in other languages.

Although MATLAB is primarily intended for numerical computation, it offers an optional toolbox that utilizes the MuPAD symbolic engine for performing symbolic computing. The Simulink extension delivers graphical multi-domain simulation and supports model-based design tailored for applications involving dynamic and embedded system technologies.

As of , MATLAB is utilized by more than four million users worldwide in fields such as engineering, science, and economics. By 2017, over 5,000 universities and colleges globally had adopted MATLAB as part of their academic curricula and research activities.

Origins

The inception of MATLAB traces back to mathematician and programmer Cleve Moler, who developed it based on his doctoral research from the 1960s. While serving as a mathematics professor at the University of New Mexico, Moler initially created MATLAB as an educational tool for his students, emphasizing linear algebra programming beginning in 1967 alongside George Forsythe. Early iterations functioned primarily as simple matrix calculators without programming features or advanced capabilities such as ordinary differential equations (ODEs) or fast Fourier transforms (FFTs).

MATLAB was first publicly released in February 1979 at the Naval Postgraduate School located in California. These initial versions contained 71 built-in functions and were distributed at no cost to academic institutions, quickly gaining popularity within university mathematics departments.

During the 1980s, Moler collaborated with John N. Little to rewrite MATLAB in the C programming language, aiming to run it on IBM desktop computers as a replacement for mainframe systems. Together with programmer Steve Bangert, they developed the MATLAB language further and introduced toolboxes, broadening its commercial appeal.

Commercial development

The commercial launch of MATLAB took place in 1984 at the Automatic Control Conference held in Las Vegas. To support its development, MathWorks, Inc. was established, and the MATLAB programming language was officially introduced. The initial commercial transaction occurred the following year when Nick Trefethen from the Massachusetts Institute of Technology acquired ten licenses.

By the end of the 1980s, several hundred copies of MATLAB had been sold to universities for student use. Its increasing adoption was largely driven by specialized toolboxes created by domain experts to address advanced mathematical problems. Many of these toolboxes originated from students at Stanford University, helping transition MATLAB from purely academic settings into industry applications.

MATLAB was adapted for early operating systems developed by companies such as Digital Equipment Corporation, including platforms like VAX, systems from Sun Microsystems, and Unix-based personal computers. Version 3 was launched in 1987. In the 1990s, the first MATLAB compiler was created by Stephen C. Johnson.

In 2000, MathWorks incorporated a Fortran-based linear algebra library into MATLAB version 6, replacing previous C-based LINPACK and EISPACK routines. The Parallel Computing Toolbox was introduced at the 2004 Supercomputing Conference, with GPU acceleration capabilities added in 2010.

Recent developments

Version 8, released in 2012, introduced major improvements including a revamped user interface and enhanced Simulink capabilities. By 2016, MATLAB had incorporated numerous technical upgrades and user interface refinements, such as the addition of the Live Editor notebook along with other features aimed at boosting productivity.

Release timeline

For a detailed overview of modifications made to MATLAB and its official toolboxes, refer to the list of previous MATLAB releases.

MATLAB product family releases
Release name MATLAB version Simulink, Stateflow (MATLAB add-ons) Year
Volume 8 5.0 1996
Volume 9 5.1 1997
R9.1 5.1.1 1997
R10 5.2 1998
R10.1 5.2.1 1998
R11 5.3 1999
R11.1 5.3.1 1999
R12 6.0 2000
R12.1 6.1 2001
R13 6.5 2002
R13SP1 6.5.1 2003
R13SP2 6.5.2
R14 7 6.0 2004
R14SP1 7.0.1 6.1
R14SP2 7.0.4 6.2 2005
R14SP3 7.1 6.3
R2006a 7.2 6.4 2006
R2006b 7.3 6.5
R2007a 7.4 6.6 2007
R2007b 7.5 7.0
R2008a 7.6 7.1 2008
R2008b 7.7 7.2
R2009a 7.8 7.3 2009
R2009b 7.9 7.4
R2010a 7.10 7.5 2010
R2010b 7.11 7.6
R2011a 7.12 7.7 2011
R2011b 7.13 7.8
R2012a 7.14 7.9 2012
R2012b 8.0 8.0
R2013a 8.1 8.1 2013
R2013b 8.2 8.2
R2014a 8.3 8.3 2014
R2014b 8.4 8.4
R2015a 8.5 8.5 2015
R2015b 8.6 8.6
R2016a 9.0 8.7 2016
R2016b 9.1 8.8
R2017a 9.2 8.9 rowspan="2" 2017
R2017b 9.3 9.0
R2018a 9.4 9.1
   rowspan="2"    2018    
R2018b 9.5 9.2
R2019a 9.6 9.3
   rowspan="2"    2019    
R2019b 9.7 10.0
R2020a 9.8 10.1
   rowspan="2"    2020    
R2020b 9 .9 10 .2
R2021a 9 .10 10 .3
   rowspan="2"     2021     
R2021b 9 .11 10 .4
R2022a 9 .12 10 .5
   rowspan="2"     2022     
R2022b 9 .13 10 .6
    -      
R2023a 9 .14 10 .7 rowspan ="2" 2023
    -      
R2023b 23 .2 23 .2
    -      
R2024a 24 .1 24 .1 rowspan ="2" 2024
    -      
R2024b 24 .2 24 .2
    -      
R2025a 25 .1 25 .1 2025

Syntax

MATLAB is built around its exclusive programming language.

Interaction typically occurs through the Command Window, which functions as an interactive shell, or by executing scripts containing MATLAB code.

Example: "Hello, world!"

A simple demonstration:

<syntaxhighlight lang="matlab"> disp('Hello, world!') </syntaxhighlight>

Produces the output:

<syntaxhighlight lang="output"> Hello, world! </syntaxhighlight>

Variables

In MATLAB, variables are assigned using the = operator. The language features weak typing with automatic type conversion and inference, permitting variable assignments without specifying types explicitly, except when dealing with symbolic objects.

Variable values can originate from constants, calculations, or the results returned by functions.

Sample session:

<syntaxhighlight lang="matlabsession"> >> x = 17

x =

   17

>> x = 'hat'

x =

   hat

>> x = [3*4, pi/2]

x =

   12    1.5708

>> y = 3*sin(x)

y =

   -1.6097    3

</syntaxhighlight>

Vectors and Matrices

Arrays are created using the colon operator syntax: start:step:end. For example: <syntaxhighlight lang="matlabsession"> >> array = 1:2:9 array =

1 3 5 7 9

</syntaxhighlight> This produces an array beginning at 1, increasing by increments of 2, up to and including 9. Omitting the step results in a default increment of 1: <syntaxhighlight lang="matlabsession"> >> ari = 1:5 ari =

1 2 3 4 5

</syntaxhighlight>

MATLAB utilizes one-based indexing, which aligns with standard mathematical practice but differs from zero-based indexing found in languages like C++ and Java.

Matrices are constructed by separating elements with spaces or commas within square brackets [], while semicolons denote new rows. Access to individual elements or subarrays is achieved via parentheses (): <syntaxhighlight lang="matlabsession"> >> A = [16, 3, 2, 13 ; 5, 10, 11, 8 ; 9, 6, 7, 12 ; 4, 15, 14, 1] A =

16    3    2   13
5   10   11    8
9    6    7   12
4   15   14    1

>> A(2,3) ans = 11 </syntaxhighlight>

To extract submatrices, ranges such as 2:4 can be used: <syntaxhighlight lang="matlabsession"> >> A(2:4,3:4) ans = 11 8 7 12 14 1 </syntaxhighlight>

Functions like eye, zeros, and ones create identity matrices or matrices filled entirely with zeros or ones: <syntaxhighlight lang="matlabsession"> >> eye(3) ans = 1 0 0 0 1 0 0 0 1

>> zeros(2,3) ans = 0 0 0 0 0 0

>> ones(2,3) ans = 1 1 1 1 1 1 </syntaxhighlight>

The transpose operation can be performed using the transpose function or the dot-prime operator (.') to avoid conjugate transposition on complex arrays: <syntaxhighlight lang="matlabsession"> >> A = [1 ; 2], B = A.', C = transpose(A) A =

   1
   2

B =

   1    2

C =

   1    2

>> D = [0,3 ;1,5], D.' D =

   0     3
   1     5

ans =

   0     1
   3     5

</syntaxhighlight>

Most MATLAB functions apply operations element-wise on arrays. For instance, mod(2*J,n) doubles each element in J before applying modulo n. Although loops are supported in MATLAB programming, vectorized commands are generally favored for better performance. As an example (from magic.m), the following code snippet constructs a magic square matrix M for odd values of n, utilizing meshgrid to generate coordinate matrices: <syntaxhighlight lang="matlab"> [J,I] = meshgrid(1:n); A = mod(I + J - (n + 3) / 2, n); B = mod(I + 2 * J - 2, n); M = n * A + B + 1; </syntaxhighlight>

Structures

MATLAB includes support for structure data types—known as "structure arrays"—where each element contains identical field names. The language also allows dynamic field referencing and modification for enhanced flexibility in handling structure fields.

Functions

In MATLAB, the name of a function file must correspond to the name of its primary function. Function identifiers begin with a letter and may contain digits or underscores; both function and variable names are case sensitive.

Function handles

MATLAB provides function handles, which serve as references to functions defined in .m files, as well as anonymous and nested functions. These handles enable programming techniques inspired by lambda calculus, enhancing flexibility.

Classes and object-oriented programming

MATLAB incorporates object-oriented programming capabilities, including features such as classes, inheritance, virtual method dispatch, packages, and support for both pass-by-value and pass-by-reference paradigms. The language differentiates between value and reference classes depending on whether the class derives from handle (reference) or not (value). Invoking methods on reference class objects can alter the object itself, whereas methods for value classes must return a new instance to apply modifications.

Example illustrating a basic class: <syntaxhighlight lang="matlab"> classdef Hello

   methods
       function greet(obj)
           disp('Hello!')
       end
   end

end </syntaxhighlight>

Execution example: <syntaxhighlight lang="matlabsession"> >> x = Hello(); >> x.greet(); Hello! </syntaxhighlight>

Graphics and graphical user interface programming

MATLAB includes built-in graphing functions essential for visualizing data in business analytics. The plot command creates two-dimensional plots from vector data, such as rendering a sine wave: <syntaxhighlight lang="matlab"> x = 0:pi/100:2*pi; y = sin(x); plot(x,y) </syntaxhighlight>

For more complex data visualization, MATLAB supports advanced three-dimensional graphics: <syntaxhighlight lang="matlab"> [X,Y] = meshgrid(-10:0.25:10,-10:0.25:10); f = sinc(sqrt((X/pi).^2+(Y/pi).^2)); mesh(X,Y,f); axis([-10 10 -10 10 -0.3 1]) xlabel('{\bfx}') ylabel('{\bfy}') zlabel('{\bfsinc} ({\bfR})') </syntaxhighlight> This code generates a wireframe 3D plot; alternatively, the surf function produces a surface plot for richer visual detail.

MATLAB also supports creation of graphical user interface (GUI) applications, which are vital for interactive dashboards and tools. GUIs can be developed either programmatically or through visual editors like GUIDE and App Designer, facilitating streamlined application design for business professionals.

MATLAB and other languages

MATLAB is capable of invoking functions written in C or Fortran by using wrapper functions that handle MATLAB data types for input and output. These wrappers are compiled into MEX files (MATLAB Executables). Since 2014, MATLAB has increasingly supported bidirectional integration with Python.

Additionally, MATLAB can directly call libraries written in Perl, Java, ActiveX, or .NET. Many MATLAB toolboxes—such as those providing XML or SQL functionality—are implemented as wrappers around Java or ActiveX components. To call MATLAB from Java requires either a dedicated MATLAB toolbox offered by MathWorks or an unofficial Java-to-MATLAB Interface (JMI). An official Java API for MATLAB was released in 2016.

For symbolic computation alternatives to the MuPAD-based Symbolic Math Toolbox, MATLAB can interface with software like Maple or Mathematica. There are also libraries available to facilitate import and export of MathML.

Impact of US Sanctions

In 2020, MATLAB ceased providing services to two Chinese academic institutions as a result of US-imposed sanctions. In response, these universities increased their reliance on open-source tools and prioritized the creation of indigenous software solutions.

See also

Further reading


External links