In this post, I want to have a look at a really neat part of calculus, Taylor series. It’s essentially a process you can use to approximate some graph, e.g. ex, using a polynomial – the idea is, the higher order the polynomial, the more accurate the approximation gets.

Let’s dive in! (This gets a bit tricky)

How does it work? First, some terminology – the first order approximation is a linear approximation (so ax+b), second order is quadratic (ax2 + bx + c), and so on. So let’s start with a first order approximation of, say, ex.

e^x
A graph of ex

The first thing to do is to decide at what point we want to approximate it – so let’s pick x=0, as it’s simple. Obviously, the easiest way to approximate the function at x=0 is to make sure it takes the same value as ex there, so the graphs intersect at that point. e0=1, so our approximation must pass through (0,1). So our first order approximation looks like ax+1. Let’s choose a random value of a (e.g. 2), and see how it looks.

e^xfirst
A graph of ex and 2x+1

The slope is obviously not very accurate, but how do we find a better gradient for our first order approximation? Well, gradients are essentially derivatives – so what if we make the derivative of our first order approximation equal to the derivative of ex?

(ex)’ = ex, e0=1

So the derivative of ex at x=0 is 1. This means we want the gradient of our approximation to also be 1, so our approximation is x+1. Let’s try that out:

e^xfirstorderapprox
First order approximation x+1

This is, as it turns out, the best first order approximation for this function. The next step is to make a second order approximation, ax2 + bx + c. We start the same way:

e0=a(0)2 + b(0) + c, so c=1

Then we make their derivatives equal, so they are generally heading in the same direction:

e0=2a(0) + b, b=1

Then the natural next step is to make their second derivatives equal:

e0=2a, a=1/2

And in general, to approximate some function f(x) around x=0, the nth order approximation pn(x) has to fit these rules:

f(0) = pn(0)

f'(0) = pn‘(0)

f”(0) = pn”(0)

f(n)(0) = pn(n)(0)

So all the derivatives match up. If you think about it, this makes sense – not only are the functions equal at 0, but they are also heading in the same direction, and the rate of change of direction is the same, and so on down the line – this isn’t a rigorous explanation of why this works, but for a lot of graphs, the further you go down this line, the closer the approximation gets.

ex-legend

 

ex-graph
The first few approximations of ex

Is this a Taylor series?

No, not yet. There are a few more steps that make this a Taylor series. First of all, what we’ve found are the Maclaurin Polynomials, the series of polynomials that give better and better approximations of our function. If we take this polynomial to infinity, we get the Maclaurin Series, which is no longer an approximation, at least in the case of ex; for some functions at least, it is exactly that function. For other functions, it is exact over a small range (for example, hyperbolas), while for still other functions it is only exact at the point x=0. Take this graph,e-1/x2.

noMac.png
This graph can’t be approximated with a Maclaurin Polynomial

Trying to find the Maclaurin series, you will quickly find that it tells you all the gradients of this function at 0 are 0, so the best you will get is the line y=0. To remedy this, you can approximate the function at a point other than 0. This generalised series, where you take an approximation at x=a towards infinite accuracy, is the Taylor Series. This is the general formula:

Taylor series = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n

It isn’t necessary to understand this, but it’s the fully fleshed out formula.

What’s the outcome of this?

If you can’t be bothered trying to follow that mess of an explanation, the ultimate result you need to understand is that for some nice functions, e.g. exponentials, and some trig functions, there is a way of representing them as a polynomial of infinite order. For example, 1/1-x = 1 + x + x2 + x3 + x4 + … and so on.

What is this good for?

Taylor Series have one big advantage – they take functions that are sometimes hard to work with, like exponentials or trig functions, and turn them into polynomials, which are often much more convenient. How are they more convenient? Well, let’s try differentiating ex. We can try from first principles:

\frac{d}{dx}e^x=\lim_{h \to 0} \frac{e^{x+h}-e^x}{h}

but this doesn’t really get us anwhere. However, when we turn it into an infinite polynomial:

e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + ...

If we differentiate this term by term:

\frac{d}{dx}e^x = 0 + 1 + x + \frac{x^2}{2!} + ... = e^x

We end up with in the same place we started. We can do similar manipulations to show the derivative of sin(x) is cos(x), and the derivative of cos(x) is -sin(x).

sin(x) = x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+...

cos(x) = 1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}+...

Is that all?

Not quite. Let’s look at a slight variation of ex, eix, where i=\sqrt{-1}. Then the expansion looks like this:

e^{ix} = 1 + ix + \frac{i^2x^2}{2!} + \frac{i^3x^3}{3!} + ...

But we know that we can replace the powers of i, because i=\sqrt{-1}, so:

e^{ix} = 1 + ix - \frac{x^2}{2!} - \frac{ix^3}{3!} + \frac{x^4}{4!} ...

If we split this into the terms that have i, and the terms that don’t:

e^{ix} = (1- \frac{x^2}{2!}+ \frac{x^4}{4!}-...) + i(x  - \frac{x^3}{3!}+\frac{x^5}{5!}-  ...)

Don’t these two new infinite series look familiar? As it happens, they are the Taylor expansions of cos(x) and sin(x), so:

e^{ix} = cos(x) + isin(x)

This formula is called Euler’s formula. Now, if we substitute in π as x:

e^{i\pi} = cos(\pi) + isin(\pi) = -1

e^{i\pi}+1=0

This little relationship is Euler’s identity, and is considered to be one of the most beautiful and fundamental connections in mathematics.

Advertisements