...

/

Inverse of a Square Matrix

Inverse of a Square Matrix

Learn about invertibility, the properties of inverse matrices, and how to create an algorithm to generate the inverse of a matrix.

Definition

The inverse of a square matrix AA is another matrix, A1A^{-1} of the same size that converts AA to identity, II, upon multiplication. Mathematically,

A1A=AA1=IA^{-1}A = AA^{-1}= I

The matrix, A1A^{-1}, has an opposite effect to that of AA. Whatever AA does, A1A^{-1} undoes.

The Python code to calculate the inverse of a square matrix is as follows:

Press + to interact
import numpy as np
mat = np.array([[1, 0, 0],
[0, 1, 0],
[0, 0, 2]])
print(mat)
inv = np.linalg.inv(mat)
print(f"""The inverse of the matrix is\n{inv}""")

Example

For example, the elimination matrix EE represents two operations, r3=r3+2r2\bold{r}_3 = \bold{r}_3 + 2\bold{r}_2 and r1=3r1\bold{r}_1 = 3\bold{r}_1:

E=[300010021]E=\begin{bmatrix} 3 & 0 & 0\\ 0 & 1 & 0\\0 & 2 & 1 \end{bmatrix}

The inverse of this matrix, E1E^{-1} , is a matrix that does the reverse operations, r3=r32r2\bold{r}_3 = \bold{r}_3 - 2\bold{r}_2 and r1=13r1\bold{r}_1 = \frac{1}{3}\bold{r}_1:

E1=[1300010021]E^{-1}=\begin{bmatrix} \frac{1}{3} & 0 & 0\\ 0 & 1 & 0\\0 & -2 & 1 \end{bmatrix}

We can verify whether we have the correct inverse by checking if the following equation is true:

EE1=[30001 ...