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

1 0 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 = 1 0 4 1 1 2 1 1 1 = 1 2 × 1 0 4 + 1 2 1 1 1 0 4 1 1 = 1 2 × 1 0 4 + 1 1 1 + 1 0 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 significant figures. Eliminating the one non-zero element below the diagonal, and remembering that we are only dealing with 3 significant figures, we obtain

1 0 4 1 0 1 0 4 x 1 x 2 = 1 1 0 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 ( 1 0 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.

Suppose we swap the rows

1 2 1 0 4 1 x 1 x 2 = 1 1

and proceed as normal, still using just 3 significant figures. 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 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

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 first 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 R 2 2 × R 1 R 3 + R 1 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 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 R 3 R 2 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 elimination phase is completed by removing the 3 from the final row as follows

1 3 2 1 4 0 1 1 1 0 0 0 1 1 2 0 0 3 2 9 R 4 + 3 × R 3 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).

The row operations required to eliminate the non-zeros below the diagonal in the first column are

1 2 4 3 6 11 4 3 5 R 2 + 3 × R 1 R 3 4 × R 1 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

which is in the required upper triangular form.

Key Point 4

When To Use Partial Pivoting

  1. 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.
  2. When doing hand calculations (not involving rounding) there are two reasons we might pivot
    1. If the element on the diagonal is zero, we have to swap rows so as to put a non-zero on the diagonal.
    2. 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
  1. Solve the following system by back substitution x 1 + 2 x 2 x 3 = 3 5 x 2 + 6 x 3 = 2 7 x 3 = 14
    1. Show that the exact solution of the system of equations

      1 0 5 1 2 4 x 1 x 2 = 2 10  is  x 1 x 2 = 0.99998 2.00001 .

    2. Working to 3 significant figures, and using Gaussian elimination without pivoting, find an approximation to x 1 x 2 . Show that the rounding error causes the approximation to x 1 to be a very poor one.
    3. Working to 3 significant figures, and using Gaussian elimination with pivoting, find an approximation to x 1 x 2 . Show that the approximation this time is a good one.
  2. Carry out row operations (with partial pivoting if necessary) to reduce these matrices to upper triangular form.
    1. 1 2 4 4 3 3 1 13 1 ,
    2. 0 1 2 1 4 2 2 5 4 ,
    3. 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.)

  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 first equation implies that x 1 = 3 .
    1. The formula a b c d 1 = 1 a d b c d b c a can be used to show that

      x 1 = 50000 50001 = 0.99998 and x 2 = 200005 100002 = 2.00001 as required.

    2. Carrying out the elimination without pivoting, and rounding to 3 significant figures we find that x 2 = 2.00 and that, therefore, x 1 = 0 . This is a very poor approximation to x 1 .
    3. 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, x 2 = 2.00 and x 1 = 1.00 . These give excellent agreement with the exact answers.
    1. The row operations required to eliminate the non-zeros below the diagonal in the first column are as follows

      1 2 4 4 3 3 1 13 1 R 2 + 4 × R 1 R 3 + 1 × R 1 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 which is of the required upper triangular form.

    2. 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

      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 R 3 + 2 × R 1 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 which is of the required upper triangular form.

    3. 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

      1 3 2 3 10 1 2 10 4 R 2 + 3 × R 1 R 3 + 2 × R 1 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 which is of the required upper triangular form.