Gaussian Elimination

You're already familiar with solving pairs of simultaneous equations in two variables, such as

x+2y=10,
3x-y=9.

Just to recap: you might subtract three times the first equation from the second, thus eliminating x and obtaining

-7y=-21,

whence y=3. Then, substituting into the first equation gives

x+7=10,

from which we get x=4.

One thing to notice is that during the elimination phase, we have no need to use the symbols x and y: the whole elimination problem can be solved in matrix form. We begin by forming what we call the augmented matrix; this consists of the matrix of coefficients, togther with an additional column representing the right-hand-sides:

\left(\begin{array}{ccc}1&2&10\\3&-1&9\end{array}\right).

Call the first row r_{1} and the second r_{2}. We then simply replace r_{2} with r_{2}-3r_{1}, to obtain

\left(\begin{array}{ccc}1&2&10\\0&-7&-21\end{array}\right),

at which point the substitution process can begin.

(There might seem little point in getting rid of the symbols and working with matrices in this way. However, it has at least two advantages. The first is that for larger, more complicated systems, it prevents confusion and keeps things systematic. The second is that it lends itself to automation on computer.)

The way things work with larger systems is exactly the same, except that because more variables are involved, we have to take more care. Consider the problem

x+2y+3z=15,
2x+7y+3z=24,
3x+9y+4z=33.

As with the 2 by 2 case, we start by forming the augmented matrix:

\left(\begin{array}{cccc}1&2&3&15\\2&7&3&24\\3&9&4&33\end{array}\right).

Call the three rows r_{1}, r_{2} and r_{3}.

Now, the rules of the game are as follows. We want to end up with one of our equations (usually the third) containing just z, with x and y having been eliminated. This will enable us to work out what z's value is. We also want one of our equations (usually the second) to contain just y and z, with x having been eliminated. Then, knowing the value of z, we can work out that of y. Finally, knowing the values of both y and z, we can work out that of x from the first equation.

In matrix terms, this means we want row 3 to be of the form

\begin{array}{cccc}0&0&?&?\end{array}

(where the question marks represent numbers) and row 2 of the form

\begin{array}{cccc}0&?&?&?\end{array}.

Overall, then, the matrix we end up with after the elimination ought to be of the form

\left(\begin{array}{cccc}?&?&?&?\\0&?&?&?\\0&0&?&?\end{array}\right).

A matrix like this, with zeros below the leading diagonal, is said to be in row echelon form.

To get the matrix into row echelon form, we are allowed to perform what are called permitted row operations. These correspond to the kind of thing we're allowed to do with simultaneous equations. We may do the following things:

1. Given a row, subtract a multiple of another row from it.

2. Given a row, multiply or divide throughout by some number.

3. Swap the order of two rows.

Here's how it works with our example.

Step 1: make zeros in the first column

Starting with the augmented matrix,

\left(\begin{array}{cccc}1&2&3&15\\2&7&3&24\\3&9&4&33\end{array}\right),

we first try to create a matrix of the form

\left(\begin{array}{cccc}?&?&?&?\\0&?&?&?\\0&?&?&?\end{array}\right),

with zeros in column 1 of rows 2 and 3. To do this we:

(i) replace r_{2} by r_{2}-2r_{1};

(ii) replace r_{3} by r_{3}-3r_{1}.

This gives

\left(\begin{array}{cccc}1&2&3&15\\0&3&-3&-6\\0&3&-5&-12\end{array}\right).

Step 2: make zeros in the second column

We now try to complete the process, and create a matrix of the form

\left(\begin{array}{cccc}?&?&?&?\\0&?&?&?\\0&0&?&?\end{array}\right),

To do this we simply replace r_{3} by r_{3}-r_{2}.

This gives

\left(\begin{array}{cccc}1&2&3&15\\0&3&-3&-6\\0&0&-2&-6\end{array}\right).

Step 3: back-substitution

We can now solve the system by back-substitution. Our final row gives us

-2z=-6,

from which we get z=3.

Our second row thus becomes

3y-9=-6,

giving y=1.

Our first row is then

x+2+9=15,

and thus x=4.

Description of the process

This process is known as Gaussian elimination. It's a very efficient way of solving one-off problems, and has one huge advantage over most other methods, in that it can also be used where the number of equations and the number of unknowns are not the same. It works like this. To solve the m by n system

\left(\begin{array}{cccc}a_{11}&a_{12}&\cdots &a_{1n}\\a_{21}&a_{22}&\cdots &a_{2n}\\\vdots &\vdots &\ddots&\vdots \\a_{m\,1}&a_{m\,2}&\cdots &a_{m\,n}\end{array}\right)\left(\begin{array}{c}x_{1}\\x_{2}\\\vdots \\x_{n}\end{array}\right)=\left(\begin{array}{c}v_{1}\\v_{2}\\\vdots \\v_{m}\end{array}\right):

1. Form the m by \left(n+1\right) augmented matrix

\left(\begin{array}{ccccc}a_{11}&a_{12}&\cdots &a_{1n}&v_{1}\\a_{21}&a_{22}&\cdots &a_{2n}&v_{2}\\\vdots &\vdots &\ddots&\vdots &\vdots \\a_{m\,1}&a_{m\,2}&\cdots &a_{m\,n}&v_{m}\end{array}\right)

2. Set j=1.

3. For each i>j, replace row r_{i} with

r_{i}-\frac{a_{i\,j}}{a_{j\,j}}r_{j.}

This will zero all the entries in column j below the leading diagonal.

4. If j<m, set j=j+1 and return to 3, else stop the elimination process and move on.

5. Solve the system by back-substitution.

The process hits a hitch if, at any stage, one of the diagonal entries a_{j\,j} is zero. When this happens, this can usually be dealt with by swapping row r_{j} with one of the rows below it.

Created with the ExportAsWebPage package in Wolfram Mathematica 7.0