I'm doing the following exercise:
Consider $$ f(x)= \begin{cases} \displaystyle\frac{1-(\cos(x))^3}{x^2}, \quad if\ x\neq 0\\ \displaystyle\frac{3}{2}, \quad if\ x= 0\\ \end{cases} $$
Calculate $f(x_0)$, with $x_0=0.000011$, with a C program (simple and double precision) and with a pocket calculator. Identify the cause of the error. Justify the differences and the magnitude of the errors.
I know that there's cancellation on the numerator and the rounding errors on every operation ($\cos(x)$, $(\cos(x))^3$, $1-(\cos(x))^3$ and dividing that quantity by $x^2$). The calculator gives me $0$, and the correct answer is very near to $3/2$. This is because a pocket calculator can store only 9 significant digits, and $1-(\cos(x_0))^3$ is $0$ for a calculator. But how can I measure the magnitude of the errors when there're not rounding errors on the input? The quantity given by $x_0$ is exact and the computer write this quantity correctly in simple and double precision, so there's only rounding errors inside every operation. Can I measure the magnitude by using the propagation of errors' formula? This formula says: $$|\Delta f(x)|=|f'(x)|\cdot|\Delta x|.$$
Thanks!
The error of the denominator can be estimated using relative error formulas for floating point evaluations as $$ (1-(\cos(x)·(1+δ_1))^3·(1+δ_2))·(1+δ_3) \\ = (1-\cos(x)^3)·(1+δ_3)-\cos(x)^3·(3δ_1+δ_2)+O(δ^2) $$ where $|δ_k|<\mu=2^{-52}$ (the last for
double). Thus the relative error of the denominator computation is $$ δ_4=δ_3+\frac{\cos(x)^3}{1-\cos(x)^3}·(3δ_1+δ_2) $$ which for $x=1.1·10^{-5}$ is bounded by $|δ_4|<5.51·10^9·\mu$. For the full quotient this relative error transfers and using a more exact evaluation formula, this error is confirmed aswhich gives the relative error as $3.68·10^9⋅μ$.