Documentation
Mathematica
Built-in Functions
Advanced Documentation
Linear Algebra
Matrix and Tensor Operations

Building Matrices
Matrices are represented in Mathematica with lists. They can be entered directly with the { } notation that Mathematica provides for lists. An example of a matrix is shown below; by default a matrix prints with the list notation.
In[1]:=
Out[1]=
Mathematica provides a number of ways to build matrices.

The function Table is particularly important to generate matrices. The Mathematica documentation contains more information on . In this example a 3
3 matrix is built.
In[2]:=
Out[2]=
MatrixForm prints the matrix in a two-dimensional form.
In[3]:=
Out[3]//MatrixForm=
Another way to build matrices in Mathematica is with the Array command. Here it is used to build a 3
3 matrix.
In[4]:=
Out[4]=
Mathematica has a number of functions for building certain specialized matrices. This builds the identity matrix.
In[5]:=
Out[5]=
Note that the identity matrix that is generated is an integer matrix. If you want to compute with floating point numbers it can be advantageous to use matrices that contain floating point entries; this is described in more detail in the section Performance: Matrix Contents. If you start with an integer matrix, such as the identity matrix generated previously, it can be converted to a floating point matrix by using the function N. This is shown in the following.
In[6]:=
Out[6]=
Here a diagonal matrix is constructed.
In[7]:=
Out[7]=
This makes a 3
4 matrix with two nonzero values filled in. SparseArray expressions are described in a later section.
In[8]:=
Out[8]=

Constructing special types of matrices with Table.
Table evaluates Random[ ] separately for each element, to give a different pseudorandom number in each case.
In[9]:=
Out[9]=

Constructing special types of matrices with SparseArray.
This sets up a general lower triangular matrix.
In[10]:=
Out[10]//MatrixForm=
Functions that can read in matrices from files are discussed in the section Import and Export.
Special Matrices
The standard package LinearAlgebra`MatrixManipulation` contains definitions for a number of special matrices.

Special matrices.
You need to load the package to use its functions.
In[1]:=
Here is a 2
4 Hilbert matrix.
In[2]:=
Out[2]//MatrixForm=
The elements of the Hankel matrix can be given as a list.
In[3]:=
Out[3]//MatrixForm=
The Hankel matrix can be filled with nonzero values by giving the final row. This also allows a non-square matrix to be generated. Note that the last element of the first column and the first element of the final row must be identical.
In[4]:=
Out[4]//MatrixForm=