πŸ“ Taylor Series


There are a lot of mathematical functions out there that are very nasty to work with. However there are very nice ones too! An example of the well behaved functions are the polynomial functions. They have well defined derivatives, integrals and are in general easy to work with as they have extensive mathematical tooling.

Now luckily there is a very handy trick to approximate nasty functions as polynomials! The most famous of those is the Taylor series1. The basic idea is that most functions (there are some constraints) can be approximated at a given point using polynomials so that the approximation is close to the function around that point.

To model the β€œcloseness around a given point” the Taylor series forces the derivatives of the functions to be equal. That means when we want to approximate a given function f(x)f(x) using g(x)g(x), such that around a given point aa we get f(a+x)β‰ˆg(a+x)f(a+x)\approx g(a+x).

Let’s say we want to approximate the following function f(x)=0.03x3βˆ’0.2x2+0.5+sin(4x)f(x)=0.03x^3 - 0.2x^2 + 0.5 + sin(4x) around x=1x=1. We can do this using a Taylor series of degree 2 as shown in the plot below.

The function is quite well approximated around x=1x=1 (however if you stray too far off it explodes… Well I said approximated around that point!)

So how is that approximation calculated? The basic idea is that we assume a given function can be approximated around point aa using polynomials. So

f(x)β‰ˆg(x)=βˆ‘ncn(xβˆ’a)nf(x) \approx g(x) = \sum_n c_n (x-a)^n

The xβˆ’ax-a tells us how much we deviate from the point we want to approximate. Our condition is, that we want to approximate the function around x=ax=a with the extra condition of it being exact at f(a)=g(a)f(a) = g(a).

With that in place we can start to calculate all the coefficients! First we use f(a)=g(a)f(a) = g(a) to calculate the first one:

f(a)=g(a)f(a) = g(a)

f(a)=βˆ‘ncn(xβˆ’a)nf(a) = \sum_n c_n (x-a)^n

as xβˆ’ax-a is 00 for if x=ax=a almost all terms vanish and we get:

f(a)=c0f(a) = c_0

So how do we get the other terms? We use a little trick and derive the function! As before we want the function to be exact at x=ax=a, so we can say:

fβ€²(a)=gβ€²(a)f'(a) = g'(a)

fβ€²(a)=ddxβˆ‘ncn(xβˆ’a)nf'(a) = \frac{d}{dx}\sum_n c_n (x-a)^n

fβ€²(a)=c1f'(a) = c_1

And with that little trick we can calculate all other coefficients. For example the next one would be

fβ€²β€²(a)=gβ€²(a)f''(a) = g'(a)

fβ€²β€²(a)=d2d2xβˆ‘ncn(xβˆ’a)nf''(a) = \frac{d^2}{d^2x}\sum_n c_n (x-a)^n

fβ€²β€²(a)=2c2f''(a) = 2c_2

fβ€²β€²(a)2=c2\frac{f''(a)}{2} = c_2

Usually the first couple of coefficients are enough to approximate the target function sufficiently.

For the function from above the first four approximations look as follows:

Sources and Annotations

Footnotes

  1. Wikipedia contributors. (2025, March 11). Taylor series. In Wikipedia, The Free Encyclopedia. Retrieved 03:50, April 12, 2025, from https://en.wikipedia.org/w/index.php?title=Taylor_series&oldid=1279861417 ↩