Avoiding catastrophic cancellation with $\sqrt{1+x} - 1$ for $x$ close to $0$

995 Views Asked by At

I'm trying to figure out how to avoid catastrophic cancellation for the following expression $$\sqrt{1+x} - 1$$ for $x$ being a number very close to $0$.

Of course, the answer would come to $0$ unless the expression is changed around.

Any help is appreciated! Thanks!

3

There are 3 best solutions below

0
On

You could use $$\sqrt{1+x}-1=\frac{x}{\sqrt{1+x}+1}$$

0
On

If $x$ is seriously small, e.g. $\ x < 10^{-14}$, and you don't care too much about terms of order $O(10^{-28})$ then why not use:

$$\sqrt{1+x}\approx1+\frac{x}{2}$$

2
On

If you want accurate results without computing any square root, you could use $[n,n]$ Padé approximants.

These could be $$\sqrt{1+x}-1\sim \frac{2 x}{x+4}$$ $$\sqrt{1+x}-1\sim \frac{4 x (x+2)}{x (x+12)+16}$$