Wolfram Language Fast Introduction for Math Students
Get Started »

Matrices & Linear Algebra

The Wolfram Language represents matrices as lists of lists:

In[1]:=
Click for copyable input
{{1, 2}, {3, 4}}

Enter a table using CTRL+ ENTER for rows and CTRL+ , for columns:

In[2]:=
Click for copyable input
{
 {a, b},
 {c, d}
}
Out[2]=

MatrixForm displays output as a matrix:

In[3]:=
Click for copyable input
MatrixForm[{{a, b}, {c, d}}]
Out[3]=

You can construct a matrix with iterative functions:

In[1]:=
Click for copyable input
Table[x + y, {x, 1, 3}, {y, 0, 2}]
Out[1]=

Or import data that represents a matrix:

In[2]:=
Click for copyable input
Import["data.csv"]
Out[2]=

IdentityMatrix, DiagonalMatrix and others are built-in symbols.

Standard matrix operations work elementwise:

In[1]:=
Click for copyable input
{1, 2, 3} {a, b, c}
Out[1]=

Compute the dot product of two matrices:

In[2]:=
Click for copyable input
{{1, 2}, {3, 4}}.{{a, b}, {c, d}}
Out[2]=

Find the determinant:

In[3]:=
Click for copyable input
Det[{{a, b}, {c, d}}]
Out[3]=

Get the inverse of a matrix:

In[4]:=
Click for copyable input
Inverse[{{1, 1}, {0, 1}}]
Out[4]=

Use LinearSolve to solve a linear system:

In[1]:=
Click for copyable input
LinearSolve[{{1, 1}, {0, 1}}, {x, y}]
Out[1]=

Functions for minimization and matrix decomposition are available as well.

QUICK REFERENCE: Matrices and Linear Algebra »