3
$\begingroup$

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!

$\endgroup$
12
$\begingroup$

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

$\endgroup$
5
$\begingroup$

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}$$

$\endgroup$
  • 1
    $\begingroup$ I'd like to point out that these equivalences are with the limit as $x\to0$, not $x\to\infty$ as you might usually expect from $\sim$. $\endgroup$ – Jam Jan 19 at 15:53
  • $\begingroup$ @Jam. I totally agree with you. In the question, it is specified "for $x$ being a number very close to $0$". $\endgroup$ – Claude Leibovici Jan 19 at 16:06
4
$\begingroup$

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}$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.