Approximations using Taylor Polynomials
This Maple worksheet generates the nth Taylor Polynomials centered at x = a for the function y = f(x). Graphs of the given function and the polynomials are generated. In addition, the remainders (error) are computed and plots are constructed.
Enter the function of your choice by changing the assignment for f. Change the value of a to change the center. Note that your choice could affect the intervals over which you need to display the plot.
Some of the parameters are
a--the center of the polynomial approximation
xmin, xmax--the endpoints of the plotting inverval
ymin,ymax--the vertical range of the plots
yticklist--the list of tickmarks for the vertical axis
step--control parameter for the procedure to generate the polynomials
numsteps--The degree of the Taylor Polynomial is computed by deg = mindeg + step*i for i = mindeg..numsteps.
For best results, slow the animation speed to 1 frame per second.
> restart;f:=sin(x);
> xmin:=-4*Pi;xmax:=4*Pi;
> ymin:=-2;ymax:=2;
> a:=0;mindeg:=1;step:=2;numsteps:=15;
> yticklist:=[-2,-1,1,2];
> with(plots):
Warning, the name changecoords has been redefined
>
plotpolys:=proc(i)
local poly, funct, titlestr, approxerror,deg:
deg := mindeg + step*i:
titlestr:= cat("n = ",deg-step);
poly:= plot(convert(taylor(f,x=a, deg), polynom),
x=xmin..xmax,y=ymin..ymax, color=red,thickness=3,
title=titlestr,ytickmarks=yticklist,numpoints=100):
funct := plot(f,x=xmin..xmax,y=ymin..ymax,color=black,thickness=3):
display([poly, funct],view=[xmin..xmax,ymin..ymax]);
end:
>
display([seq(plotpolys(i),i=mindeg..numsteps)],
view=[xmin..xmax,ymin..ymax],insequence=true);
>
errorplot:=proc(i)
local poly,err, desc, titlestr, deg:
deg := mindeg + step*i:
titlestr:= cat("Error(x) = f(x) - p",deg-step,"(x)");
err:=plot((f-convert(taylor(f,x=a,deg),polynom)),
x=xmin..xmax,y=ymin..ymax,color=blue,thickness=3,
view=[xmin..xmax,ymin..ymax],title=titlestr,
ytickmarks=yticklist):
display(err,view=[xmin..xmax,ymin..ymax]);
end:
>
display([seq(errorplot(i),i=mindeg..numsteps)],
view=[xmin..xmax,ymin..ymax],insequence=true);
Additional good examples with parameters:
f := log(x+1);
a := 0;
xmin := -1;xmax := 3;
step := 1;
numsteps := 15;
__________________________________________
f := cos(x);
a := 7*Pi/4;
xmin := -4*Pi;xmax := 4*Pi;
step := 1;
__________________________________________
f := cos(x);
a := 0;
xmin := -4*Pi;xmax := 4*Pi
step := 1;
mindeg := 2;
__________________________________________
This Maple worksheet was developed by
Lila F. Roberts
Mathematics and Computer Science Department
Georgia Southern University
Statesboro, GA 30460
lroberts@gasou.edu