I have make a program in Matlab that calculate $e^{-5}$ using Taylor's series. I have calculated it with two ways first way using the first 10 terms for $x = -5$
$$
e^{-5} = 1 - 5/1! + 5^2/2! - 5^3/3! + ...
$$
and second way using the first 10 terms for $x = 5$
$$
e^5 = 1 + 5/1! + 5^2/2! + 5^3/3! + ...
$$
and then divide the result with $1$ to get $e^{-5}$. I noticed that second way gives more accurate answer than first one. So I would like to ask is it because of the truncation error added from Taylor's series because I use only the first $10$ terms or is it because of the subtraction error added from the floating point system?
2026-03-26 06:27:28.1774506448
Taylor's series error or floating point error?
515 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
1
The largest term in the series for $e^x$ has index $n$ or $n+1$ where $n≤|x|≤n+1$ with value about $\frac{n^n}{n!}∼e^n$ (by Stirling's approximation). For negative arguments, these alternating large numbers have to cancel to get a very small result, you would need many digits of precision in the internal number format to capture both the large and the small numbers with enough remaining digits to get the result in the desired output precision.
Or put another way, if $μ$ ($=2^{-23}$ or $=2^{-53}$) is the machine constant of the floating point number type, the series evaluation of $e^x$ (up to some kind of numerical convergence at a number of $4(1+|x|)+|\log_4(\mu)|$ or so terms) has random floating point error contributions up to size $e^{|x|}μ$, which can be bad for medium to large negative arguments $x$, as the relative error would be of size up to $e^{2|x|}μ$.
Miraculously the errors cancel largely in the computation of $e^{-5}$ giving only an error of
-8.29e-16in the 40 term partial sum. Computation of $1/e^5$ by the same number of terms gives no difference to the FPU result.