Chapter 1 - Numerical Algorithms
Approximating the derivative
We can approximate the derivative of a function at as where the error is of order . For , for example we get
We can investigate how the error behaves as gets smaller. To plot the error as a function of , we can evaluate the error for multiple at the same time (note the subtle changes in the Matlab code used to compute the approximation).
Do Exercise 1.4.1
A better approximation of the derivative is supposedly given by
Do Exercise 1.4.2 and show that the error is indeed of order .
Do Exercise 1.4.3
Evaluating functions
Numerical errors can cause problems even when performing seemingly simple tasks like evaluating a function. To study this, we consider evaluating a function at a point and a nearby point . The relative error between the points is given by , and the relative error in the function value is given by . The question is, is the relative error in the function, , bigger or smaller then the relative error in ? If it is bigger, then we call ill-conditioned (near ) because it will blow up small errors. For near , for example, we get
so this function is well-conditioned near (why?) Looking at arouns we find
making this function function ill-conditioned (near ). Can you explain why these two functions behave like they do? (Hint: use the fact that is small).
Do Exercise 1.4.4
Chapter 2 - Roundoff errors
Consider the following equivalent representations of the same polynomial
and
and plot the function using both expressions on the interval . Zoom in around the roots; can you explain the difference between the two graphs?
Cancellation errors
In the previous chapter we saw that when computing the derivative with finite differences, cancallation errors caused the approximation error to grow for small step-sizes. In some cases these cancellation errors can be prevented by rewriting the expressions used in the computations
Do Exercise 2.5.{2,11,12(a),13}
Accumulation of roundoff errors and overflow
Another issue is the accumulation of roundoff errors when performing many arithmetic operations or when computing with large numbers. As an example, let's consider computing for some given and large . Of course, we expect as final result. We can compute this in three different ways and compare. We'll first use and .
Try it again using and large (for example and ), what do you notice? Can you explain this?
Do Exercise 2.5.{12(b), 15, 19}