Computer Project 1
Catastrophic cancellation or loss of significant digits can occur due to
roundoff error in using a floating point number system. One must be on
guard to avoid situations that can lead to such cancellation.
This may require
re-formulating equations, increasing floating point precision, or
minimizing the number of calculations.
The purpose of this project is to become familiar with Matlab and to
demonstrate the occurrence of catastrophic
cancellation Some preventative measures will be tried. We
consider the simple function
f(x) = (x-1.0)8
on the interval (0.99,1.01). This seems harmless enough!
Write a Matlab program for the steps below
to help illustrate the
effect of roundoff error.
For each of
the following parts, generate 101 equally spaced data
points (check out the linspace command) for the given
functions and generate a graph using Matlab.
- Plot f(x) on the
interval (0.99, 1.01).
- Algebraically expand f(x) and plot
the 8th order polynomial on the interval (0.99,
1.01). Generate a graph. You can expand it by hand or using Maple.
- Use Horner's method to evaluate the expanded function in part 2. at
the same 101 points. Use the built-in function to implement
Horner's method -- polyval(,). Again generate a graph.
- Use Matlab to place on three graphs in the same axes with
each graph having a different line type. Make a legend to describe
the different plots and label the axes.
- Write a paragraph describing the differences in the plots.
Which gives the most accurate result? What is the source of the
differences?
Describe Matlab's default floating point number system?
You are to submit a diary listing of your commands or an m-file
along the the requested plots.