I have a function $\frac{e^x - 1}{x}$. In order to avoid loss of significance when calculating values of this function near $x = 0$, I represent $e^x$ as Taylor series. The truncation error of $e^x$ is $\frac{x^5}{5!}*e^x$ (If i use 4 members of Taylor series for the approximation). But this is the error only for $e^x$, not for the whole function. How to compute truncation error for $\frac{e^x - 1}{x}$ when $e^x$ is computed using Taylor series approximation?
Asked
Active
Viewed 522 times
2
1 Answers
2
The Lagrange formula tells you that
$$e^x=\sum_{n=0}^N \frac{x^n}{n!} + \frac{x^{N+1}}{(N+1)!} e^{\xi_N(x)}$$
where $\xi_N(x)$ is between $0$ and $x$. You can then manipulate this expression directly to get
$$\frac{e^x-1}{x}=\sum_{n=0}^{N-1} \frac{x^n}{(n+1)!} + \frac{x^N}{(N+1)!} e^{\xi_N(x)}.$$
Ian
- 101,645
(x==0)?1:expm1(x)/xor(1+x==1)?1:(exp(x)-1)/((1+x)-1)should give correct results for smallx. – Lutz Lehmann Sep 16 '17 at 06:38(1+x)-1the last bit is removed, giving a relative error of $-2^{11}\approx 0.5·10^{-3}$ in the denominator. // Theexpm1expression does not have this problem, so it can be used with both branching variants. – Lutz Lehmann Aug 22 '22 at 10:41