row reduc 97

advertisement
SIF Computer Project: Gaussian Elimination and rref
Name ______________________________
Purpose: To calculate the reduced row echelon form by hand and with rref, and to see some effects of roundoff error.
Prerequisite: Section 1.3 and 1.4 in “Elementary Linear Algebra,” by Spence, Insel and Friedberg, 2000.
MATLAB functions used: -, /; format, rref ; and rowdat from a Math 129A diskette.
Background: Read about elementary row operations, reduced row echelon form, and the Gaussian Elimination algorithm in
Sections 1.3-1.4.
Type rowdat to get two matrices, A and B.
Part I. Compare Gaussian Elimination and the output of rref.
1. (a) (hand) Using the Gaussian Elimination Algorithm, calculate the reduced row echelon form of A by hand. Show all
steps:
 0
 1
A= 
 2

 1
3
6
4
2
1
3
3
4
0
5
3
9
9
1
~
 1

 7
(b) (MATLAB) Type rref(A) . Does the output look the same as what you obtained above? ____ (If not, redo hand
calculations.)
2. (a) (hand) Using the Gaussian Elimination Algorithm, calculate the reduced row echelon form of B by hand. Show all
steps:
1
SIF Project 3. G.E. and rref - J.M. Day, Aug. 05
 0.1
B =  0.3
 0
0.1
0.2
0.5
2
0.7 ~
6.7
(c) (MATLAB) Type rref(B) . Does the output look the same as what you obtained above? ____ (If not, redo hand
calculations.)
Part II. When should a calculated number be considered zero?
2
SIF Project 3. G.E. and rref - J.M. Day, Aug. 05
MATLAB does floating point arithmetic, so there is almost always some roundoff error when it does calculations. In
particular, a number which theoretically should be zero may turn out to be a very small nonzero number instead. Indeed,
roundoff error during pivoting on the (1,1) and (2,2) positions of B does actually cause the third row to be of the form
[0 0 x] where x is not truly zero; but rref treated x as if it were zero and did not pivot on the (3,3) position, so the final
result of rref(B) is correct.
In fact, every implementation of floating point arithmetic sets a value which it considers true zero. We will call this
value “tolerance.” Clearly it is a matter of judgment to decide what value to use for tolerance. In the problem below, you will
experiment with different values for this constant, and will be able to get a pretty good estimate of what its value is.
Specifically, you will see that if you make the value of tolerance a little smaller, the output of rref(B) will be wrong.
Recall that typing 1e-16 is a way to enter the number 10-16 in MATLAB. Thus
10-16 = 1e-16 < 2e-16 < … < 9e-16 < 10e-16 = 1e-15 = 10-15.
3. (MATLAB) Use the same matrix B as in question 2. Here you will force rref(B) to return the wrong answer by
making the value of tol too small; and you will experiment to figure out a good estimate for what is the default value of tol.
(a) Type each of the following commands and record the result:
rref( B, 1e-15 )
rref( B, 1e-16 )
Why can you now be certain that the default value for tol is between 10-15 and 10-16 ?
(b) Experiment to find more precise bounds for the default value of tol, and record the best upper and lower bounds you
find:
Hint: type rref(B, e-15) , then rref(B, 9e-16) ; is tol between 1e-15 and 9e-16 ? Etc.
Note: MATLAB has special functions that do row operations for various purposes, and these are extremely accurate for the
vast majority of matrices. (One of these functions is backslash. Type help \ to learn about it.) The most important reason
for their accuracy is not the value for tolerance, but instead the fact that these functions do not pivot on a value that is
extremely small compared to the entries below it. This process, called “partial pivoting,” is a slightly modified Gaussian
Elimination algorithm: it finds the next pivot position as described in Sec. 1.3 of our text, next searches its column to find the
largest magnitude entry in or below that pivot position, and then does a row exchange if necessary to put the largest
magnitude number found into that pivot position.
This row exchange step reduces roundoff error because it causes prevents division by a number that is small compared
to the numbers below it. In more detail, each pivot operation adds a scalar multiple of the pivot row to each row below it;
when partial pivoting is done, those scalars are always less than or equal to one in magnitude.
Partial pivoting is studied in numerical analysis courses.
3
SIF Project 3. G.E. and rref - J.M. Day, Aug. 05
Download