next up previous
Next: About this document ...

ESC 251 HW 21 Due: Oct. 27

1)
(6 pts) For this problem, you will compare 2 methods for approximating the derivative of a function. Using the code in the notes as a guide, generate a table of values of f(x) for $x \in [a,b].$ In addition, at each x-coordinate, generate approximations for f'(x) using the formulas:

\begin{displaymath}f'(x) \approx \frac{f(x+\Delta x) - f(x)}{\Delta x}\end{displaymath}

and

\begin{displaymath}f'(x) \approx \frac{f(x+\Delta x) - f(x-\Delta x)}{2 \Delta x}.\end{displaymath}

Compute the relative errors in your approximations Note that you will have a relative error for each point in the table and some of the relative errors will need special attention.

Test your program using $f(x) = x\,\sin(x)$ on the interval $x \in [0,\pi].$ Use n = 10 and $\Delta x = 0.0001.$ Which derivative approximation is more accurate? If you try to print out x, f(x), both approximations for f'(x) and their relative errors on one line, your output will wrap at the screen boundary so you may need to experiment with your data output.

2)
What happens to your errors in Problem 1 if you try and use $\Delta x = 10^{-11}?$ Note that 10-11 = 1.0d-11 Why does this happen?





2017-10-27