Taylor Series Review

Algebra of Power Series

Clear[f]

Here is a truncated power series. We want to look for patterns in the algebraic manipulation of the two series:

n=5;

s1=(∑_(i=0)^n)(Subscript[a, i])(((x-(Subscript[x, 0])))^i)

s2=(∑_(i=0)^n)(Subscript[b, i])(((x-(Subscript[x, 0])))^i)

Addition

Collect[s1+s2,(x-(Subscript[x, 0]))]

(∑_(n=0)^∞)(Subscript[a, n])(((x-(Subscript[x, 0])))^n)+(∑_(n=0)^∞)(Subscript[b, n])(((x-(Subscript[x, 0])))^n)=(∑_(n=0)^∞)((Subscript[a, n])+(Subscript[b, n]))(((x-(Subscript[x, 0])))^n).

Subtraction

Collect[s1-s2,(x-(Subscript[x, 0]))]

(∑_(n=0)^∞)(Subscript[a, n])(((x-(Subscript[x, 0])))^n)-(∑_(n=0)^∞)(Subscript[b, n])(((x-(Subscript[x, 0])))^n)=(∑_(n=0)^∞)((Subscript[a, n])-(Subscript[b, n]))(((x-(Subscript[x, 0])))^n).

Multiplication

Collect[s1*s2,(x-(Subscript[x, 0]))]

(∑_(n=0)^∞)(Subscript[a, n])(((x-(Subscript[x, 0])))^n)×(∑_(n=0)^∞)(Subscript[b, n])(((x-(Subscript[x, 0])))^n)=(∑_(n=0)^∞)((∑_(k=0)^n)(Subscript[a, k])(Subscript[b, n-k]))(((x-(Subscript[x, 0])))^n).

Our result here is only valid for the terms up to (((x-(Subscript[x, 0])))^5). The higher order terms are missing bits from the infinite series due to our trancating at 5 terms.

Division

(((∑_(n=0)^∞)(Subscript[a, n])(((x-(Subscript[x, 0])))^n))/((∑_(n=0)^∞)(Subscript[b, n])(((x-(Subscript[x, 0])))^n)))=(∑_(n=0)^∞)(Subscript[d, n])(((x-(Subscript[x, 0])))^n).

where the (Subscript[d, n])satisfy the system of equations:

(Subscript[a, n])=(∑_(k=0)^n)(Subscript[d, k])(Subscript[b, n-k])

which can be solved recursively for n=0,1,2,....

Calculus

f(x)=(∑_(n=0)^∞)(Subscript[a, n])(((x-(Subscript[x, 0])))^n).

We can differentiate term-by-term based on Fubini’s Theorem. We will assume the following hold for the types of series we will be working with:

(d/(d x))f(x)=(∑_(n=0)^∞)n (Subscript[a, n])(((x-(Subscript[x, 0])))^(n-1)) =(∑_(n=1)^∞)n (Subscript[a, n])(((x-(Subscript[x, 0])))^(n-1)).

((d^2)/(d (x^2)))f(x)=(∑_(n=0)^∞)n(n-1) (Subscript[a, n])(((x-(Subscript[x, 0])))^(n-2)) =(∑_(n=2)^∞)n (n-1)(Subscript[a, n])(((x-(Subscript[x, 0])))^(n-2)).

∫f(x)dx=(∑_(n=0)^∞)(Subscript[a, n])((((x-(Subscript[x, 0])))^(n+1))/(n+1)).

Taylor Series Basics

Consider the following function, which we wish to generate a series approximation to:

f[x_] = 1/(1+x)

The function has a vertical asymptote at x=-1, so any series solution will have an absolutely convergent region that is constrained by this fact.

The Taylor Series of a function f(x) about x=a is given by the series:

f(x)=(∑_(n=0)^∞)(((f^((n)))(a))/(n!))(((x-a))^n).

To calculate these in general, you need to construct a table of derivatives and search for a pattern. Mathematica can get the first few terms in a series using the command Series. The command Normal strips off the error estimate that is returned by the Series command, creating the Taylor polynomial.

The series about x=0 to order 5 is:

S1[x_] = Normal[Series[f[x],{x,0,5}]]

The series about x=1 to order 5 is:

S2[x_] = Normal[Series[f[x],{x,1,5}]]

Here are plots of the two series and the function f(x):

Plot[{f[x],S1[x],S2[x]},{x,-1,3.5},PlotStyle->{ {Blue,Thick},{Red,Dashed,Thick},{Black,DotDashed,Thick}},PlotRange-> {{-1,3.5},{-1,5}},AxesLabel->{"x","y"},ImageSize->{400,Automatic},BaseStyle->20]

The series will only approximate the function well within the region where it is absolutely convergent. We can show that the series about x=0 is absolutely convergent for -1 ≤ x ≤ 1 (using the ratio test). Examining the graph (red curve and blue curve), we see that the series does not approximate the function outside this region.

The series about x=1 is absolutely convergent in the region -1 ≤ x ≤ 3. We see that it approximates the function over a larger range than the other series. Notice, however, that it does not approximate the function as well for x < 0. We really need to understand where a solution is required when we prepare series approximations.

Adding more terms improves the approximation in the region where it is absolutely convergent. The following graph illustrates this. Notice that the error will always be large outside the region of absolute convergence.

S1b[x_] = Normal[Series[f[x],{x,0,15}]]

Plot[{f[x],S1[x],S1b[x]},{x,-1,1},PlotStyle->{ {Blue,Thick},{Red,Dashed,Thick},{Black,DotDashed,Thick}},PlotRange->{{-1,1}, {-1,10}},AxesLabel->{"x","y"},ImageSize->{400,Automatic},BaseStyle->20]

Plot[{Abs[(f[x]-S1[x])/f[x]],Abs[(f[x]-S1b[x])/f[x]]},{x,-1,1},PlotStyle->{ {Blue,Thick},{Red,Dashed,Thick},{Black,DotDashed,Thick}}, PlotRange->{0,1},AxesLabel->{"x","Error"},ImageSize->{400,Automatic},BaseStyle->20]

Example of Calculating a Taylor Series

Let's look at how we can calculate the Taylor series of y=ln(x+2) about (Subscript[x, 0])=0.

f[x_] = Log[x+2]

Mathematica has a neat command to find the general coefficient in a series, which replaces creating a table and calculating enough derivatives until you can recognize a pattern. Here it is:

SeriesCoefficient[f[x],{x,0,i}]

series[x_,n_]:=Log[2]+(∑_(i=1)^n)(-(((-(1/2)))^i)(1/i))(x^i)

series[x,8]

Plot[{f[x],series[x,8]},{x,0,5},BaseStyle->20]

Mathematica is pretty cool, and it can do some fun things with your Taylor series, like simplify to a Hypergeometric function if n is left as an unspecified constant:

series[x,n]

or even evaluate the sum out to infinity and return our original function:

series[x,∞]

Sweet! Here is the table you would create if you were looking for a pattern (which you did in Calculus II), but Mathematica has already found the pattern for you:

Table[{i,(1/(i!))Derivative[i][f][x],(1/(i!))Derivative[i][f][0]},{i,0,6}]//TableForm

Manipulating Sigma Series Notation

Let's define some coefficients for a series:

Clear[a]
a[n_]:=a[n]=(((((-1))^n)(n+1))/((2n)!))

Relabelling doesn't change the series:

(∑_(n=0)^∞)(Subscript[a, n+2])(x^n)=(∑_(m=2)^∞)(Subscript[a, m])(x^(m-2)) where we let n=m-2

Sum[a[n+2]*(x^n),{n,0,6}]

Sum[a[m]*(x^(m-2)),{m,2,8}]

Taking the first few terms out of the summation doesn't change the series:

(∑_(m=2)^∞)(Subscript[a, m])(x^(m-2)) =(Subscript[a, 2])+(Subscript[a, 3])x+(∑_(m=4)^∞)(Subscript[a, m])(x^(m-2))

a[2]+a[3](x^1)+Sum[a[m]*(x^(m-2)),{m,4,8}]

You can use Mathematica to sum the infinite series and see if it represents a function:

Sum[a[n+2]*(x^n),{n,0,Infinity}]
Sum[a[m]*(x^(m-2)),{m,2,Infinity}]

In Calculus II, you learned how to find the Taylor series for a given function:

Series[((-2+2 x+2 Cos[(Sqrt[x])]-(Sqrt[x]) Sin[(Sqrt[x])])/(2 (x^2))),{x,0,6}]

In Differential Equations, we are interested in finding the function from the series.

Important for DE: Collecting power of x

We will see that when working with power series we will often want to collect powers of x. This requires a multi-step process, which is outlined here. I recommend you use Mathematica’s typesetting power to avoid having to rewrite long equations that have only minimal changes. I use Format > Style > DisplayFormula to typeset equations

Let’s say we want to determine what conditions the (Subscript[a, n]) must satisfy for the following relation to be true for all values of x.

(∑_(n=1)^∞)n (Subscript[a, n]) (x^(n-1))+ x(∑_(n=0)^∞) (Subscript[a, n]) (x^n)=0

We can determine this by collecting powers of x in the following manner.

Step 0: (often not needed) Taylor expand about (Subscript[x, 0]) any function of x not in the summation. Not needed in this example.

Step 1: Multiply through by any x not in the summation.

(∑_(n=1)^∞)n (Subscript[a, n]) (x^(n-1))+ x(∑_(n=0)^∞) (Subscript[a, n]) (x^n)=0
 (∑_(n=1)^∞)n (Subscript[a, n]) (x^(n-1))+ (∑_(n=0)^∞) (Subscript[a, n]) (x^(n+1))=0

Step 2: Relabel to get all terms with an (x^n). Note you can do more than one summation at a time, I am doing them separately to make the process clear here.

(∑_(n=1)^∞)n (Subscript[a, n]) (x^(n-1))+ (∑_(n=0)^∞) (Subscript[a, n]) (x^(n+1))=0 
Let m=n+1 in second sum. When n=0, m=1:
 (∑_(n=1)^∞)n (Subscript[a, n]) (x^(n-1))+ (∑_(m=1)^∞) (Subscript[a, m-1]) (x^m)=0 
Let m=n:
 (∑_(n=1)^∞)n (Subscript[a, n]) (x^(n-1))+ (∑_(n=1)^∞) (Subscript[a, n-1]) (x^n)=0 
Let m=n-1 in first sum. When n=1, m=0:
 (∑_(m=0)^∞)(m+1) (Subscript[a, m+1]) (x^m)+ (∑_(n=1)^∞) (Subscript[a, n-1]) (x^n)=0 
Let m=n:
 (∑_(n=0)^∞)(n+1) (Subscript[a, n+1]) (x^n)+ (∑_(n=1)^∞) (Subscript[a, n-1]) (x^n)=0

Step 3: Start each summation at the same value of n. This entails taking some terms out of the sums that start at a lower value of n.

(∑_(n=0)^∞)(n+1) (Subscript[a, n+1]) (x^n)+ (∑_(n=1)^∞) (Subscript[a, n-1]) (x^n)=0 
(0+1) (Subscript[a, 0+1]) (x^0)+ (∑_(n=1)^∞)(n+1) (Subscript[a, n+1]) (x^n)+ (∑_(n=1)^∞) (Subscript[a, n-1]) (x^n)=0 
(Subscript[a, 1]) (x^0)+ (∑_(n=1)^∞)(n+1) (Subscript[a, n+1]) (x^n)+ (∑_(n=1)^∞) (Subscript[a, n-1]) (x^n)=0

Now, we can collect powers of x.

(Subscript[a, 1]) (x^0)+ (∑_(n=1)^∞)[(n+1) (Subscript[a, n+1])+ (Subscript[a, n-1])] (x^n)=0

For the relationship to be true for all values of x, each coefficient of a power of x must be zero.

(Subscript[a, 1])=0
(n+1) (Subscript[a, n+1])+ (Subscript[a, n-1])=0 for n=1,2,3,4,...