Taylor Polynomials Demo.
The following worksheet demonstrates some of Maple's abilities to work with Taylor polynomials.
To begin we need to include the following Maple packages...
> | restart;
with(Student[Calculus1]): with(Optimization): |
Let's work with a "Bell Curve" like function...
> | f := x -> exp(-x^2):
'f(x)'=f(x); |
(1) |
The "Student[Calculus1]" package has a function called "TaylorApproximation" which will do pretty much everything we want.
Here is the (fifth order) Taylor polynomial for centered at =1...
> | TaylorApproximation(f(x),x=1,order=5); |
(2) |
This function will also happily churn out a whole list of Taylor polynomials.
For example here are and ...
> | TaylorApproximation(f(x),x=1,order=1..3); |
(3) |
"TaylorApproximation" will also produce plots. Here is a plot of the first 3 Taylor polynomials (in blue)
along with the original function (in red). I have set the view window to and ...
> | TaylorApproximation(f(x),x=1,order=1..3,output=plot,view=[-2..4,-0.5..1.5]); |
Another nice feature is that this function will output animations (a series of plots shown over time).
Here are plots of the first 25 Taylor polynomials.
Note: To play this animation, click on the plot and then click on the play button appearing in the toolbar at the top of this window.
> | TaylorApproximation(f(x),x=1,order=1..25,output=animation,view=[-2..4,-0.5..1.5]); |
Let's compute the actual maximum error for the 9th order Taylor polynomial.
> | P9 := TaylorApproximation(f(x),x=1,order=9); |
(4) |
Next, we use the "Maximize" function again to find the max error...
> | ActualMaxError := Maximize(abs(f(x)-P9),x=0..2)[1]; |
(5) |
So if we stay with of the base point , our Taylor polynomial never gives an answer more than off of our actual function.
A second example: Let's consider and base at x = 0 this time.
> | f := x -> sin(x^2)+sin(x):
'f(x)'=f(x); |
(6) |
The Student[Calculus1] package has a function called "TaylorApproximation" which will do pretty much
everything we want.
Here is the (fifth order) Taylor polynomial for centered at =0...
> | TaylorApproximation(f(x),x=0,order=5); |
(7) |
Here are and ...
(8) |
> | TaylorApproximation(f(x),x=0,order=1..3); |
(9) |
Here is a plot of the first 3 Taylor polynomials (in blue)
along with the original function (in red). I have set the view window to and .
> | TaylorApproximation(f(x),x=0,order=1..3,output=plot,view=[-4..4,-4..4]); |
Here are plots of the first 25 Taylor polynomials.
> | TaylorApproximation(f(x),x=0,order=1..25,output=animation,view=[-4..4,-4..4]); |
Let's compute the actual maximum error for the 9th order Taylor polynomial.
> | P9 := TaylorApproximation(f(x),x=0,order=9); |
(10) |
Next, we use the "Maximize" function again to find the max error...
> | ActualMaxError := Maximize(abs(f(x)-P9),x=-1..1)[1]; |
(11) |
So if we stay with of the base point , our Taylor polynomial never gives an answer more than off of our actual function.