### Building a series representation of a function

Note: this section makes heavy use of differential calculus.

Taylor series are infinite series of a particular type. They are extremely important in practical mathematics. Very often we are faced with using functions that aren't that easy to use, like exponential and logarithmic functions, or trigonometric functions, or tricky combinations of those, and life gets much simpler if we can replace them with something that's easier to work with.

Taylor series are polynomial series that can be used to approximate other functions, in most cases to arbitrary precision, as long as we're willing to use terms of high-enough degree. They aren't difficult to come up with, either – you'll see.

We'll start by reviewing linear approximations of functions.

### Linear approximations – a review

We showed that the linear approximation of a function f near a point x = a in its domain is

.

Let's just review how that was derived. Look at the figure below. It shows a function, f(x), and its linear approximation, L(x) near the point (a, f(a)). Remember that any function, when we view it closely enough, looks approximately linear. We can approximate a curve in the region around a point, a, in its domain by a line that has the same slope as the curve at x = a, and is tangent to f(x) there, too. Using the approximation, we can estimate values of the function in the domain around x = a.

Here's how we derive L(x). Start with the linear equation y = mx + b, and plug in the slope and the y-intercept.

Notice that f'(a) is the slope of f(x) at x = a, and f(a) - f'(a)·a is just b = y - mx, the y-intercept. Substituting the quantities in blue into the linear equation y = mx + b and rearranging, we get:

There are two features of linear approximation that we will use in developing even better polynomial approximations of functions. They are

1. The first derivative of the function and its approximation must be the same at x = a: L(a) = f(a), and
2. The value of the function and the value of the approximation must be the same at x = a, where a is the point around which we build our approximation: L'(a) = f'(a).

In what follows, we'll further insist that all derivatives of the function and its approximation must be the same at x = a. It's all in the green box below.

#### Linear approximations

The linear approximation of a function f(x) near x = a (left), and for x = 0 (right)

### Example: Approximation of f(x) = cos(x)

Take a look at the plot of f(x) = cos(x) below (thick black curve). Superimposed on it are the graphs of three successively better approximations, each centered around x = 0. They are linear, quadratic and quartic approximations.

Notice that we haven't included any odd polynomial terms* in this approximation because cos(x) is an even function (symmetric across the x-axis). As you learn how to generate Taylor series, you'll find that those missing terms will naturally just drop out. If our example was the sine function, only polynomial terms of odd degree would appear.

The red line is our familiar linear approximation. It has the same value and slope as cos(x) at x = 0. It's also not a very good approximation of the cosine function in this region because cos(x) is very curvy there.

The magenta approximation includes a quadratic term or "correction" to the linear approximation with the same curvature as cos(x). It bends the linear approximation downward like the cosine function. It's better, but it isn't perfect; you can see how it bends away from the cosine curve as we move away from x = 0 in either direction.

Finally, the dashed green curve includes a quartic term, and clearly it matches cos(x) quite well over the region shown, even relatively far from x = 0.

*Remember that odd means f(-x) = -f(x) and even means f(-x) = f(x), which is just saying that there's symmetry across the y-axis.

### How it's done

In the linear approximation, we made the assumptions that the value of the approximation and its slope should be the same at the point x = a. That just makes sense.

Well, we can generalize that kind of thinking to higher derivatives. It's also a reasonable goal to expect the curvature of a better approximation to match the curvature of the function we're trying to approximate.

If the curvature of f(x) is concave-downward, then our approximation should be, too. And that means that both the function and the approximation should have the same second derivative.

We might also insist that the change in curvature (the third derivative) be the same ... and so on.

#### Requirements for a good polynomial approximation near x = a

In order for a polynomial function P(x) to be a good approximation of a function f(x),

1. The value of the approximation must be the same as the value of the function at x = a: P(a) = f(a)
2. The slope of the approximation must be the same as the slope of the function at x = a: P'(a) = f'(a)
3. The curvature of the approximation must be the same as the curvature of the function at x = a: P''(a) = f''(a)
4. ... and so on. Each successive derivative of the approximation and the function at x = a must be equal: P(n)(a) = f(n)(a)

### Example: Finding a series approximation of   f(x) = ex

Let's explore the derivation of a Taylor-series approximation of a function by making a polynomial approximation of the exponential function,

.

Our approximation will take the form of a 5th degree polynomial with unknown coefficients. I've chosen five terms because it's enough to show that important patterns emerge, but there's nothing special about 5. It looks like this:

Now we said above that the function and all of its derivatives have to be the equal at the point in which we're interested. We'll center this approximation about x = 0 for convenience. Here are the derivatives of the function, those derivatives evaluated at x = 0, and the corresponding derivatives of our approximation, g(x).

#### A note on derivative notation

We often write the first, second and third derivatives of a function f(x) as f'(x), f''(x) and f'''(x), but writing all those primes gets tedious for higher derivatives, so we write f(4)(x) for the fourth derivative, f(5)(x) for the fifth, and so on.

Now if we equate g(0) = f(0), g'(0) = f'(0), and so on, we can solve for the coefficients, A, B, C, D & E, of our polynomial, g(x).

The resulting polynomial, just a sum of these terms, looks like this:

Now if we recognize some patterns, including that the factorial function is hidden in those denominators [recall that n! = n(n-1)(n-2) ... 3·2·1, and 0! = 1].

This pattern will continue indefinitely, and we can write the series approximation in shorthand like this:

We can use this sum with x = 1 to estimate the value of e = e1. Here's a table from a spreadsheet. Each row represents one more term added to the series. Notice that each successive term adds a smaller number onto the sum. This series is said to converge to a limit of ex.

The table shows successive values of n, n! and 1/n! used in the series approximation of ex. Notice that each new term is smaller than the previous one. That is, the size of the next term is decreasing.

As terms are added to our series approximation of ex, terms nearest the decimal point begin to be fixed and no longer change (green). This is called convergence, and we say that the series is converging to the number e. If more precision is required, we just add more terms to the series.

For more on the transcendental number e, the base of all continuously-growing exponential functions, you might want to check out the exponential functions section.

Animation: Here is an animation of the first few terms of the series we just derived, centered at x = 0. This animation may not show up too well on a smaller device like a phone. I'm working on that, so stand by.

### A general formula for Taylor series centered on x = 0

If we go back to our derivation of the series approximation of f(x) = ex, we can see that a general formula for the series approximation of any differentiable function centered around x = 0 is:

Here f(n)(0) is the nth derivative of f(x) evaluated at x = 0. In the special case where x = 0, the Taylor series is called a MacLaurin series.

#### The MacLaurin Series

The MacLaurin series is a Taylor series approximation of a function f(x) centered at x = 0. f(n)(0) are the nth derivatives of f(x) evaluated at x = 0.

### Taylor series not centered at x = 0

If we choose to center our approximation at some other point, x = a, in the domain of f(x), then any value we calculate from the approximation will be at (x - a), and we just evaluate the derivatives at x = a. The generalized Taylor series looks like this:

Notice that if a = 0, we just end up with the MacLaurin series formula.

### Example 2

#### Derive the Taylor series approximation of f(x) = sin(x) near x = 0.

Because this approximation will be centered at x = 0, it's a MacLaurin series.

To stay organized, try making yourself a table of derivatives, derivatives evaluated at x = 0, and terms of the series.

Be on the lookout for patterns as you calculate the terms of the series. Looking at the right column of the table it's pretty obvious that terms with even powers of x drop out because the derivative is zero. It also appears that the sign of each term alternates between positive and negative.

If we write the remaining terms out, we can speculate (intelligently) on further terms, such as the last term (red) below:

Finally, we should try to capture that series of terms in compact summation notation. We try always to start the index, n, at zero, but sometimes it just isn't convenient. It works fine here, though. The alternating sign is represented by (-1)n, giving us 1 for n = 0, -1 for n = 1, and so on. The exponent and factorial terms are 2n+1 and (2n+1)! to ensure only odd numbers.

### Example 3

#### Find the Taylor series approximation of f(x) = ln(x) near x = 1

Notice that this is a general Taylor series, not a MacLaurin series.

First, organize and set up a table of f(n)(x), f(n)(1) and the terms of the series (right).

Notice that in this example we've centered the approximation on x = 1 because ln(x) is not defined at x = 0.

You might need to take a minute to work out those derivatives for yourself, but they're correct. The first term of the series vanishes but the successive terms are quite predictable and alternate sign, + - + -.

The terms of the series are summed below. Try to notice the patterns and ask how you might extend the series by one or two more terms.

Now notice that the numerators of the fractions of each term are the factorials 0!, 1!, 2!, ... :

If we use the definition of factorials, e.g. 3! = 3 · 2 · 1, it's easy to see how the factorial ratios above can be reduced, like this:

So we can rewrite our series in its simplest form:

Finally, write the summation notation. It's easier, in this case, to start with n = 1 in the sum, and the (-1)n+1 term provides the right alternation of sign. You'll have to do set up these summations with a fair bit of trial and error before you develop some intuition for it. Don't worry – it'll happen with some practice.

xaktly.com by Dr. Jeff Cruzan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. © 2012, Jeff Cruzan. All text and images on this website not specifically attributed to another source were created by me and I reserve all rights as to their use. Any opinions expressed on this website are entirely mine, and do not necessarily reflect the views of any of my employers. Please feel free to send any questions or comments to jeff.cruzan@verizon.net.