Explaining error in a floating-point calculation

165 Views Asked by At

I'm working through a numerical analysis text and came across this question.

The function $f_{1}(x,\delta) = \cos(x + \delta) - \cos(x)$ can be transformed into another form, $f_{2}(x,\delta)$, using the formula $$ \cos(\phi) - \cos(\varphi) = -2\sin\bigg(\frac{\phi + \varphi}{2}\bigg)\sin\bigg(\frac{\phi - \varphi}{2}\bigg) $$ Thus, $f_{1}$ and $f_{2}$ have the same values, in exact arithmetic, for any given argument values $x$ and $\delta$.

(1) Show that, analytically, $f_{1}/\delta$ and $f_{2}/\delta$ are effective approximations.

This is very vague. How might this be accomplished?

(2) Explain the difference in the computed results (in MATLAB or a similar software) for $$\frac{f_{1}}{\delta} + \sin(x) \hspace{5mm} \text{ and } \hspace{5mm} \frac{f_{2}}{\delta} + \sin(x)$$

using $x = 3$ and $\delta = 1\times10^{-11}$.

I made a table of the computed values:

enter image description here

and I thus have $$\frac{f_{1}}{\delta} + sin(x) = -4.4060023643433\times 10^{-07}$$ $$\frac{f_{2}}{\delta} + sin(x) = 4.94995711086688\times 10^{-12}$$

How do I explanation these differences? I want to say that the division by $\delta$, which is arbitrarily small, amplifies the roundoff error in the calculations for $f_{1}$ and $f_{2}$. Then, the addition of $\sin(x)$ results in cancellation of significant digits since the two numbers are nearly equal. I am new to this new terminology so I want to get it straight. May you comment on my explanation?

1

There are 1 best solutions below

2
On

Perhaps you lost some words and the first part is (1) Show that, analytically, $f_{1}/\delta$ and $f_{2}/\delta$ are effective approximations to $\frac {d\cos x}{dx}$ I suggest this because it looks like the thing you take the limit (as $\delta \to 0$) of to get the derivative. Then $\frac {f_1(x,\delta)}\delta \approx -\sin x$ and you might expect the addition of $\sin x$ to result in cancellation.

To explain the difference in $f_1$ and $f_2$ as computed, note that the numerator in $f_1$ has two nearly equal quantities being subtracted so you will get cancellation. In $f_2$ the subtraction is handled analytically because the second term is $\sin \frac \delta 2$ and no cancellation occurs at this step.