Exponential function $e^x$ is entire function, meaning it's Taylor series around any point $a$ will converge with infinite radius of convergence. However, rate of convergence will depend on how far $x$ is from $a$. Further it is, slower the convergence is.
The problem is actually evident, no matter how large degree of Taylor polynomial you are using for approximations, no polynomial can approximate exponential function well when $|x|\to\infty$ because of elementary limits $\lim_{x\to\infty}\frac{e^x}{x^n} = \infty$ and $\lim_{x\to -\infty}\frac{x^n}{e^x} = \pm\infty$. Intuitively, and as you probably know, exponential growth is staggeringly faster than polynomial growth.
So, even though it's clear that for higher accuracy of approximation you need Taylor polynomial of higher degree, here we want to closer inspect it's dependance on $x$. For that we can look at Lagrange form of the remainder:
$$e^x = \sum_{k=0}^n\frac{x^k}{k!}+\frac{e^c}{(n+1)!}x^{n+1}$$
for $c$ between $0$ and $x$. Combined with the fact that $e^x$ is strictly increasing, for positive $x$ we get an upper bound on absolute error:
$$\left|e^x - \sum_{k=0}^n\frac{x^k}{k!}\right|\leq\left|\frac{e^x}{(n+1)!}x^{n+1}\right|.$$ Therefore, to guarantee that the absolute error is less than $\varepsilon$, for positive $x$ you need to find $n$ such that $$x^{n+1}e^x < \varepsilon (n+1)!\tag{1}.$$ To get a feel for that, here's a table where $n$ will be the smallest positive integer that satisfies inequality $(1)$ for $\varepsilon = 0.1$ (meaning the absolute error is less than $0.1$) and $m$ will be the smallest positive integer that satisfies $\left|e^x - \sum_{k=0}^n\frac{x^k}{k!}\right| < 0.1,$ i.e. true minimal value for the degree of Taylor polynomial good enough to approximate $e^x$ to the desired accuracy.
\begin{array}{c|c|c}
x & n & m \\ \hline
1 & 4 & 3\\
2 & 7 & 6\\
5 & 17 & 14\\
10 & 35 & 27\\
100 & ? & 273
\end{array}
I couldn't find the value with $?$ due to machine precision issues.
The table tells you, for example, that to estimate $e^5$ with absolute error less than $0.1$, we need Taylor polynomial of degree at least $14$, while Lagrange form of the remainder would tell us that we need at least $17$ to be certain without actually computing.
Of course, if you have keen eye, you will notice the bigger problem with this. To get an upper bound on error for approximating $e^x$ in Lagrange form of the remainder, we need to know $e^x$, or to avoid circularity, upper bound for $e^x$, i.e. $M$ such that $|e^x| \leq M$, so we get the following estimate on absolute error:
$$\left|e^x - \sum_{k=0}^n\frac{x^k}{k!}\right|\leq\left|\frac{e^x}{(n+1)!}x^{n+1}\right|\leq\left|\frac{M}{(n+1)!}x^{n+1}\right|,$$
so instead of $(1)$ we need to first find suitable $M$ and then solve inequality $Mx^{n+1} < \varepsilon (n+1)!$ for $n$. For example, if you are estimating $e^x$ for $x\in [0,1]$, we can pick $M = 3$, since $e < 3$.
All of this tells you that approximating $e^x$ with Taylor series around $0$, although possible, is not practical for $x$ far away from $0$.
e=2.7...
you could splite^a
intoe^{n+b}
where n is the greatest integer smaller than a andb=a-n
. Then usinge^{n+b} = e^n e^b
computee^n = e * e * ... * e
and evaluatee^b
via the Taylor approx. aroundx=0
. – infinitezero Nov 09 '23 at 08:04