Taylor Series
A Taylor Series is an expansion of a function into an infinite sum of terms, like these ones:
Taylor Series expansion | As Sigma Notation |
(There are many more)
Approximations
You can use the first few terms of a Taylor Series to get an approximate value for a function.
Here we show better and better approximations for cos(x). The red line is cos(x), the blue is the approximation (try plotting it yourself) :
1 − x^{2}/2! | |
1 − x^{2}/2! + x^{4}/4! | |
1 − x^{2}/2! + x^{4}/4! − x^{6}/6! | |
1 − x^{2}/2! + x^{4}/4! − x^{6}/6! + x^{8}/8! |
(You can also see the Taylor Series in action at Euler's Formula for Complex Numbers.)
What is this Magic?
How can you turn a function into a series of power terms like this?
Well, it isn't really magic. First you say you want to have this:
f(x) = c_{0} + c_{1}(x-a) + c_{2}(x-a)^{2} + c_{3}(x-a)^{3} + ...
Then choose a value "a", and work out the values c_{0} , c_{1} , c_{2} , ... etc
It is done using derivatives ...
Quick review: a derivative gives you the slope of a function at any point.
You must know the derivatives of your function f(x) and these basic derivative rules :
- The derivative of a constant is 0
- The derivative of x is 1
- The derivative of x^{n} is nx^{n-1} (Example: the derivative of x^{3} is 3x^{2})
We will use the little mark ’ to mean "derivative of".
OK, let's start:
To get c_{0}, choose x=a so all the (x-a) terms become zero, leaving you with:
f(a) = c_{0}
So c_{0} = f(a)
To get c_{1}, take the derivative of f(x):
f’(x) = c_{1} + 2c_{2}(x-a) + 3c_{3}(x-a)^{2} + ...
With x=a all the (x-a) terms become zero:
f’(a) = c_{1}
So c_{1} = f’(a)
To get c_{2}, do the derivative again:
f’’(x) = 2c_{2} + 3×2×c_{3}(x-a) + ...
With x=a all the (x-a) terms become zero:
f’’(a) = 2c_{2}
So c_{2} = f’’(a)/2
In fact, a pattern is emerging. Each term is
- the next higher derivative ...
- ... divided by all the exponents so far multiplied together (for which we can use factorial notation, for example 3! = 3×2×1)
And we get:
Now we have a way of finding our own Taylor Series: keep taking derivatives and divide by n! each time.
Example: Taylor Series for cos(x)
And all we need to know is:
- The derivative of cos(x) is -sin(x)
- The derivative of sin(x) is cos(x)
Choose a=0:
- c_{0} = f(0) = cos(0) = 1
- c_{1} = f'(0)/1! = -sin(0) = 0
- c_{2} = f''(0)/2! = -cos(0)/2! = -1/2!
- c_{3} = f'''(0)/3! = sin(0)/3! = 0
- c_{4} = f''''(0)/4! = cos(0)/4! = 1/4!
- etc...
The odd terms are all zero, so we get:
cos(x) = 1 − x^{2}/2! + x^{4}/4! − ...
Try that for sin(x) yourself, it will help you to learn.
Or try it on another function of your choosing. The key thing is that you be able to take derivatives of your function f(x).
Note: A Maclaurin Series is a Taylor Series where a=0, so all the examples we have been using so far can also be called Maclaurin Series.