Matrix Inversion

Inverse[m]find the inverse of a square matrix

Matrix inversion.

Here is a simple 2×2 matrix.
In[1]:=
Click for copyable input
Out[1]=
This gives the inverse of . In producing this formula, Mathematica implicitly assumes that the determinant is nonzero.
In[2]:=
Click for copyable input
Out[2]=
Multiplying the inverse by the original matrix should give the identity matrix.
In[3]:=
Click for copyable input
Out[3]=
You have to use Together to clear the denominators, and get back a standard identity matrix.
In[4]:=
Click for copyable input
Out[4]=
Here is a matrix of rational numbers.
In[5]:=
Click for copyable input
Out[5]=
Mathematica finds the exact inverse of the matrix.
In[6]:=
Click for copyable input
Out[6]=
Multiplying by the original matrix gives the identity matrix.
In[7]:=
Click for copyable input
Out[7]=
If you try to invert a singular matrix, Mathematica prints a warning message, and returns the input unchanged.
In[8]:=
Click for copyable input
Out[8]=

If you give a matrix with exact symbolic or numerical entries, Mathematica gives the exact inverse. If, on the other hand, some of the entries in your matrix are approximate real numbers, then Mathematica finds an approximate numerical result.

Here is a matrix containing approximate real numbers.
In[9]:=
Click for copyable input
Out[9]=
This finds the numerical inverse.
In[10]:=
Click for copyable input
Out[10]=
Multiplying by the original matrix gives you an identity matrix with small round-off errors.
In[11]:=
Click for copyable input
Out[11]=
You can get rid of small off-diagonal terms using Chop.
In[12]:=
Click for copyable input
Out[12]=

When you try to invert a matrix with exact numerical entries, Mathematica can always tell whether or not the matrix is singular. When you invert an approximate numerical matrix, Mathematica can usually not tell for certain whether or not the matrix is singular: all it can tell is, for example, that the determinant is small compared to the entries of the matrix. When Mathematica suspects that you are trying to invert a singular numerical matrix, it prints a warning.

Mathematica prints a warning if you invert a numerical matrix that it suspects is singular.
In[13]:=
Click for copyable input
Out[13]=
This matrix is singular, but the warning is different, and the result is useless.
In[14]:=
Click for copyable input
Out[14]=

If you work with high-precision approximate numbers, Mathematica will keep track of the precision of matrix inverses that you generate.

This generates a 6×6 numerical matrix with entries of 20-digit precision.
In[15]:=
Click for copyable input
This takes the matrix, multiplies it by its inverse, and shows the first row of the result.
In[16]:=
Click for copyable input
Out[16]=
This generates a 20-digit numerical approximation to a 6×6 Hilbert matrix. Hilbert matrices are notoriously hard to invert numerically.
In[17]:=
Click for copyable input
The result is still correct, but the zeros now have lower accuracy.
In[18]:=
Click for copyable input
Out[18]=

Inverse works only on square matrices. "Advanced Matrix Operations" discusses the function PseudoInverse, which can also be used with nonsquare matrices.

New to Mathematica? Find your learning path »
Have a question? Ask support »