2
$\begingroup$

I am a student and I was reading Numerical Analysis by Burden. In one of the exercises, I have to calculate $e^{-5}$ in two ways.

The first is using the Taylor's series for $x=-5$, $( e^{-5} = 1 - 5/1! + 5^2/2!-...)$ and second way is calculating $e^5$ and then $e^{-5}=1/e^5$, again using Taylor's series but this time for $x=5$. In his solution, he says second way gives better results because we avoid subtraction. I think that it has to do with the floating point system but I am not very sure so I thought someone could further explain it to me. (Sorry if I have made any mistakes. English is not my native language)

$\endgroup$
  • $\begingroup$ As Carl Bender famously points out, one of the worst things you can do with a series is sum it. $\endgroup$ – Pseudonym Jan 23 '17 at 1:00
  • 1
    $\begingroup$ This is a pure mathematics question and should have been posted on or migrated to Mathematics. $\endgroup$ – Raphael Mar 12 '17 at 17:57
  • $\begingroup$ $e^{-5}$ is not a good example, because you would get two plausible but different results. I'd choose a negative argument large enough so that the imprecise calculation gives a result outside [0, 1] where the result should be. $\endgroup$ – gnasher729 Jul 10 '17 at 22:13
1
$\begingroup$

Use a spreadsheet and calculate $e^{-100}$ both ways. It will become totally obvious what is going on. "We avoid subtraction" is not the problem. The problem is that you are adding the sum or difference of large numbers, and each large number has a large rounding error. For one method, the rounding error is not large compared to the result. For the other matter, the rounding errors are huge compared to the result.

$\endgroup$
0
$\begingroup$

Once you expand the series for

$$e^{(-x)} $$

you are going to get alternative negative terms as we can see the nth derivative of

$$e^{(-x)} = (-1)^n * e^{(-x)} $$

therefore the author advises to use the other method instead.

$\endgroup$
  • 9
    $\begingroup$ I think the OP's difficulty is with understanding why subtraction can be a problem with floating point accuracy. Briefly: catastrophic cancellation. $\endgroup$ – j_random_hacker Jan 11 '17 at 14:58
  • $\begingroup$ I think I forgot an important note , I will use Taylor's series for n=9 and even tho we have alternating series the numbers we subtract are not close too each other so as far as I know we wont have any rounding erros $\endgroup$ – van Jan 11 '17 at 15:00
  • $\begingroup$ @j_random_hacker sorry for being so late didn't know i have to use @ to notify you ,my difficulty is what you say could you maybe explain me this catastrophic cancellation you mention, thanks a lot for your time $\endgroup$ – van Jan 11 '17 at 20:22
  • 2
    $\begingroup$ @van: Basically, if you subtract 2 floating point numbers that are close enough together that their first, say, 10 bits are equal, then the result has 10 bits less precision than usual. For more detail I suggest googling "catastrophic cancellation" and "subtraction floating point accuracy". $\endgroup$ – j_random_hacker Jan 12 '17 at 9:51

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.