Gaussian Elimination: × 2 Matrix
Gaussian Elimination: × 2 Matrix
Gaussian Elimination: × 2 Matrix
_
`
30.2
Introduction
In this Section we will reconsider the Gaussian elimination approach discussed in 8, and we
will see how rounding error can grow if we are not careful in our implementation of the approach. A
method called partial pivoting, which helps stop rounding error from growing, will be introduced.
_
Prerequisites
Before starting this Section you should . . .
revise matrices, especially matrix solution of
equations
recall Gaussian elimination
be able to nd the inverse of a 2 2 matrix
_
`
Learning Outcomes
On completion you should be able to . . .
carry out Gaussian elimination with
partial pivoting
12 HELM (2005):
Workbook 30: Introduction to Numerical Methods
1. Gaussian elimination
Recall from 8 that the basic idea with Gaussian (or Gauss) elimination is to replace the matrix of
coecients with a matrix that is easier to deal with. Usually the nicer matrix is of upper triangular
form which allows us to nd the solution by back substitution. For example, suppose we have
x
1
+ 3x
2
5x
3
= 2
3x
1
+ 11x
2
9x
3
= 4
x
1
+ x
2
+ 6x
3
= 5
which we can abbreviate using an augmented matrix to
1 3 5 2
3 11 9 4
1 1 6 5
.
We use the boxed element to eliminate any non-zeros below it. This involves the following row
operations
1 3 5 2
3 11 9 4
1 1 6 5
R2 3 R1
R3 + R1
1 3 5 2
0 2 6 2
0 4 1 7
.
And the next step is to use the 2 to eliminate the non-zero below it. This requires the nal row
operation
1 3 5 2
0 2 6 2
0 4 1 7
R3 2 R2
1 3 5 2
0 2 6 2
0 0 11 11
.
This is the augmented form for an upper triangular system, writing the system in extended form we
have
x
1
+ 3x
2
5x
3
= 2
2x
2
+ 6x
3
= 2
11x
3
= 11
which is easy to solve from the bottom up, by back substitution.
HELM (2005):
Section 30.2: Gaussian Elimination
13
Example 5
Solve the system
x
1
+ 3x
2
5x
3
= 2
2x
2
+ 6x
3
= 2
11x
3
= 11
Solution
The bottom equation implies that x
3
= 1. The middle equation then gives us that
2x
2
= 2 6x
3
= 2 + 6 = 4 x
2
= 2
and nally, from the top equation,
x
1
= 2 3x
2
+ 5x
3
= 2 6 5 = 9.
Therefore the solution to the problem stated at the beginning of this Section is
x
1
x
2
x
3
9
2
1
.
The following Task will act as useful revision of the Gaussian elimination procedure.
Task
Carry out row operations to reduce the matrix
2 1 4
4 3 1
6 8 2
2 1 4
4 3 1
8 2
R2 2 R1
R3 + 3 R1
2 1 4
0 5 9
0 5 10
2 1 4
0 5 9
0 5 10
R3 R2
2 1 4
0 5 9
0 0 19
10
4
1
1 2
x
1
x
2
1
1
.
First of all let us work out the exact answer to this problem
x
1
x
2
10
4
1
1 2
1
1
=
1
2 10
4
+ 1
2 1
1 10
4
1
1
=
1
2 10
4
+ 1
1
1 + 10
4
0.999800...
0.999900...
.
Now we compare this exact result with the output from Gaussian elimination. Let us suppose, for
sake of argument, that all numbers are rounded to 3 signicant gures. Eliminating the one non-zero
element below the diagonal, and remembering that we are only dealing with 3 signicant gures, we
obtain
10
4
1
0 10
4
x
1
x
2
1
10
4
.
The bottom equation gives x
2
= 1, and the top equation therefore gives x
1
= 0. Something has
gone seriously wrong, for this value for x
1
is nowhere near the true value 0.9998. . . found without
rounding.The problem has been caused by using a small number (10
4
) to eliminate a number much
larger in magnitude (1) below it.
The general idea with partial pivoting is to try to avoid using a small number to eliminate much
larger numbers.
HELM (2005):
Section 30.2: Gaussian Elimination
15
Suppose we swap the rows
1 2
10
4
1
x
1
x
2
1
1
and proceed as normal, still using just 3 signicant gures. This time eliminating the non-zero below
the diagonal gives
1 2
0 1
x
1
x
2
1
1
which leads to x
2
= 1 and x
1
= 1, which is an excellent approximation to the exact values, given
that we are only using 3 signicant gures.
Partial pivoting in general
At each step the aim in Gaussian elimination is to use an element on the diagonal to eliminate all
the non-zeros below. In partial pivoting we look at all of these elements (the diagonal and the ones
below) and swap the rows (if necessary) so that the element on the diagonal is not very much smaller
than the other elements.
Key Point 3
Partial Pivoting
This involves scanning a column from the diagonal down. If the diagonal entry is very much smaller
than any of the others we swap rows. Then we proceed with Gaussian elimination in the usual way.
In practice on a computer we swap rows to ensure that the diagonal entry is always the largest
possible (in magnitude). For calculations we can carry out by hand it is usually only necessary to
worry about partial pivoting if a zero crops up in a place which stops Gaussian elimination working.
Consider this example
1 3 2 1
2 6 1 4
1 2 3 4
0 1 1 1
x
1
x
2
x
3
x
4
4
1
12
0
.
The rst step is to use the 1 in the top left corner to eliminate all the non-zeros below it in the
augmented matrix
1 3 2 1 4
2 6 1 4 1
1 2 3 4 12
0 1 1 1 0
R2 2 R1
R3 + R1
1 3 2 1 4
0 0 3 2 9
0 1 5 5 8
0 1 1 1 0
.
What we would like to do now is to use the boxed element to eliminate all the non-zeros below it.
But clearly this is impossible. We need to apply partial pivoting. We look down the column starting
16 HELM (2005):
Workbook 30: Introduction to Numerical Methods
at the diagonal entry and see that the two possible candidates for the swap are both equal to 1.
Either will do so let us swap the second and fourth rows to give
1 3 2 1 4
0 1 1 1 0
0 1 5 5 8
0 0 3 2 9
.
That was the partial pivoting step. Now we proceed with Gaussian elimination
1 3 2 1 4
0 1 1 1 0
0 1 5 5 8
0 0 3 2 9
R3 R2
1 3 2 1 4
0 1 1 1 0
0 0 4 4 8
0 0 3 2 9
.
The arithmetic is simpler if we cancel a factor of 4 out of the third row to give
1 3 2 1 4
0 1 1 1 0
0 0 1 1 2
0 0 3 2 9
.
And the eliminition phase is completed by removing the 3 from the nal row as follows
1 3 2 1 4
0 1 1 1 0
0 0 1 1 2
0 0 3 2 9
R4 + 3 R3
1 3 2 1 4
0 1 1 1 0
0 0 1 1 2
0 0 0 5 15
.
This system is upper triangular so back substitution can be used now to work out that x
4
= 3,
x
3
= 1, x
2
= 2 and x
1
= 1.
The Task below is a case in which partial pivoting is required.
[For a large system which can be solved by Gauss elimination see Engineering Example 1 on page
62].
Task
Transform the matrix
1 2 4
3 6 11
4 3 5
into upper triangular form using Gaussian elimination (with partial pivoting when
necessary).
HELM (2005):
Section 30.2: Gaussian Elimination
17
Your solution
Answer
The row operations required to eliminate the non-zeros below the diagonal in the rst column are
1 2 4
3 6 11
4 3 5
R2 + 3 R1
R3 4 R1
1 2 4
0 0 1
0 11 11
which puts a zero on the diagonal. We are forced to use partial pivoting and swapping the second
and third rows gives
1 2 4
0 11 11
0 0 1
10
5
1
2 4
x
1
x
2
2
10
is
x
1
x
2
0.99998
2.00001
.
(b) Working to 3 signicant gures, and using Gaussian elimination without pivoting, nd an
approximation to
x
1
x
2
x
1
x
2
1 2 4
4 3 3
1 13 1
, (b)
0 1 2
1 4 2
2 5 4
, (c)
3 10 1
1 3 2
2 10 4
.
(Hint: before tackling (c) you might like to consider point 2(b) in Key Point 4.)
Answers
1. From the last equation we see that x
3
= 2. Using this information in the second equation
gives us x
2
= 2. Finally, the rst equation implies that x
1
= 3.
2. (a) The formula
a b
c d
1
=
1
ad bc
d b
c a
1 2 4
4 3 3
1 13 1
R2 + 4 R1
R3 + 1 R1
1 2 4
0 11 13
0 11 5
Next we use the element in the middle of the matrix to eliminate the value underneath
it. This gives
1 2 4
0 11 13
0 0 18
1 4 2
0 1 2
2 5 4
.
We carry out one row operation to eliminate the non-zero in the bottom left entry as
follows
1 4 2
0 1 2
2 5 4
R3 + 2 R1
1 4 2
0 1 2
0 3 0
Next we use the middle element to eliminate the non-zero value underneath it. This
gives
1 4 2
0 1 2
0 0 6
1 3 2
3 10 1
2 10 4
R2 + 3 R1
R3 + 2 R1
1 3 2
0 1 7
0 4 0
Next we use the element in the middle of the matrix to eliminate the non-zero value
underneath it. This gives
1 3 2
0 1 7
0 0 28