2

Suppose $f(x) = \sqrt{x^2+1}-x$ is to be computed in 4-digit rounding arithmetic. (i) Determine the value of $f(42.545)$ in 4-digit rounding arithmetic, and the relative error of this value.

Notation: $fl(a)$ means 4-digit rounding of the value $a$.

$x=42.545 \implies fl(x)=0.4255x10^2$

$fl(x) \times fl(x)=1810.5025=0.18105025 \times 10^4$

$fl[fl(x)\times fl(x)]=0.1811\times 10^4$

$fl[fl(x)\times fl(x)]+1=0.1812\times 10^4$

let $a=\sqrt{fl[fl(x)\times fl(x)]+1}=42.56759331$

$fl(a)=0.4257x10^2$

$fl(a) - x=0.02$

Now the exactly value is 0.01175, so i assume there has to be an instance or instances of catastrophic cancellation somewhere in the computation (did i even do that right?) but i can't seem to find it.

Furthermore, is there another method to calculate this to minimise the error?

Danxe
  • 1,695
  • Your computations looks correct. It's not really strange the result is off: you are subtracting two numbers that are very close to each other and since $x >10$ you can only represent two decimal digits of these two numbers so we would expect an error in the subtraction that is $\sim 0.01$. – Winther Jan 25 '16 at 00:02
  • Thanks man! I was wondering why it's so far off unlike the other questions that I have done and now i get it. Thanks so much for explaining! – Danxe Jan 25 '16 at 01:07

1 Answers1

2

You see that $$ f(x)=\frac{1}{\sqrt{1+x^2}+x}\;? $$


This formula shows that the difference $f(x)$ between $x$ and $\sqrt{x^2+1}$ is of size $1/(2x)$. The difference in magnitude between these terms explains the cancellation.

It also gives a way to compute the result exactly and without cancellation.


Using Taylor series in $1/x$ one can also observe that for large $x$ $$ \sqrt{1+x^2}-x=x(\sqrt{1+x^{-2}}-1)=x(\tfrac12x^{-2}-\tfrac38x^{-4}+\tfrac5{16}x^{-6}\mp…)\\ =\frac1{2x}(1-\frac3{4x^2}\pm…) $$ where the first two term should already exhaust the given precision.

This confirms the magnitude estimation and gives the next terms for its correction.

Lutz Lehmann
  • 126,666
  • The second computation (and also the first) shows that the difference between $x$ and $\sqrt{x^2+1}$ is of size $1/(2x)$. The difference in magnitude between these terms explains the cancellation. The first formula gives a way to compute the result without cancellation. – Lutz Lehmann Jan 25 '16 at 00:19
  • Thanks so much for your clear response man! – Danxe Jan 25 '16 at 01:06