2 Partial pivoting
Partial pivoting is a refinement of the Gaussian elimination procedure which helps to prevent the growth of rounding error.
2.1 An example to motivate the idea
Consider the example
First of all let us work out the exact answer to this problem
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 significant figures. Eliminating the one non-zero element below the diagonal, and remembering that we are only dealing with 3 significant figures, we obtain
The bottom equation gives , and the top equation therefore gives . Something has gone seriously wrong, for this value for is nowhere near the true value 0.9998…found without rounding.The problem has been caused by using a small number ( ) to eliminate a number much larger in magnitude ( ) below it.
The general idea with partial pivoting is to try to avoid using a small number to eliminate much larger numbers.
Suppose we swap the rows
and proceed as normal, still using just 3 significant figures. This time eliminating the non-zero below the diagonal gives
which leads to and , which is an excellent approximation to the exact values, given that we are only using 3 significant figures.
2.2 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
The first step is to use the 1 in the top left corner to eliminate all the non-zeros below it in the augmented matrix
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 at the diagonal entry and see that the two possible candidates for the swap are both equal to . Either will do so let us swap the second and fourth rows to give
That was the partial pivoting step. Now we proceed with Gaussian elimination
The arithmetic is simpler if we cancel a factor of 4 out of the third row to give
And the elimination phase is completed by removing the from the final row as follows
This system is upper triangular so back substitution can be used now to work out that , , and .
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
into upper triangular form using Gaussian elimination (with partial pivoting when necessary).
The row operations required to eliminate the non-zeros below the diagonal in the first column are
which puts a zero on the diagonal. We are forced to use partial pivoting and swapping the second and third rows gives
which is in the required upper triangular form.
Key Point 4
When To Use Partial Pivoting
- When carrying out Gaussian elimination on a computer, we would usually always swap rows so that the element on the diagonal is as large (in magnitude) as possible. This helps stop the growth of rounding error.
-
When doing hand calculations (not involving rounding) there are two reasons we might pivot
- If the element on the diagonal is zero, we have to swap rows so as to put a non-zero on the diagonal.
- Sometimes we might swap rows so that there is a “nicer" non-zero number on the diagonal than there would be without pivoting. For example, if the number on the diagonal can be arranged to be a 1 then no awkward fractions will be introduced when we carry out row operations related to Gaussian elimination.
Exercises
- Solve the following system by back substitution
-
-
Show that the exact solution of the system of equations
is .
- Working to 3 significant figures, and using Gaussian elimination without pivoting, find an approximation to . Show that the rounding error causes the approximation to to be a very poor one.
- Working to 3 significant figures, and using Gaussian elimination with pivoting, find an approximation to . Show that the approximation this time is a good one.
-
Show that the exact solution of the system of equations
-
Carry out row operations (with partial pivoting if necessary) to reduce these matrices to upper triangular form.
- ,
- ,
- .
(Hint: before tackling (c) you might like to consider point 2(b) in Key Point 4.)
- From the last equation we see that . Using this information in the second equation gives us . Finally, the first equation implies that .
-
-
The formula
can be used to show that
as required.
- Carrying out the elimination without pivoting, and rounding to 3 significant figures we find that and that, therefore, . This is a very poor approximation to .
- To apply partial pivoting we swap the two rows and then eliminate the bottom left element. Consequently we find that, after rounding the system of equations to 3 significant figures, and . These give excellent agreement with the exact answers.
-
The formula
can be used to show that
-
-
The row operations required to eliminate the non-zeros below the diagonal in the first column are as follows
Next we use the element in the middle of the matrix to eliminate the value underneath it. This gives
which is of the required upper triangular form.
-
We must swap the rows to put a non-zero in the top left position (this is the partial pivoting step). Swapping the first and second rows gives the matrix
We carry out one row operation to eliminate the non-zero in the bottom left entry as follows
Next we use the middle element to eliminate the non-zero value underneath it. This gives
which is of the required upper triangular form.
-
If we swap the first and second rows of the matrix then we do not have to deal with fractions. Having done this the row operations required to eliminate the non-zeros below the diagonal in the first column are as follows
Next we use the element in the middle of the matrix to eliminate the non-zero value underneath it. This gives
which is of the required upper triangular form.
-
The row operations required to eliminate the non-zeros below the diagonal in the first column are as follows