Mathematics 172 – Numerical Analysis 2 Lab/Problem Set 3, Studying Gaussian Elimination with Maple February 25, 1999

The Goals for Today’s Session

Today, we will use Maple to perform the Gaussian elimination procedure we discussed last time in class. The main goal is to get a feeling for how this procedure can behave when floating-point arithmetic is employed.

The linalg Package

Most of Maple’s built-in routines for linear algebra operations are contained in an external package called linalg. As with the functions in other Maple packages, you will need to load this package before you can use them. This is done by issuing a

                               with(linalg);

command. Do this now. This command should generate a list of about 100 different procedure names. Take a look at them and see if you can guess what they do. As always, you can also use the Maple on-line help to get info about the correct format of the commands and exactly what they do.

Entering Matrices

In Maple, matrices are represented essentially as lists of row vectors (or lists of lists). For instance, to type in a 3 × 3 matrix

A = ( \begin{matrix}3 & 6 & 9 \\ −1 & 0 & 2 \\ 6 & 7 & 21 \end{matrix} )

you would use a format like this:

                 A := array([[3,6,9],[-1,0,2],[6,7,21]]);

Try it and note the nicely formatted output!

Row Operations

The linalg functions that perform row operations on a matrix are called:

1) mulrow – multiplies a row of a matrix by an expression (the expression can be a constant, or an expression involving only constants, of course!).

2) addrow – adds a multiple of a row to another row.

3) swaprow – interchanges two rows.

Look at the Maple on-line help files for each of these. There shouldn’t be any surprises; the addrow format is slightly tricky to remember though – you may want to write down the format of the command so you will not have to go back and look at it repeatedly!

Experiment with a few operations on your matrix A from above to get the hang of it.

Bringing Floating-Point Arithmetic into the Picture

As we have seen before, there is a built-in Maple variable called Digits. Its default value is 10, but you can set it to a smaller or larger value if you like. To illustrate, and exaggerate some round-off effects, set

                           Digits := 4;

(Maple will now act like a 4-digit rounding calculator for the arithmetic operations.)

Lab Problems

A) Enter the augmented matrix for this system of equations:

(1)  \begin{aligned}−.002x_{1} & + & 4x_{2} & + & 4x_{3} & = 7.998 \\ −2x_{1} & + & 2.906x_{2} & − & 5.387x_{3} & = −4.481 \\ 3x_{1} & − & 4.031x_{2} & − & 3.112x_{3} & = −4.143 \end{aligned}

and perform row operations on it according to the Gaussian Elimination method. One suggestion: If you call your original augmented matrix augmat, the the command

                 augmat := addrow(augmat,1,2,-2);

would add −2 times row 1 to row 2, then store the results back into the variable augmat, so you can continue with further row operations on that matrix. What is your computed solution? Note: The exact solution is (x_{1}, x_{2}, x_{3}) = (1, 1, 1). (Check it if you don’t believe me!) What happened?? What happens if you repeat the calculation after setting Digits back to the default value of 10? Would the “full” Gauss-Jordan elimination procedure be better, or potentially even worse than Gaussian Elimination on an example like this using Digits = 4? (You can experiment a bit, or think about it without calculation.)

B) (Some Prophylaxis?) As a counter-measure, most good numerical software uses a selection scheme of some sort for the pivot element to use when there is a choice. A good selection scheme will minimize the effects of round-off error in the computations of the Gaussian Elimination. The most basic selection scheme is the following:

“Maximal Column Pivoting:” In selecting the pivot element in each column, do not use the first non-zero column element encountered. Instead, pick the element in the column (on or below the diagonal) that is largest in absolute value.

1) Redo the Gauss elimination for (1) above using maximal column pivoting, still using 4-digit rounding arithmetic. How do your results compare with the previous results?

2) Why is maximal column pivoting better?

C) For the following system:

1.19x_{1} + 2.11x_{2} − 100x_{3} +x_{4} = 1.12
14.2x_{1} − 0.122x_{2} − 12.2x_{3} −x_{4} = 3.44
100x_{2} − 99.9x_{3} +x_{4} = 2.15
15.3x_{1} + 0.11x_{2} − 13.1x_{3} −x_{4} = 4.16

1) Solve the system by Gaussian Elimination (without pivoting) using 3-digit rounding arithmetic.

2) Repeat part 1 using Maximal Column Pivoting and 3-digit rounding arithmetic.

3) Now repeat part 1 using 10-digit rounding arithmetic. with and without pivoting.

4) Discuss your results.

D) (For after class on Tuesday, March 2) Do 2 a,c; 3 a,c; 5c from section 6.5 of Burden and Faires (page 402-3).

Assignment

Individual write-ups due Tuesday, March 16 (after Spring Break).

For Future Reference – Maple’s Linear Equation-Solvers

In the future, to solve systems of linear equations, we will not need to do rowoperations explicitly! Instead, we will use Maple’s built-in commands:

1) gausselim: Does Gaussian elimination with maximal column pivoting.

2) backsub: Does back-substitution on the eliminated matrix.

3) linsolve: basically, this is a combination of 1 and 2.

4) gaussjord: Does Gauss-Jordan reduction with pivoting.