# Numerical Analysis

I am trying to determine some numerical difficulties that arise from a couple problems, and a good way to re-write them to avoid those errors.

For instance, I have:

1) $\sqrt{x+\dfrac{1}{x}} - \sqrt{x-\dfrac{1}{x}}$ where $x\gg 1$

I think that since these two terms approximately equal each other, there will be cancellation error. So I multiplied the numerator and denominator by the conjugate yielding:

$\dfrac{\dfrac{2}{x}}{\sqrt{x+\dfrac{1}{x}}+\sqrt{x-\dfrac{1}{x}}}$

I think that this should get rid of the cancellation error, does anyone see anything wrong with this attempt?

If this looks right, then I will show my attempt on the second problem, but I hope to verify my method first.

2) $\sqrt{\dfrac{1}{a^2}+\dfrac{1}{b^2}}$ where $a\approx 0$ and $b\approx 1$

Thanks!

-
There was no complex conjugate. Just saying. – VF1 Aug 26 '12 at 20:33
Haha thanks! I edited it, I just meant conjugate – Samuel Gregory Aug 26 '12 at 20:34
Yes, your answer to (1) is correct. – Robert Israel Aug 26 '12 at 21:14
I don't see a way to do 2) in the same way. There is not a conjugate of it that would make things disappear. – Samuel Gregory Aug 26 '12 at 21:16
Is there really a need to do anything in (2)? There is no cancellation to worry about here. – Robert Israel Aug 26 '12 at 21:41

For 1, you have successfully avoided the cancellation. If you want, you could go to $$\frac {\frac 2x}{\sqrt x (\sqrt{1+\frac 1{x^2} }+\sqrt{1-\frac 1{x^2} })}=\frac 2{x^{\frac 32} (\sqrt{1+\frac 1{x^2} }+\sqrt{1-\frac 1{x^2} })}\approx x^{-\frac 32}$$ but I am not sure that is an improvement.
For 2, you could have $\frac 1{a^2}$ overflow where $\frac 1a$ does not. To avoid this, you could rewrite it as $\frac 1a \sqrt {1+\frac {a^2}{b^2}}$. That still squares $a$, but if it underflows maybe it gets set to zero and you are OK.