Taylor Polynomials

Taylor series review

If function f(x) has a power series representation centered at a, then that power series must be the Taylor series centered at a,
	f(x)=(Underoverscript[Σ, (n=0), ∞])(((f^((n)))(a))/(n!))(((x-a))^n)

Question

Let f(x)=sin(x).

What is the Taylor series for f(x) centered at π?

Series[Sin[x],{x,π,10}]

What is its interval of convergence?

We have already seen that the Taylor series for f(x) centered at 0 is sin(x)=(((Underoverscript[Σ, (k=0), ∞])(-1))^k)((x^(2k+1))/((2k+1)!)). Replace x in this with x-π. How do the results of this series compare with the Taylor series for f(x) centered at π?

Series[Sin[x],{x,π,10}]

There is a trigonometric identity that sin(x-π)=-sin(x). What does this mean for the above calculations?

Series[-Sin[x],{x,0,10}]

Tangent line approximation

Question

Given a general function f(x) and value x=a, what is the tangent line approximation of f(x) at a?

Clear[g]
g[a]+g'[a](x-a)

Questions

Let f(x)=cos(x)+sin(2x).

What is an equation of the tangent line to y=f(x) at x=0?

f[x_]:=Cos[x]+Sin[2x]
f[0]+f'[0](x-0)

What is the sum of the linear terms of the series for  cos(x) and sin(2x) at 0?

Series[Cos[x]+Sin[2x],{x,0,1}]

Taylor polynomials

Definition

The (n^th) degree Taylor polynomial of f(x) centered at a is the partial sum of the Taylor series that goes up to and includes the (n^th) power of (x-a). If the Taylor series for f(x) centered at a converges to f(x) for a given value x, then the (n^th) Taylor polynomial of f(x) centered at a provides a polynomial approximation to f(x).

Questions

Let f(x)=cos(x)+sin(2x).

f[x_]:=Cos[x]+Sin[2x]

What is the first degree Taylor polynomial of f(x) centered at 0?

Series[f[x],{x,0,1}]

What is the second degree Taylor polynomial of f(x) centered at 0?

Series[f[x],{x,0,2}]

What is the third degree Taylor polynomial of f(x) centered at 0?

Series[f[x],{x,0,3}]

Plot the graphs of three polynomials along with the graph y=f(x).

p1=Plot[f[x],{x,-2,2},PlotStyle->Black];
p2=Plot[Evaluate[Table[Normal[Series[f[x],{x,0,n}]],{n,3}]],{x,-Pi,Pi}];
Show[p1,p2]

Using the third degree Taylor polynomial of f(x) centered at 0, approximate f(0.5).

Series[f[x],{x,0,3}]
(* I was tempted, but don't be fooled: doesn't satisfy decreasing coefficients in Alternating Series! *)
g[x_]=Normal[Series[f[x],{x,0,3}]]
exact=f[.5]
approx=g[.5]
error=Abs[approx-exact]
TableForm[{{approx},{exact},{error}},TableHeadings->{{"g(.5)","f(.5)","|g(.5)-f(.5)|"},{"f(x) = Cos[x] + Sin[2  x]"}}]

Taylor remainder

If you approximate a quantity, you need some way to analyze how good the approximation is. Consider the error=|approximation-exact|. Here the exact is a given function g(x) and the approximation is the (n^th) degree Taylor polynomial of g(x) centered at a.

Definition

The (n^th) Taylor remainder of g(x) centered at a is

(Subscript[R, n])(x)=g(x)-(Underoverscript[Σ, (k=0), n])(((g^((k)))(a))/(k!))(((x-a))^k)

In other words the error in using the (n^th) degree Taylor polynomial to approximate the function is error=|(Subscript[R, n])(x)|

Analyzing error

The Taylor series error estimate: If |(f^((n+1)))(x)|≤M for all values of x of interest, then

|(Subscript[R, n])(x)|≤(M/((n+1)!))|x-a((|)^(n+1)).

You can think of this roughly as the error on the interval is smaller than the largest "first neglected term" on the interval.

Questions

Let f(x)=(e^(-(x^2))).

What is the Taylor series centered at zero for (e^x)?

Using the Taylor series for (e^x) what is the Taylor series for f(x)?

What is the fourth degree Taylor polynomial for f(x) centered at 0?

nterms=4 (* Why does nothing change if you replace 4 with 5? *)
f[x_]:=E^(-x^2)
Series[f[x],{x,0,nterms}]
sn[x_]=Normal[Series[f[x],{x,0,nterms}]];
Plot[{f[x],sn[x]},{x,-2,2}]
Plot[{f[x],sn[x]},{x,-2,2},Axes->{False,False}]

Using the plot y=|(f^((5)))(x)| below use the Taylor series error estimate the error in approximating f(x) with the (4^th) degree Taylor polynomial

f[x_]:=(E^(-(x^2)));
nterms=4
fp[x_]=D[f[x],{x,nterms+1}]
Plot[Abs[fp[x]],{x,-2,2},PlotRange->All]
g[x_]=Normal[Series[f[x],{x,0,nterms}]];
Plot[{f[x],g[x]},{x,-2,2},PlotLabels->{"f(x)","Taylor Approx"}]
Plot[{Abs[f[x]-g[x]],35/Factorial[nterms+1]Abs[x-0]^(nterms+1)},{x,-2,2},PlotLabels->{"actual error","bound"}]

Questions

Let g(x)=sin(x).

What is the Taylor series centered at zero for g(x)?

What is a simple estimate for M in the remainder for this function? (|(g^((n+1)))(x)|≤M)

What degree Taylor polynomial for g(x) will approximate it with error less than 0.01 for |x|<1?

What degree Taylor polynomial for g(x) will approximate it with error less than 0.01 for |x|<2?

What degree Taylor polynomial for g(x) will approximate it with error less than 0.01 for |x|<3?

nterms=3 (* Why does nothing change if you replace 3 with 4? *)
f[x_]:=Sin[x]
Series[f[x],{x,0,nterms}]
sn[x_]=Normal[Series[f[x],{x,0,nterms}]];
Plot[{f[x],sn[x]},{x,-3,3}]
Plot[{f[x]-sn[x]},{x,-3,3}]

Questions

Let h(x)=ln(x).

What is the Taylor series centered at 1 for h(x)?

What is the interval of convergence for that Taylor series?

What is true about any estimate for M in the remainder for this function for the values of x in the interval of convergence?

What if we use the (5^th) degree Taylor polynomial, (Subscript[T, 5])(x), centered at 1 to approximate h(x) for |x-1|≤0.5? What is a good estimate for M?

Approximate ln(1.5) with (Subscript[T, 5])(1.5). What is an estimate of the error in this approximation?

nterms=5
f[x_]:=Log[x]
Series[f[x],{x,1,nterms}]
sn[x_]=Normal[Series[f[x],{x,1,nterms}]];
Plot[{f[x],sn[x]},{x,0.2,1.8}]
Plot[{f[x]-sn[x]},{x,0.2,1.8},PlotLabel->"Absolute Error"]

Questions

Let f(x)=(e^x).

What is the Taylor series centered at zero for (e^x)?

If we plan to use an (n^th) degree Taylor polynomial, (Subscript[T, n])(x), to approximate f(x) for -1≤x≤1, what is an estimate for M?

Find a value of n so that (Subscript[T, n])(x) approximates f(x) with error less than 0.0001 for all x with |x|≤1.

nterms=5
f[x_]:=Exp[x]
Series[f[x],{x,0,nterms}]
sn[x_]=Normal[Series[f[x],{x,0,nterms}]];
Plot[{f[x],sn[x]},{x,-1,1}]
Plot[{f[x]-sn[x]},{x,-1,1},PlotLabel->"Absolute Error"]