1

I understand that when subtracting two values that are nearly identical there is a loss of significance. Aside from this however I'm not quite sure how to tell what results in the next largest loss of precision.

For example, here is a problem in my textbook:

f(x) = tan(x) − sin(x)  when x ~ 0

What is the best and worst algorithm for evaluating this out of these three choices:

(a) (1/ cos(x) − 1) sin(x),
(b) (x^3)/2
(c) tan(x)*(sin(x)^2)/(cos(x) + 1).

I understand that when x is close to zero, tan(x) and sin(x) are nearly the same. I don't understand how or why any of these algorithms are better or worse for solving the problem.

In my opinion it seems as though option a will always give the most loss of significance, simply because when x is a small enough number you can have a roundoff error that leads to a dividing by 0 error.

Meanwhile I can't tell what would make for the best algorithm for avoiding loss of significance. Option b and c seem nearly identical to me in terms of loss of significance. How can I know which algorithm gives the better results and know for the future?

Valrok
  • 493

1 Answers1

1

a has a subtraction of two nearly equal quantities, so will suffer from loss of precision. b and c avoid that. To choose between them, you can evaluate the Taylor series and see if either matches better what you want to compute.

Ross Millikan
  • 374,822
  • How would I use the taylor series of each function to determine which one is better? I ran the two functions through wolfram's taylor series calculator, but am not sure how to tell what will be better. – Valrok Feb 01 '15 at 00:27
  • 1
    You compare the Taylor series for $\tan x - \sin x$ to the series for b and c. Do they agree for the same number of terms? – Ross Millikan Feb 01 '15 at 00:28