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.

To solve a system of linear equations like

2x1+5x2=213x2=26\begin{align} 2x_1 + 5x_2 &= 2\\ 13x_2 &= -26 \end{align}

Note that the second equation is easily solved for x2=2x_2 = -2, which can be substituted in the first equation to give x1=(25x2)/2=6x_1 = (2-5x_2)/2 = 6. If we can bring systems so that one variable is isolated, we can work backwards to solve the others! How do we do this systematically for equations?

Because of 2 and 3, we can also add a multiple of one equation to another.

For example, suppose we instead started with the equations

2x1+5x2=24x1+3x2=30\begin{align} 2x_1 + 5x_2 &= 2 \\ -4x_1 + 3x_2 &= -30 \end{align}

Adding twice the first equation to the second equation gives 13x2=2613 x_2 = -26, from which we were able solve before!

Procedure

This process can be tedious, particularly when there are more variables and equations. Matrices provide a systematic approach to both performing elementary operations to isolate variables, as well as to carry out subsequent substitution. This entire procedure is called Gauss-Jordan elimination with backsubstitution.

  1. Rewrite the equations as Ax=b\vv{A}\vv{x} = \vv{b} using a matrix and vectors

    [2543][x1x2]=[230]\begin{bmatrix}2 5 \\ -4 3\end{bmatrix} \begin{bmatrix}x_1 \\ x_2\end{bmatrix} = \begin{bmatrix}2 \\ -30\end{bmatrix}
  2. Form the “augmented” matrix [Ab][\vv{A} \vv{b}]

    A=[2524330]\mathbf{A} = \begin{bmatrix} 2 & 5 & 2\\ -4 & 3 & -30\end{bmatrix}
  3. Perform elementary operations on rows to create “pivot” points in each row. The goal is to get a number on the diagonals and zeros below. It is OK to have a zero on the diagonal if there are no nonzero values underneath it.

    [2524330]R1+2R1[25201326]\begin{bmatrix} 2 & 5 & 2 \\ -4 & 3 & -30 \end{bmatrix} \begin{matrix}\vphantom{R_1} \\ +2 R_1 \end{matrix} \to \begin{bmatrix} 2 & 5 & 2 \\ 0 & 13 & -26 \end{bmatrix}

    Here, we noted that we added twice Row 1 to Row 2 to eliminate the 4 under the first pivot point 2.

  4. When you reach the bottom row, check there are no rows of zeros with a nonzero last column. This would be equivalent to a false equation (like 0=10=1), meaning there is no solution and no further work is needed.

  5. Work back up to turn pivot points into ones and get zeros above in each column

    [25201326]R1÷13[252012]5R2R2[2012012]÷2R2[106012]\begin{align} \begin{bmatrix} 2 & 5 & 2 \\ 0 & 13 & -26 \end{bmatrix} \begin{matrix}\vphantom{R_1} \\ \div 13 \end{matrix} &\to \begin{bmatrix} 2 & 5 & 2 \\ 0 & 1 & -2 \end{bmatrix} \begin{matrix}-5 R_2 \\ \vphantom{R_2}\end{matrix} \\ &\to \begin{bmatrix} 2 & 0 & 12 \\ 0 & 1 & -2 \end{bmatrix} \begin{matrix}\div 2 \\ \vphantom{R_2}\end{matrix} \\ &\to \begin{bmatrix} 1 & 0 & 6 \\ 0 & 1 & -2 \end{bmatrix} \end{align}
  6. The solution comes from reexpressing the augmented matrix as Ax=b\vv{A} \vv{x} = \vv{b}.

    [1001][x1x2]=[62]\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} = \begin{bmatrix} 6 \\ -2 \end{bmatrix}

    Or, x1=6x_1 = 6 and x2=2x_2 = -2.

Example: Pump circuit

Incompressible flow can be written analogous to an electrical circuit as

ΔP=RQ-\Delta P = RQ

where ΔP\Delta P is the pressure change, R is the resistance, and Q is the volumetric flow rate. For the following pump “circuit”:

Fluid System Modeled as Circuit

The pressure and mass balances for the nodes and loop give:

Q1+Q3=Q2Q2=Q1+Q380=10Q2+20Q190=25Q3+10Q2\begin{align} Q_1 &+ Q_3 = Q_2 \\ Q_2 &= Q_1 + Q_3 \\ 80 &= 10Q_2 + 20Q_1 \\ 90 &= 25Q_3 + 10Q_2 \end{align}

Find Q1Q_1, Q2Q_2, and Q3Q_3.


First, rearrange the equations into consistent linear form:

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}

Then, rewrite using matrix representation:

[1111112010001025][Q1Q2Q3]=[008090]\begin{bmatrix} 1 & -1 & 1 \\ 1 & -1 & 1 \\ 20 & 10 & 0 \\ 0 & 10 & 25 \end{bmatrix} \begin{bmatrix} Q_1 \\ Q_2 \\ Q_3 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 80 \\ 90 \end{bmatrix}

Now, perform Gauss-Jordan elimination steps to solve for the unknown flow rates. We form the augmented matrix, then use Row 1 to eliminate values in Rows 2 and 3:

[1110111020100800102590]R1+R120R1R1[1110000003020800102590]\begin{bmatrix} 1 & -1 & 1 & 0 \\ -1 & 1 & -1 & 0 \\ 20 & 10 & 0 & 80 \\ 0 & 10 & 25 & 90 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ + R_1 \\ -20 R_1 \\ \vphantom{R_1} \end{matrix} \to \begin{bmatrix} 1 & -1 & 1 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 30 & -20 & 80 \\ 0 & 10 & 25 & 90 \end{bmatrix}

Row 2 is all zeros because it was a redundant equation to Row 1. Swap Rows 2 and 4, then use the new Row 2 to eliminate value in Row 3:

[1110010259003020800000]R1R13R2R1[1110010259000951900000]\begin{bmatrix} 1 & -1 & 1 & 0 \\ 0 & 10 & 25 & 90 \\ 0 & 30 & -20 & 80 \\ 0 & 0 & 0 & 0 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \vphantom{R_1} \\ -3 R_2 \\ \vphantom{R_1} \end{matrix} \to \begin{bmatrix} 1 & -1 & 1 & 0 \\ 0 & 10 & 25 & 90 \\ 0 & 0 & -95 & -190 \\ 0 & 0 & 0 & 0 \end{bmatrix}

Normalize Row 3 (divide by -95), then eliminate values above in Column 3:

[1110010259000120000]R325R3R1R1[110201004000120000]\begin{bmatrix} 1 & -1 & 1 & 0 \\ 0 & 10 & 25 & 90 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 0 & 0 \end{bmatrix} \begin{matrix} - R_3 \\ -25 R_3 \\ \vphantom{R_1} \\ \vphantom{R_1} \end{matrix} \to \begin{bmatrix} 1 & -1 & 0 & -2 \\ 0 & 10 & 0 & 40 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 0 & 0 \end{bmatrix}

Normalize Row 2 (divide by 10), then eliminate values above in Column 2:

[1102010400120000]+R2R1R1R1[1002010400120000]\begin{bmatrix} 1 & -1 & 0 & -2 \\ 0 & 1 & 0 & 4 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 0 & 0 \end{bmatrix} \begin{matrix} + R_2 \\ \vphantom{R_1} \\ \vphantom{R_1} \\ \vphantom{R_1} \end{matrix} \to \begin{bmatrix} 1 & 0 & 0 & 2 \\ 0 & 1 & 0 & 4 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 0 & 0 \end{bmatrix}

Turning back into an equivalent system of equations gives the final solution, Q1=2Q_1 = 2, Q2=4Q_2 = 4, and Q3=2Q_3 = 2.

Number of solutions

The number of solutions for the system of linear equations can be determined from the row-reduced augmented matrix.

Skill builder problems

Solution to Exercise 1

Form the augmented matrix and perform row reduction:

[5220.91419.3]swapR2[1419.35220.9]×1R2[1419.35220.9]R15R1[1419.301875.6]R1÷18[1419.3014.2]+4R2R2[102.5014.2]\begin{align} \begin{bmatrix} 5 & -2 & 20.9 \\ -1 & 4 & -19.3 \end{bmatrix} \begin{matrix} {\rm swap} \\ \vphantom{R_2}\end{matrix} &\to \begin{bmatrix} -1 & 4 & -19.3 \\ 5 & -2 & 20.9\end{bmatrix} \begin{matrix} \times -1 \\ \vphantom{R_2}\end{matrix} \\ &\to \begin{bmatrix} 1 & -4 & 19.3 \\ 5 & -2 & 20.9\end{bmatrix} \begin{matrix} \vphantom{R_1} \\ -5 R_1 \end{matrix} \\ &\to \begin{bmatrix} 1 & -4 & 19.3 \\ 0 & 18 & -75.6\end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \div 18 \end{matrix} \\ &\to \begin{bmatrix} 1 & -4 & 19.3 \\ 0 & 1 & -4.2\end{bmatrix} \begin{matrix} +4 R_2 \\ \vphantom{R_2} \end{matrix} \\ &\to \begin{bmatrix} 1 & 0 & 2.5 \\ 0 & 1 & -4.2\end{bmatrix} \end{align}

so x1=2.5x_1 = 2.5 and x2=4.2x_2 = -4.2.

Solution to Exercise 2
[1482817]R12R1[148001]\begin{align} \begin{bmatrix} 1 & 4 & 8 \\ 2 & 8 & 17 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ -2 R_1\end{matrix} &\to \begin{bmatrix} 1 & 4 & 8 \\ 0 & 0 & 1\end{bmatrix} \end{align}

The equations do not have a solution because the last row is false.

Solution to Exercise 3
[0112046121112]R1shuffleR3[1112011204612]R1R2 4R2[111201120024]R1R2÷2[111201120012]R3R3R3[110401000012]R2R2R3[100401000012]\begin{align} \begin{bmatrix} 0 & 1 & 1 & -2 \\ 0 & 4 & 6 & -12 \\ 1 & 1 & 1 & 2 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \rm shuffle \\ \vphantom{R_3} \end{matrix} &\to \begin{bmatrix} 1 & 1 & 1 & 2 \\ 0 & 1 & 1 & -2 \\ 0 & 4 & 6 & -12 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \vphantom{R_2} \\ \ -4 R_2 \end{matrix} \\ &\to \begin{bmatrix} 1 & 1 & 1 & 2 \\ 0 & 1 & 1 & -2 \\ 0 & 0 & 2 & -4 \end{bmatrix} \begin{matrix} \vphantom{R_1} \\ \vphantom{R_2} \\ \div 2 \end{matrix} \\ &\to \begin{bmatrix} 1 & 1 & 1 & 2 \\ 0 & 1 & 1 & -2 \\ 0 & 0 & 1 & -2 \end{bmatrix} \begin{matrix} -R_3 \\ -R_3 \\ \vphantom{R_3} \end{matrix} \\ &\to \begin{bmatrix} 1 & 1 & 0 & 4 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & -2 \end{bmatrix} \begin{matrix} -R_2 \\ \vphantom{R_2} \\ \vphantom{R_3} \end{matrix} \\ &\to \begin{bmatrix} 1 & 0 & 0 & 4 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & -2 \end{bmatrix} \end{align}

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

Solution to Exercise 4
[0442431126617118]swapR2R2R3[3112604424617118]R1R22R1[311260442405530]R1÷4÷5[3112601160116]R1R2R2[3112601160000]+11R2R2R3[3096001160000]÷3R2R3[1032001160000]\begin{align} \begin{bmatrix} 0 & 4 & 4 & 24 \\ 3 & -11 & -2 & -6 \\ 6 & - 17 & 1 & 18 \end{bmatrix} \begin{matrix}{\rm swap}\,R_2 \\ \vphantom{R_2} \\ \vphantom{R_3}\end{matrix} &\to \begin{bmatrix} 3 & -11 & -2 & -6 \\ 0 & -4 & 4 & 24 \\ 6 & - 17 & 1 & 18 \end{bmatrix} \begin{matrix}\vphantom{R_1} \\ \vphantom{R_2} \\ -2 R_1\end{matrix}\\ &\to \begin{bmatrix} 3 & -11 & -2 & -6 \\ 0 & 4 & 4 & 24 \\ 0 & 5 & 5 & 30 \end{bmatrix} \begin{matrix}\vphantom{R_1} \\ \div 4 \\ \div 5\end{matrix}\\ &\to \begin{bmatrix} 3 & -11 & -2 & -6 \\ 0 & 1 & 1 & 6 \\ 0 & 1 & 1 & 6 \end{bmatrix} \begin{matrix}\vphantom{R_1} \\ \vphantom{R_2} \\ -R_2\end{matrix}\\ &\to \begin{bmatrix} 3 & -11 & -2 & -6 \\ 0 & 1 & 1 & 6 \\ 0 & 0 & 0 & 0 \end{bmatrix} \begin{matrix}+11 R_2 \\ \vphantom{R_2} \\ \vphantom{R_3}\end{matrix}\\ &\to \begin{bmatrix} 3 & 0 & 9 & 60 \\ 0 & 1 & 1 & 6 \\ 0 & 0 & 0 & 0 \end{bmatrix} \begin{matrix}\div 3 \\ \vphantom{R_2} \\ \vphantom{R_3}\end{matrix}\\ &\to \begin{bmatrix} 1 & 0 & 3 & 20 \\ 0 & 1 & 1 & 6 \\ 0 & 0 & 0 & 0 \end{bmatrix} \end{align}

Hence,

x13x3=20x1=3x3+20x2+x3=6x2=x3+6\begin{align} x_1 - 3x_3 &= 20 \to & x_1 &= 3 x_3 + 20 \\ x_2 + x_3 &= 6 \to & x_2 &= x_3 + 6 \end{align}

with x3x_3 free.

Solution to Exercise 5
[21314262]R1+2R1[21310000]\begin{align} \begin{bmatrix} 2 & -1 & 3 & -1 \\ -4 & 2 & -6 & -2 \end{bmatrix} \begin{matrix}\vphantom{R_1} \\ +2R_1\end{matrix} \to \begin{bmatrix} 2 & -1 & 3 & -1 \\ 0 & 0& 0 & 0 \end{bmatrix} \end{align}

Hence,

2x1x2+3x3=1x1=12(x2+x31)2x_1 - x_2 + 3x_3 = -1 \to \quad x_1 = \frac{1}{2}(x_2 + x_3 - 1)

with x2x_2 and x3x_3 free.