5
$\begingroup$

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!

  • 0
    There was no complex conjugate. Just saying.2012-08-26
  • 0
    Haha thanks! I edited it, I just meant conjugate2012-08-26
  • 0
    Yes, your answer to (1) is correct.2012-08-26
  • 0
    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.2012-08-26
  • 0
    Is there really a need to do anything in (2)? There is no cancellation to worry about here.2012-08-26
  • 0
    I think there is error, because the magnitude of the first term will be much less than the magnitude of the second term. So, in a computer, it may truncate some digits and ignore the first term. I was thinking of multiplying through by a^2 or something like that but I am still not certain that is the trick I am looking for.2012-08-26
  • 0
    Actually it's the second term that is much less than the first term here. But when the second term is ignored, ignoring that second term does in fact give you a result as accurate as possible to the given number of digits.2012-08-26
  • 0
    Hmm, maybe then I should do the reverse of what I suggested. I am afraid of overflow and would like to prevent it. Perhaps: 1/b*(sqrt(1+b^2/a^2))2012-08-26
  • 0
    Nope - this leaves the problem term ($b^2/a^2$) inside the square root.2012-08-26
  • 0
    Under which values of x do you experience problems in either expressions? I am not aware of the exact value of re-writing the expression in your case. Could you provide an example?2012-08-26

1 Answers 1

3

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.