Shared15 - Taylor Series Assignment / Taylor Series Notes.sagewsOpen in CoCalc
This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is

### Prerequisites:

• Intro to Sage
• Series

# Taylor Series

Definition: A power series centered at is a series of the form

where and all the are constants.

Notice that a power series is a function of . The domain is all values of for which the series converges. There is always at least one number in the domain, namely .

You can think of a power series as a polynomial with (possibly) infinite degree.

One of the nice things about power series is that it's easy to differentiate and integrate them. Just like regular polynomials, you can take the derivative or integral of each term first, and then add up the results.

## Example 1

A geometric series with as the common ratio is a simple example of a power series ( and for all ):

We know when this series converges and what it coverges to:

provided that .

So is a function with domain . On this domain, this power series function happens to be equal to the function .

## Taylor Series

This raises the question of whether other functions are equal to the sum of a power series (at least for part of their domains).

In other words, given a function , can we find so that

for some interval of x-values?

This process of representing a function by a power series is called "expanding" the function into a series. The power series you get is called a Taylor series expansion of , after mathematician Brook Taylor (1685-1731).

Expanding functions into Taylor series and differentiating and integrating the series had a number of applications back then. For example, you can use Taylor Series to approximate the values of numbers like and . Or consider the logarithmic and trigonometric functions. These are often difficult to calculate, but if you expand these into Taylor series, then you can approximate values of these functions using only polynomials (and polynomials only require arithmetic to calculate).

Fortunately, finding the right power series to represent a function is fairly straightforward, as long as the function is repeatedly differentiable. The secret is to find derivatives of every order and evaluate them at .

Suppose , take the derivative, and plug in :

For all , , so when you plug in it's still 0.

For all , , with . So when you plug in , you get .

Finally, when , .

Putting this all together, we see that .

Therefore, .

Conclusion: If a function with derivatives of every order may be represented by a power series centered at on some interval , then that power series is

where the series converges on the interval .

Notice the "if" in the last sentence. There are functions that are not equal to the sum of their Taylor series, even if the series converges. We are not going to deal with such functions in this lab.

## Example 2

Find the Taylor series of centered at (Taylor series centered at 0 are also called Maclaurin series).

We know in this case. Since , we have for all .

Thus, .

If equals the sum of its Taylor series, then . For this particular function, the Taylor series converges for all , and does equal the sum of the series (take my word for it).

## Taylor Polynomials

The partial sums of a Taylor series are actual polynomials, called Taylor polynomials. In other words, the Taylor polynomial of degree is .

We can approximate a Taylor series to whatever level of accuracy we want by using a Taylor polynomial of high enough degree.

Note: If , then this polynomial will actually have degree less than .

Notice that the Taylor polynomial of degree 1 is .

Does this look familiar? It should! This is an equation for the tangent line to at . In other words, Taylor polynomials are generalizations of the tangent line to higher degree polynomials.

Also note that the Taylor polynomial of degree 2 is

This is the formula we used for Quadratic Approximation in Calc 1.

## Example 3

We will use Taylor polynomials to approximate the value of . We saw above that .

The Taylor polynomial of degree is .

So . The approximation improves as increases.

If we plug in , we get .

Let's approximate the value of .

%auto
%var n
@interact
def _(m=input_box(1,label='Degree of Taylor polynomial',width=20)):
print "Approximation =",N(sum(1/factorial(n),n,0,m),digits=30)
print "Actual value  =",N(e,digits=30)


How big must be so that our approximation is correct for all the decimal places shown?

Let's look at some graphs.

is plotted in black, along with three Taylor polynomials (blue = degree 2, green = degree 3, red = degree 4)

%var n
plot(sum(x^n/factorial(n),n,0,2),xmin=-1, xmax=1,color='blue',legend_label='degree 2')+plot(sum(x^n/factorial(n),n,0,3),xmin=-1, xmax=1,color='green',legend_label='degree 3')+plot(sum(x^n/factorial(n),n,0,4),xmin=-1, xmax=1,color='red',legend_label='degree 4')+plot(e^x,xmin=-1, xmax=1,ymax=e,color='black',legend_label='$e^x$')


Notice that the higher the degree the better the approximation.

Now try xmin=-10; xmax=10; ymax=1000

%var n
plot(sum(x^n/factorial(n),n,0,2),xmin=-10,xmax=10,color='blue',legend_label='degree 2')+plot(sum(x^n/factorial(n),n,0,3),xmin=-10, xmax=10,color='green',legend_label='degree 3')+plot(sum(x^n/factorial(n),n,0,4),xmin=-10, xmax=10,color='red',legend_label='degree 4')+plot(e^x,xmin=-10, xmax=10,ymax=1000,color='black',legend_label='$e^x$')


Notice that the Taylor polynomials are better approximations the closer you get to the center of the expansion (in this case ), just like the tangent line is a better approximation the closer you get to the point of tangency.

In the animation below, we see taylor polynomials of increasing degree (in blue) plotted with (in black).

%auto
s=[]
taylorpoly=1
p=plot(e^x,-5,15,ymin=-100,ymax=1500,color='black')
for n in [1..10]:
taylorpoly+=x^n/factorial(n)
s+=[p+plot(taylorpoly,-5,15)]
a=animate(s)
show(a,delay=50)


We can use Sage to calculate Taylor polynomials using the "taylor" command. This command takes four arguments: the expression or function to expand, the variable of expansion, the center of the expansion, and the degree of polynomial you want.

## Example 4

Use Sage to find the 10th-degree Taylor polynomial centered at for .

show(taylor(e^x,x,0,10))


## Example 5

Find the 15th-degree Taylor polynomials of centered at , , and .

show(taylor(sin(x),x,0,15))

show(taylor(sin(x),x,-pi,15))

show(taylor(sin(x),x,pi,15))


Notice that some of the coefficients (the ) are 0 in this example.

## Example 6

Find the Taylor polynomials of centered at of degrees 5, 10, and 15.

show(taylor(cos(x),x,0,5))

show(taylor(cos(x),x,0,10))

show(taylor(cos(x),x,0,15))


## Example 7

Find the 10th-degree Taylor polynomial centered at of .

%var c
show(taylor(c/(1-x),x,0,10))


Here's a graph of this one for .

plot(taylor(1/(1-x),x,0,10))+plot(1/(1-x),color='black',ymax=6,ymin=0)