0

How could the function $$f(x)=\frac{\sin x}{(x^2+1)^{1/2}-1}$$ be computed to avoid loss of significance?

I know that $$f(x)=\frac{\sin x((x^2+1)^{1/2}+1)}{x^2}$$ But $x^2$ has a problem.... How to solve this problem??

asfajaf
  • 175
  • 1
    What do you mean by "loss of significance" (maybe "indeterminate form"? That's a wild guess.)? At what point do you want to evaluate the function Again, a guess... $0$?) – Clement C. Apr 22 '16 at 13:06
  • If we compute the function f(x) near 0, then original form f(x)'s error is big. Thus, I want to change f(x)'s form. – asfajaf Apr 22 '16 at 13:13
  • How do you define the error in this case -- are you tying it to a particular representation system (IEEE something)? How do you "compute" the function, for a start? (also, note that $\lvert f(x)\rvert \xrightarrow[x\to 0]{} \infty$: you cannot get a bounded absolute error in any floating-point representation system, I believe the best you can aim for is a good relative error) – Clement C. Apr 22 '16 at 13:16
  • Yes. The error means relative error. – asfajaf Apr 22 '16 at 13:17
  • What do you mean by "$x^2$ has a problem", then? Is $x$ so small that you're worried about $x^2$ underflowing? – hmakholm left over Monica Apr 22 '16 at 13:18
  • Right.. I want to miss "denominator is 0" situation. – asfajaf Apr 22 '16 at 13:19
  • Possible idea: you have $f(x) = \frac{2}{x} + \frac{x}{6} + o(x^2)$ around $0$, and computing instead $g(x)= \frac{2}{x} + \frac{x}{6}$ the ratio $f(x)/g(x)$ is $1 - o(x^3)$ (actually, even $1+O(x^4)$. Would that be good for you? (But you still have to compute a quantity that blows to $\infty$.... since you want to approximate a function that does.) – Clement C. Apr 22 '16 at 13:20
  • This problem cannot use series ... – asfajaf Apr 22 '16 at 13:22
  • 1
    OK, then I give up. (I cannot understand what you can, cannot do, allow, do not allow, and aim at achieving in the end; and I am not even clear on the computation model you want to work in...) – Clement C. Apr 22 '16 at 13:24

1 Answers1

2

The main problem with the original form seems to be the subtractive cancellation in the denominator. This goes away when you rewrite to $$ f(x) = \frac{(\sin x)(\sqrt{x^2+1}+1)}{x^2} $$ You may still have a problem in the denominator if $x$ can be so small that $x^2$ underflows -- but it would seem that this could be taken care of by $$ f(x) = \frac{\sin x}{x} \cdot \frac{\sqrt{x^2+1}+1}{x} $$

  • How to compute right term? – asfajaf Apr 22 '16 at 13:21
  • @asfajaf: You mean the right factor? I don't see there's a problem there. If $x\approx 0$ then the numerator collapses nice and smoothly into $\sqrt{1}+1=2$ -- but that only happens when the true value would round to $2$ anyway, so it will contribute no relative error to speak of. – hmakholm left over Monica Apr 22 '16 at 13:24