2. Systems of Linear Equations and Floating-Point Errors
§2.1 Floating Point Limitations
Of course, in theory, dividing a number indefinitely by 2 will never result in a value at or below zero. In practice, however, there appears to be a limit to how small numbers can get in MATLAB.
Let's look at another example of the limitations to which floating point numbers are subject. Let's look at the sum (also called a 'series'):
What if we wanted to know the difference between the value of this series, when x = 1, after 38 terms and its value after 41 terms? Let's look at the sum of the first 38 terms of the expansion at x = 1. Enter this:
>> x = 1; Sum_38 = 1;
>> for n = 1 : 38
Sum_38 = Sum_38 + (x^n)/factorial(n);
end
Of
course, the value of this series after 38 terms is not the same as the
value of the series after 41 terms, even though Matlab told us the
difference between them was zero. This time, MATLAB's error was
not due to a number being too small (as in the first example), but
rather has to do with where the significant figures are in the numbers
being added. Now let's switch our attention to errors that can
come up in linear algebra.
§2.2 Systems of Linear Equations
By now we have seen how a system of linear equations can be transformed into a matrix equation, making the system easier to solve. For example, the system
can be written the following way
Now, by augmenting the matrix with the vector on the right and using row operations, this equation can easily be solved by hand. However, if our system did not have nice integer entries, solving the system by hand using row reduction could become very difficult. MATLAB provides us with an easier way to get an answer.
A system of this type has the form Ax = b, so we can enter these numbers into MATLAB using the following commands:
>> A = [2 -1 1; 1 2 3; 3 0 -1];
>> b = [8; 9; 3]
(Notice that for the column vector b, we include semicolons after each entry to ensure that the entries are on different rows; the command
>> b = [8 9 3]
would produce a row vector, which is not the same thing.)
The command
>> x = A\b
will find the solution (if it exists) to our equation Ax = b. In this case, MATLAB tells us
x =
2.0000
-1.0000
3.0000
The discrepancy in part (d) of the above exercise is simply due to rounding error. You'll notice that the error is a vector multiplied by a very small number, one on the order of 10-15. But why is there any error at all? After all, solving by row reduction gave very nice numbers, right? The reason is that MATLAB doesn't solve this problem the way you did. Instead, MATLAB uses complicated calculations to find the inverse of C, C-1, then finds the answer by the formula x = C-1*d. Some error is introduced when calculating C-1.
§2.3 Effects of Errors
So far, the error that we encounter appears to be extremely small. Will it really make a difference in a real-world application? Often the answer is no, but it is important to be aware of the difference even a small error can make. For one thing, if a problem requires many calculations and each calculation introduces a small, seemingly insignificant error, the errors can compound through the calculations until the small errors have become very large. But even a tiny error in a single calculation has the potential to cause big problems given the right (or wrong) circumstances.
For example, consider a linear system given by
ax + y = 3.5
bx + y = 3.0
and suppose through MATLAB calculations we have determined that a and b are both within 0.001 of 0.27; i.e. a = 0.27 ± 0.001 and b = 0.27 ± 0.001. How much difference can an error of ±0.001 make? We know that
0.269 ≤ a ≤ 0.271 and
0.269 ≤ b ≤ 0.271
so let's just test the extremes.
§2.4 Conclusion
Floating-point errors are an inherent part of computer calculations and knowing how to handle them is necessary in any field that uses computers to model real-world scenarios. Error analysis now is an important and active area of mathematical study because, in practice, problems can arise very quickly if even small errors are not kept in check.
Last Modified:
09/26/04