Taylor Remainder

MAT 229, Spring 2021

Week 8

Supporting materials

If you wish to get a different perspective on the notes below, try either of the following textbook sections.

Stewart’s Calculus
	11.11: Taylor Polynomials

Boelkins/Austin/Schlicker’s Active Calculus
	8.5 Taylor Polynomials and Taylor Series

Error

In numerical approximation, we had error estimates that gave us information on how good our estimates are.
	absolute error=|exact-approximation|.
Being able to estimate this error is vital when we have no way to get the exact value. Even more, we were able to use the error estimates to determine the n-value needed to make sure our estimate was within some prescribed error.

Now we are approximating function values f(x) with the Taylor polynomial for f. A couple of questions we want to address:

How good is the approximation?

If we want our approximation to be within a prescribed error, what degree do we need for the approximating Taylor polynomial? We presume that, the higher degree of the polynomial approximation, the better the approximation.

Taylor remainder

Definition

The (n^th) Taylor remainder of g(x) centered at a is difference in g(x) with its (n^th) degree Taylor polynomial centered at a, (Subscript[T, n])(x).
	(Subscript[R, n])(x)=g(x)-(Subscript[T, 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 |(g^((n+1)))(x)|≤M for all values of x of interest, then |(Subscript[R, n])(x)|≤(M/((n+1)!))|x-a((|)^(n+1)).

Questions

Let g(x)=sin(x), -π/2≤x≤π/2.

What is the (3^th) degree Taylor polynomial centered at zero for g(x), (Subscript[T, 3])(x)? (Video)

(* This function will generate the nth Taylor polynomial to f at x=a: *)
taylor[f_,a_,n_]:=
Sum[
(D[f[x],{x,k}]/. x->a)/k!
(x-a)^k,
{k,0,n}]

Do you see how it implements the definition
		(Subscript[T, n])(x)=(Underoverscript[Σ, (k=0), n])(((g^((k)))(a))/(k!))(((x-a))^k)
I'll use “taylor” throughout the following exercises to generate the required Taylor polynomials. Follow Professor Wilkinson's videos to see the development of each Taylor polynomial done slowly and gently! I’m using this to give you some idea of how wonderful Taylor polynomials are, and how wonderful it is to have software to help us....

Clear[g]
g[x_]:=Sin[x]
a=0;
n=3;
(* So let's generate the third degree Taylor polynomial to Sine about 0: *)
tn[x_]=taylor[g,a,n]; (* notice: no ":=" -- I'm using just "=". That's important.*)
(* What's it look like? *)
tn[x]
rn[x_]:=g[x]-tn[x]
GraphicsGrid[{{
Plot[{g[x],tn[x]},{x,a-Pi/2,a+Pi/2},PlotLabels->Automatic],
Plot[{rn[x]},{x,a-Pi/2,a+Pi/2},PlotRange->All]
}}]

What is the biggest |(g^((4)))(x)| can be? What is a good choice for M in the Taylor series error estimate? (Video)

Plot[Abs[g''''[x]],{x,-Pi/2,Pi/2}]

If you approximate sin(0.2) with (Subscript[T, 3])(0.2) what is an upper bound on the error using the Taylor series error estimate? (Video)

boundThis[x_]=D[g[x],{x,n+1}]
width=0.2
Plot[Abs[boundThis[x]],{x,a-width,a+width},PlotRange->All]
bound=.21
bound/((n+1)!)*width^(n+1)
tn[0.2]
Sin[0.2]
rn[0.2]

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?

(Video)

Questions

Let h(x)=ln(x), 0.5≤x≤1.5

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 (Subscript[T, 5])(x)? What is a good estimate for M? (Here, the fifth derivative is maximal at one of the endpoints. Which endpoint?)

Clear[g]
g[x_]:=Log[x]
a=1;
width=.5;
n=5;
(* So let's generate the third degree Taylor polynomial to Sine about 0: *)
tn[x_]=taylor[g,a,n];
(* What's it look like? *)
tn[x]
rn[x_]:=g[x]-tn[x]
GraphicsGrid[{{
Plot[{g[x],tn[x]},{x,a-width,a+width},PlotLabels->Automatic],
Plot[{rn[x]},{x,a-width,a+width},PlotRange->All]
}}]

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

boundThis[x_]=D[g[x],{x,n+1}]
width=.5
Plot[Abs[boundThis[x]],{x,a-width,a+width},PlotRange->All]
bound=8000
tn[1.5]
g[1.5]
rn[1.5]
bound/((n+1)!)*width^(n+1)

(Video)

Questions

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

What is the (n^th) degree Taylor polynomial centered at zero for f(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.

(Video)

Approximating Sine for your calculator

The reason we love Taylor polynomials is because they allow us to replace “complicated” functions with polynomials -- which require only the four operations of addition, subtraction, multiplication, and division for their computation. 

Because of the symmetry and periodicity of the sine function, we can approximate Sine everywhere with this polynomial; by taking a high enough degree polynomial, you can get your error down below the  number of decimals usually shown on a calculator. A 15th degree polynomial is probably good....

f[x_]:=Sin[x]
a=Pi/4;
n=15;
tn[x_]=taylor[f,a,n];
tn[x]
rn[x_]:=f[x]-tn[x]
GraphicsGrid[{{
Plot[{f[x],tn[x]},{x,0,Pi/2}],
Plot[{rn[x]},{x,0,Pi/2},PlotRange->All]
}}]

This function, SinFake, is our fake version of sine -- in contrast to Mathematica’s fake version of sine -- which it calls Sin. It’s built entirely off of symmetry, periodicity, and the Taylor polynomial about x=Pi/4 on the interval [0,Pi/2].

SinFake[x_]:=
If[x<0,-SinFake[-x], (* Sine is odd; throw it across to the right side *)
If[x≤Pi/2,tn[x], (* If we're in the interval [0,Pi/2], use tn *)
If[x≤Pi,tn[Pi-x], (* if in the interval (Pi/2,Pi], use symmetry about x=Pi/2 *)
If[x≤2Pi,-SinFake[2Pi-x], (* if on (Pi,2Pi], use Sin[x]=Sin[2Pi-x] *)
SinFake[x-2Pi*Floor[x/(2Pi)] (* if above 2Pi, use periodicity to get down to (0,2Pi] *)
]
]
]
]
]
Plot[SinFake[x],{x,-3Pi,3Pi}]
Plot[Sin[x]-SinFake[x],{x,-3Pi,3Pi},PlotRange->All]