Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Motivation and definition

Gauss-Jordan elimination works well for solving Ax = b, but the process needs to be repeated for every new b. Is there an alternative if we need to solve Ax = b for many different b?

A matrix is called nonsingular or invertible if it has an inverse, but singular if it does not.

If the inverse of A exists, it is unique and can be used to solve Ax = b.

Ax=bA1Ax=A1bx=A1b\begin{align} \vv{A} \vv{x} &= \vv{b} \\ \vv{A}^{-1} \vv{A} \vv{x} &= \vv{A}^{-1} \vv{b} \\ \vv{x} &= \vv{A}^{-1} \vv{b} \end{align}

Finding the inverse of A is usually hard. There is a general definition based on cofactors, as well as advanced numerical methods, that we will not cover. Instead, we focus on two options: a formula for 2 x 2 matrices, and use of Gauss-Jordan elimination for larger matrices.

Inverse of a 2 x 2 matrix

For a 2 x 2 matrix,

A=[abcd],\vv{A} = \begin{bmatrix} a & b \\ c & d \end{bmatrix},

the matrix inverse is

A1=1A[dbca]\vv{A}^{-1} = \frac{1}{|\vv{A}|} \begin{bmatrix} d & -b \\ -c & a \end{bmatrix}

(Flip a and d, change the signs of b and c.)

For example, to find the inverse of

A=[3124]\vv{A} = \begin{bmatrix} 3 & 1 \\ 2 & 4 \end{bmatrix}

First, compute its determinant:

A=3×42×1=122=10|\vv{A}| = 3 \times 4 - 2 \times 1 = 12 - 2 = 10

Then, compute its inverse

A1=110[4123]=[0.40.10.20.3]\vv{A}^{-1} = \frac{1}{10} \begin{bmatrix} 4 & -1 \\ -2 & 3 \end{bmatrix} = \begin{bmatrix} 0.4 & -0.1 \\ -0.2 & 0.3 \end{bmatrix}

Inverses using Gauss-Jordan elimination

For larger matrices, we can use Gauss–Jordan elimination to solve AA1=I\vv{A} \vv{A}^{-1} = \vv{I} as a generalization of Ax = b.

Example: Pump circuit

We will resolve the problem we used Gauss-Jordan elimination for, but now using the matrix inverse. As a reminder, the equations to solve were

Q1Q2+Q3=0Q1Q2+Q3=020Q1+10Q2+0Q3=800Q1+10Q2+25Q3=90\begin{align} Q_1 - Q_2 + Q_3 &= 0 \\ Q_1 - Q_2 + Q_3 &= 0 \\ 20Q_1 + 10Q_2 + 0Q_3 &= 80 \\ 0Q_1 + 10Q_2 + 25Q_3 &= 90 \end{align}

We need a square matrix to calculate the inverse, and we know the second equation is redundant of the first. We write this in matrix form Ax = b with

A=[1112010001025]b=[08090]\vv{A} = \begin{bmatrix} 1 & -1 & 1 \\ 20 & 10 & 0 \\ 0 & 10 & 25\end{bmatrix} \qquad \vv{b} = \begin{bmatrix} 0 \\ 80 \\ 90 \end{bmatrix}

First, compute the determinant to make sure A is invertible

A=1011200+25112010=10(020)+25(10+20)=950\begin{align} |\vv{A}| &= -10 \begin{vmatrix} 1 & 1 \\ 20 & 0 \end{vmatrix} + 25 \begin{vmatrix} 1 & -1 \\ 20 & 10\end{vmatrix} \\ &= 10 (0-20) + 25 (10+20) = 950 \end{align}

The determinant is nonzero, so A1\vv{A}^{-1} exists. Form the augmented matrix we need to compute, then use a similar sequence of row operations as when we used Gauss-Jordan elimination to solve directly:

[1111002010001001025001]R120R1R1[11110003020201001025001]R1swapR3R1[11110001025001030202010]R1R13R2[1111000102500100952013]R1÷10÷95[111100012.5000.1001.211.0100.032]R32.5R3R3[1100.7890.0100.0320100.5280.0250.0200010.2110.0100.032]+R2R2R3[1000.2610.0350.0120100.5280.0250.0200010.2110.0100.032]\begin{align} &\begin{bmatrix} 1 & -1 & 1 & 1 & 0 & 0 \\ 20 & 10 & 0 & 0 & 1 & 0 \\ 0 & 10 & 25 & 0 & 0 & 1 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ -20 R_1 \\ \vphantom{R_1} \end{matrix} \\ \to &\begin{bmatrix} 1 & -1 & 1 & 1 & 0 & 0 \\ 0 & 30 & -20 & -20 & 1 & 0 \\ 0 & 10 & 25 & 0 & 0 & 1 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ {\rm swap}\,R_3 \\ \vphantom{R_1} \end{matrix} \\ \to &\begin{bmatrix} 1 & -1 & 1 & 1 & 0 & 0 \\ 0 & 10 & 25 & 0 & 0 & 1 \\ 0 & 30 & -20 & -20 & 1 & 0 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \vphantom{R_1} \\ -3 R_2 \end{matrix} \\ \to &\begin{bmatrix} 1 & -1 & 1 & 1 & 0 & 0 \\ 0 & 10 & 25 & 0 & 0 & 1 \\ 0 & 0 & -95 & -20 & 1 & -3 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \div 10 \\ \div -95 \end{matrix} \\ \to &\begin{bmatrix} 1 & -1 & 1 & 1 & 0 & 0 \\ 0 & 1 & 2.5 & 0 & 0 & 0.1 \\ 0 & 0 & 1 & .211 & -.010 & 0.032 \end{bmatrix} \begin{matrix} -R_3 \\ -2.5 R_3 \\ \vphantom{R_3} \end{matrix} \\ \to &\begin{bmatrix} 1 & -1 & 0 & 0.789 & 0.010 & -0.032 \\ 0 & 1 & 0 & -0.528 & 0.025 & 0.020 \\ 0 & 0 & 1 & 0.211 & -0.010 & 0.032 \end{bmatrix} \begin{matrix} +R_2 \\ \vphantom{R_2} \\ \vphantom{R_3} \end{matrix} \\ \to &\begin{bmatrix} 1 & 0 & 0 & 0.261 & 0.035 & -0.012 \\ 0 & 1 & 0 & -0.528 & 0.025 & 0.020 \\ 0 & 0 & 1 & 0.211 & -0.010 & 0.032 \end{bmatrix} \end{align}

Solve:

Q=A1b=[0.2610.0350.0120.5280.0250.0200.2110.0100.032][08090]=[1.723.802.08]\vv{Q} = \vv{A}^{-1}{b} = \begin{bmatrix} 0.261 & 0.035 & -0.012 \\ -0.528 & 0.025 & 0.020 \\ 0.211 & -0.010 & 0.032 \end{bmatrix} \begin{bmatrix} 0 \\ 80 \\ 90 \end{bmatrix} = \begin{bmatrix} 1.72 \\ 3.80 \\ 2.08 \end{bmatrix}

This is close to the solution we found before, with some errors due to rounding.

Skill builder problems

Solution to Exercise 1

First, write in matrix form Ax = b with:

A=[5214]b=[20.919.3]\vv{A} = \begin{bmatrix} 5 & -2 \\ -1 & 4 \end{bmatrix} \qquad \vv{b} = \begin{bmatrix} 20.9 \\ -19.3 \end{bmatrix}

Then, evaluate A|\vv{A}| to check if an inverse exists:

A=(54)(12)=18|\vv{A}| = (5 \cdot 4) - (-1 \cdot -2) = 18

A0|\vv{A}| \ne 0, so an inverse can be found using the formula for a 2x2 matrix:

A1=118[5214]\vv{A}^{-1} = \frac{1}{18} \begin{bmatrix} 5 & -2 \\ -1 & 4 \end{bmatrix}

Last, solve for x:

x=A1b=118[5214][20.919.3]=118[420.9+219.3120.9+519.3]=[2.54.2]\begin{align} \vv{x} = \vv{A}^{-1}\vv{b} &= \frac{1}{18} \begin{bmatrix} 5 & -2 \\ -1 & 4 \end{bmatrix} \begin{bmatrix} 20.9 \\ -19.3 \end{bmatrix} \\ &= \frac{1}{18} \begin{bmatrix} 4 \cdot 20.9 + 2 \cdot -19.3 \\ 1 \cdot 20.9 + 5 \cdot -19.3 \end{bmatrix} \\ &= \begin{bmatrix} 2.5 \\ -4.2 \end{bmatrix} \end{align}

Therefore, x1=2.5x_1 = 2.5 and x2=4.2x_2 = -4.2.

Solution to Exercise 2

First, write in matrix form Ax = b with:

A=[1428]b=[817]\vv{A} = \begin{bmatrix} 1 & 4 \\ 2 & 8 \end{bmatrix} \qquad \vv{b} = \begin{bmatrix} 8 \\ 17 \end{bmatrix}

Then, evalaute A|\vv{A}| to check if an inverse exists:

A=(18)(24)=0|\vv{A}| = (1 \cdot 8) - (2 \cdot 4) = 0

A is singular because A=0|\vv{A}| = 0, so these equations cannot be solved using an inverse.

Solution to Exercise 3

First, write in matrix form Ax = b with:

A=[011046111]b=[2122]\vv{A} = \begin{bmatrix} 0 & 1 & 1 \\ 0 & 4 & 6 \\ 1 & 1 & 1 \end{bmatrix} \qquad \vv{b} = \begin{bmatrix} -2 \\ -12 \\ 2 \end{bmatrix}

Then, evaluate A|\vv{A}| to check if an inverse exists:

A=0461110611+10411\begin{align} |\vv{A}| = 0 \cdot \begin{vmatrix} 4 & 6 \\ 1 & 1 \end{vmatrix} -1 \cdot \begin{vmatrix} 0 & 6 \\ 1 & 1 \end{vmatrix} + 1 \cdot \begin{vmatrix} 0 & 4 \\ 1 & 1 \end{vmatrix} \end{align}
A=1(06)+1(04)=2|\vv{A}| = -1 \cdot (0-6) + 1 \cdot (0-4) = 2

Since A0|\vv{A}| \ne 0, A is invertible. Use Gauss-Jordan elimination to find the inverse. Start with the augmented matrix [AI][\vv{A} | \vv{I}], then rearrange the rows

[011100046010111001][111001011100046010]R1R14R1[111001011100002410]R1R1÷2[11100101110000120.50]R3R3R1[11020.5101030.5000120.50]R2R1R1[10010101030.5000120.50]\begin{align} \begin{bmatrix} 0 & 1 & 1 & 1 & 0 & 0 \\ 0 & 4 & 6 & 0 & 1 & 0 \\ 1 & 1 & 1 & 0 & 0 & 1 \end{bmatrix} &\to \begin{bmatrix} 1 & 1 & 1 & 0 & 0 & 1 \\ 0 & 1 & 1 & 1 & 0 & 0 \\ 0 & 4 & 6 & 0 & 1 & 0 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \vphantom{R_1} \\ -4 R_1 \end{matrix} \\ &\to \begin{bmatrix} 1 & 1 & 1 & 0 & 0 & 1 \\ 0 & 1 & 1 & 1 & 0 & 0 \\ 0 & 0 & 2 & -4 & 1 & 0 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \vphantom{R_1} \\ \div 2 \end{matrix} \\ &\to \begin{bmatrix} 1 & 1 & 1 & 0 & 0 & 1 \\ 0 & 1 & 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & -2 & 0.5 & 0 \end{bmatrix} \begin{matrix} -R_3 \\ -R_3 \\ \vphantom{R_1} \end{matrix} \\ &\to \begin{bmatrix} 1 & 1 & 0 & 2 & -0.5 & 1 \\ 0 & 1 & 0 & 3 & -0.5 & 0 \\ 0 & 0 & 1 & -2 & 0.5 & 0 \end{bmatrix} \begin{matrix} -R_2 \\ \vphantom{R_1} \\ \vphantom{R_1} \end{matrix} \\ &\to \begin{bmatrix} 1 & 0 & 0 & -1 & 0 & 1 \\ 0 & 1 & 0 & 3 & -0.5 & 0 \\ 0 & 0 & 1 & -2 & 0.5 & 0 \end{bmatrix} \end{align}

Hence,

A1=[10130.5020.50]\begin{align} \vv{A}^{-1} = \begin{bmatrix} -1 & 0 & 1 \\ 3 & -0.5 & 0 \\ -2 & 0.5 & 0 \end{bmatrix} \end{align}

and

x=A1b=[10130.5020.50][2122]=[12+1232+0.51222+0.512]=[402]\begin{align} \vv{x} = \vv{A}^{-1} \vv{b} &= \begin{bmatrix} -1 & 0 & 1 \\ 3 & -0.5 & 0 \\ -2 & 0.5 & 0 \end{bmatrix} \begin{bmatrix} -2 \\ -12 \\ 2 \end{bmatrix} \\ & = \begin{bmatrix} -1 \cdot -2 + 1 \cdot 2 \\ 3 \cdot -2 + -0.5 \cdot -12 \\ -2 \cdot -2 + 0.5 \cdot -12 \end{bmatrix} \\ &= \begin{bmatrix} 4 \\ 0 \\ -2 \end{bmatrix} \end{align}

So, x1=4x_1 = 4, x2=0x_2 = 0, and x3=2x_3 = -2.

Solution to Exercise 4

First, write in matrix form Ax = b with:

A=[04431126171]b=[24618]\vv{A} = \begin{bmatrix} 0 & 4 & 4 \\ 3 & -11 & -2 \\ 6 & -17 & 1 \end{bmatrix} \qquad \vv{b} = \begin{bmatrix} 24 \\ -6 \\ 18 \end{bmatrix}

Then, evaluate A|\vv{A}| to check if an inverse exists:

A=011217143261+4311617\begin{align} |\vv{A}| = 0 \cdot \begin{vmatrix} -11 & -2 \\ -17 & 1 \end{vmatrix} -4 \cdot \begin{vmatrix} 3 & -2 \\ 6 & 1 \end{vmatrix} + 4 \cdot \begin{vmatrix} 3 & -11 \\ 6 & -17 \end{vmatrix} \end{align}
A=4(3162)+4(317611)=415+415=0\begin{align} |\vv{A}| &= -4 (3 \cdot 1 - 6 \cdot -2) + 4 (3 \cdot -17 - 6 \cdot -11) \\ &= -4 \cdot 15 + 4 \cdot 15 \\ &= 0 \end{align}

Since A=0|\vv{A}| = 0, A is not invertible.

Solution to Exercise 5

First, write in matrix form Ax = b with:

A=[213426]b=[12]\vv{A} = \begin{bmatrix} 2 & -1 & 3 \\ -4 & 2 & -6 \end{bmatrix} \qquad \vv{b} = \begin{bmatrix} -1 \\ 2 \end{bmatrix}

Since A is not square, A is not invertible.