I have a doubt about a general situation in where I am asked to calculate $f(x)$ with a certain precision. How can I compute the number of terms of the Taylor polynomial needed for that?

For example if I wanted to calculate $\dfrac{1}{\sqrt e}$ from the function $e^x$ with a precision of $.01$ how can I know how many terms I need? I think it has something to do with Taylor's remainder.

Thanks for your help!


Taylor's Theorem states that if a function is of class $C^{n+1}$ ($n+1$ times continuously differentiable) then the difference between the function and its Taylor Polynomial at some point $x$ will be $$\text{Error}=\frac{f^{(n+1)}(c)}{(n+1)!}(x-a)^{n+1}$$ where $a$ is the center of the Taylor expansion and $c$ is some number $c\in(a,x)$. ($n$ is the degree of the approximation, or $1$ less than the number of terms you have.)

So if you can bound the derivative in that expression, then you can bound the error. In your case, the function is $e^x$. We have $$\frac{d^{n+1}}{dx^{n+1}}e^x=e^x$$ so the derivative, on the interval $(a,b)$, is at most $e^{\max\{a,b\}}$ because $e^x$ is strictly increasing everywhere. In your case $b=-1/2$ so we get $$|\text{Error}|\le \frac{e^0}{(n+1)!}|-1/2-0|^{n+1}=\frac{1}{2^{n+1}(n+1)!}$$ This is an excellent bound. To get $0.01$ precision just take $n$ large enough so that $$\frac{1}{2^{n+1}(n+1)!}\le 0.01$$ (I believe $n=3$ will work)

With $n=3$, we have $$e^{-1/2}\approx 1-{1\over 2}+\frac{1}{2!\cdot 2^2}-\frac{1}{3!\cdot 2^3}=0.604166...$$ The true answer is $0.6065306597126334...$, and the error is about $0.002<0.01$.


For each $n$ you can usually tell whether $n$ terms are enough by computing an upper bound of the remainder. Recall that

$f(x)=\Sigma_{k=0}^nf^{(k)}(x_0)(x-x_0)^k/k! + f^{(n+1)}(x_*)(x-x_0)^{n+1}/(n+1)!$,

where $x_*\in[x_0,x]$.

If you can produce a bound on $f^{(n+1)}(x_*),x_*\in[x_0,x]$ (which is easy enough for convex functions such as $e^x$), then you can pick $n$ where the remainder is below your desired precision threshold.

  • $\begingroup$ So I for example I should take remainder with x = -1/2 since I want to calculate e^-0.5 and start trying for which n the result becomes smaller than what I want? $\endgroup$ – Ruben Apr 21 '14 at 17:49
  • $\begingroup$ yes: you figure out the upper bound for derivatives (say, n-th derivatives in [-0.5,0] has to be smaller than 2), and then pick n such that for x=-0.5 the remainder is below the precision you want. $\endgroup$ – Michael Apr 21 '14 at 18:24

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.