HomeProjectsBlogAbout

Maclaurin and Taylor Series

December 25, 2019
Maclaurin and Taylor Series

Consider an unknown function f(x)f(x). How can one approximate f(x)f(x) if (s)he know the information of the function f(x)f(x), such as derivaties, at a certain xx, e.g. x=0x=0?

Maclaurin Series

One way is to use a polynomial with infinitely many terms p0(x)=a0+a1x+a2x2+p_0(x) = a_0 + a_1 x + a_2 x^2 + \dots using f(x)f(x)'s information around x=0x=0. The idea is that each term in the polynomial approximates a certain aspect of f(x)f(x):

  • The first term govern p0(x)p_0(x) such that p(0)=f(0)p(0) = f(0);
  • The second term govern p0(x)p_0(x) such that p(0)=f(0)p'(0) = f'(0);
  • The nn-th term should govern p0(x)p_0(x) such that p(n)(0)=f(n)(0)p^{(n)}(0) = f^{(n)}(0).

Consider the nn-th term in p(x)p(x). From the construction, this term allows p(n)(0)=f(n)(0)p^{(n)}(0) = f^{(n)}(0), hence

p(i)(0)=n(n1)(n2)(1)derivative coefficients(an)=f(n)(0).\begin{aligned} p^{(i)}(0) &= \underbrace{n(n-1)(n-2)\cdots(1)}_{\text{derivative coefficients}} (a_n) \\ &= f^{(n)}(0). \end{aligned}

The equation above suggests that an=f(n)(0)n!a_n = \frac{f^{(n)}(0)}{n!}. In principle, we can use infinitely many terms, i.e. nn \rightarrow \infty, yielding a series:

p0(x)=n=0f(n)(0)n!xn,p_0(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(0)}{n!}x^n,

which is called Maclaurin series.

Example

Considier x3x2x+1x^{​3}-x^{​2}-​x+1. Let p0n(x)p_0^n(x) be the polynomial approximation upto degree jj:

p0(j)(x)=n=0jf(n)(0)n!xn+O(xj+1)error.p_0^{(j)}(x) = \sum_{n=0}^{j} \frac{f^{(n)}(0)}{n!} x^n + \underbrace{O(x^{j+1})}_{\text{error}}.

The equation above tells us that we will make some error O(xj+1)O(x^{j+1}) when we use only the first j+1 term approximation; thus, this technique gives accurate approximation only in a region near x=0x=0.


Taylor Series

In general, one might have information at a particular point x0x \ne 0, i.e x=cx=c for cRc \in \mathbb{R}. Using the same derivation as x=0x=0, the polynomial approximation at x=cx=c is

pc(x)=n=0f(n)(c)n!(xc)n.p_c(x) = \sum_{n=0}^\infty \frac{f^{(n)}(c)}{n!}(x-c)^n.

This is the Taylor series, a generalized version of the Maclaurin series into any arbitary xx. In essence, this means we do local expansion around x=cx=c: the farther we are away from cc the larger approximation error we get.

Conclusion

In this article, I have discussed the origin and the idea behind the Maclaurin and Taylor series. The Taylor series itself is a foundation in optimization and machine learning.

If you are would like to explore these two series on different functions, you might be interested in looking at my Colab notebook, which I used it to make the two figures for this article.