Skip to article frontmatterSkip to article content

1.2 Solving Linear Systems via Gaussian Elimination

Forward elimination and back substitution are all you need

Dept. of Electrical and Systems Engineering
University of Pennsylvania

Binder

Lecture notes

1ReadingΒΆ

Material related to this page, as well as additional exercises, can be found in ALA Ch. 1.1, LAA Ch 1.1, and ILA Ch. 2.2. These notes are mostly based on ALA Ch 1.1.

2Learning ObjectivesΒΆ

By the end of this page, you should know:

  • what a linear equation is, how to identify one, and how they combine to form a system of linear equations (also called a linear system)
  • what a solution set is, and the kinds of solution sets a linear system can have
  • how to solve most small systems of linear equations by hand using Gaussian Elimination

3TerminologyΒΆ

A linear equation[1] in the variables x1,…,xnx_1,\dots,x_n is an equation that can be written in the form

a1x1+a2x2+β‹―+anxn=b,a_1x_1 + a_2x_2+\cdots+a_nx_n = b,

where bb and the coefficients a1,a2,…,ana_1,a_2,\dots,a_n are real or complex numbers[2] that are typically known in advance. The subscript nn is a positive integer, and encodes how many variables appear in the linear equation. When we ask you to solve problems by hand, nn is typically 2 or 3, but we will see and solve problems where nn is in the hundreds or even thousands!

A system of linear equations (or linear system) is a collection of one or more linear equations involving the same variables, say x1,…,xnx_1,\dots,x_n. An example is

x1+2x2+x3=2,2x1+6x2+x3=7,x1+x2+4x3=3,\begin{align*} x_1+2x_2+x_3 & = 2,\\ 2x_1+6x_2+x_3 & =7,\\ x_1+x_2+4x_3 & =3, \end{align*}

which is a system of three equations in three unknowns.

A solution of the system is a list (s1,s2,…,sn)(s_1,s_2,\dots,s_n) of numbers that makes each equation a true statement when the values s1,…,sns_1,\dots,s_n are substituted for x1,…,xnx_1,\dots,x_n, respectively. For instance, (βˆ’3,2,1)(-3,2,1) is a solution of system (2) because, when these values are substituted in (2) for x1,x2,x3x_1,x_2,x_3, respectively, the equations simplify to 2=22=2, 7=77=7, and 3=33=3. The set of all possible solutions is called the solution set of the linear system. We state an important fact regarding the solution set of linear systems that we will understand very deeply by the end of this chapter:

4Solving Linear SystemsΒΆ

We start with a simple observation: we know how to solve equations that look like

52x1=6,Β 5βˆ’x3=12,Β 1+3x2=βˆ’4. \frac{5}{2}x_1 = 6, \ 5-x_3 = 12, \ 1 + 3x_2 = -4.

These equations are ``easy’’ to solve because they only involved one unknown, that we can solve for using simple algebra. Our strategy will be to develop a systematic way of reducing linear systems, like the example (2) above, into an equivalent system of equations that are easy to solve.

To illustrate, let’s start with the system of three linear equations (2) we introduced above:

x1+2x2+x3=2,2x1+6x2+x3=7,x1+x2+4x3=3,\begin{align*} x_1+2x_2+x_3 & = 2,\\ 2x_1+6x_2+x_3 & =7,\\ x_1+x_2+4x_3 & =3, \end{align*}

Our strategy will be to systematically employ the following very useful observation:

Before continuing, you might try to convince yourself that this observation is true. Our goal is to apply ObservationΒ 1 judiciously to transform the system of linear equations (4) into a much simpler one that is easy to solve but still has the same solutions as the original. Any linear system that is derived from the original system by successive application of such operations will be called an equivalent system. An important property is that equivalent systems have the same solutions.

Our strategy will be to successively eliminate variables in our equations in order of appearance. So, here, our first step is to eliminate the first variable, x1x_1, from the second equation. We’ll do that by subtracting twice the first equation from the second:

[secondΒ equation]2x1+6x2+x3=7-2[firstΒ equation]βˆ’2[x1+2x2+x3=2][updatedΒ equation]0x1+2x2βˆ’x3=3, \begin{array}{lrl} \text{[second equation]} & 2x_1+6x_2+x_3 & =7 \\ \text{-2[first equation]} & -2\left[x_1+2x_2+x_3 \right. & \left. = 2\right]\\ \hline \\ \text{[updated equation]} & 0x_1 + 2x_2 - x_3 & = 3, \end{array}

so that now, our equivalent system of linear equations is given by

x1+2x2+x3=2,2x2βˆ’x3=3,x1+x2+4x3=3.\begin{align*} x_1+2x_2+x_3 & = 2,\\ 2x_2-x_3 & =3,\\ x_1+x_2+4x_3 & =3. \end{align*}

This system of equations is simpler than (4) because x1x_1 no longer appears in the second equation. We can eliminate x1x_1 from the third equation by subtracting the first equation from it, giving

x1+2x2+x3=2,2x2βˆ’x3=3,βˆ’x2+3x3=1.\begin{align*} x_1+2x_2+x_3 & = 2,\\ 2x_2-x_3 & =3,\\ -x_2+3x_3 & =1. \end{align*}

The equivalent system (7) is even simpler than the original (4): notice that the second and third equations do not involve x1x_1 (by design), and so constitute a system of two linear equations in two unknowns. Moreover, once we have solved this subsystem for x2x_2 and x3x_3, we can substitute the answer into the first equation, and we need only solve a single linear equation for x1x_1.

We continue on, with our goal in this next phase to eliminate the second variable, x2x_2, from the third equation by adding 1/21/2 the second equation to it. The result is

x1+2x2+x3=2,2x2βˆ’x3=3,52x3=52,\begin{align*} x_1+2x_2+x_3 & = 2,\\ 2x_2-x_3 & =3,\\ \frac{5}{2}x_3 & =\frac{5}{2}, \end{align*}

which is the simple system we have been working towards. It is in what is called triangular form: the first equation depends on all three variables, the second only depends on the second and third variables, and the last equation involves only the last variable. The process we went through of transforming the original system (4) to the triangular system (8) is an example of Forward Elimination: we work our way down the equations, eliminating variables as we go. Once a system is in triangular form, it can be straightforwardly solved by the method of Back Substitution. As the name suggests, we work backwards, solving the last equation first, which requires that x3=1x_3=1. We substitute the result back into the middle equation, which becomes 2x2βˆ’1=32x_2-1=3, with solution x2=2x_2=2. We finally substitute the two values x2=2x_2=2 and x3=1x_3=1 into the first equation, which becomes x1+5=2x_1+5=2, and so the solution to the triangular system (8) is

x1=βˆ’3,x2=2,x3=1. x_1=-3, \quad x_2=2, \quad x_3=1.

Even more exciting is that recalling ObservationΒ 1, we know that the triangular system (8) is equivalent to our original system (4), which means that this is also the solution to our original system of equations (you can check). We note that in this case, system (4) has a unique, meaning one and only one, solution. We’ll understand why this is the case later in the semester.

This process was incredibly simple and intuitive: add equations together to eliminate ``downstairs’’ variables until you have found an equivalent triangular system, which can then be readily solved via back substitution. Amazingly, barring a few minor complications that can come up from time to time, this is essentially all there is to Gaussian Elimination. This incredibly simple algorithm is also unbelievably important and powerful. After a brief detour to remind ourselves about matrix and vector notation, we’ll revisit Gaussian Elimination through the lens of matrix factorization, which will allow us to easily automate and scale out these ideas to systems with hundreds or even thousands of variables.

5Worked ExamplesΒΆ

Binder

FootnotesΒΆ
  1. We’ll see later exactly why we call these equations linear, and the deep implications that linearity has on science and engineering. For now, it’s enough to think of an equation as being linear if the unknowns only appear to the first power, and there are no product terms like x1x2x_1x_2 or x1x2x3x_1x_2x_3, in it.

  2. Almost all equations that we will encounter in this class will be defined in terms of real numbers. In certain settings, we will need to use complex numbers, but don’t worry, we’ll go over how to work with complex numbers carefully then.