6.39 animating plots of taylor polynomials (28.2.02)

6.39.1 John Losse

In attempting to show students Taylor polynomials of successive degrees, we tried defining the first few via the loop

for k from 1 to 8 by 1 do 
 tp[k]:=convert(taylor(f,x=0,k+1),polynom) 
end do;
 

This worked.

Next we hoped to plot the polynomials one after the other in the same window, but the animate command

animate(tp[s],x=-10..10,s=0..8, view=[-10..10,-3..3],frames = 9);
 

produces an empty plot.

We’ve found a very elaborate workaround but it seems the basic idea - step from one member of an indexed list to another - ought to work.

6.39.2 Carl Devore (1.3.02)

Animate requires s to be a real parameter, not integer. Use instead

plots[display] 
   ([seq(plot(tp[s], x= -10..10, -3..3), s= 0..8)] 
   ,insequence= true 
   );
 

or, in Maple 7, the more elegant syntax

plots[display] 
   ([seq](plot(tp[s], x= -10..10, -3..3), s= 0..8) 
   ,insequence= true 
   );
 

While I applaud your efforts to show your students the mechanics of creating these animations, you may be interested in also showing them my worksheet "Animation of Taylor series converging to their generating functions" available at the Maple Applications Center http://www.mapleapps.com.

This produces labelled animations several orders of magnitude faster than your example above, handles discontinuities, and most of the full range of plot options.

For example

   f:= x-> exp(cos(x))*tan(x)+cos(2*x)+sin(Pi*x); 
   TaylorAnim(f, Pi, 0..2*Pi, 50, -10..10, discont= true);
 

animates the complicated, discontinuous function f and its first 50 Taylor polynomials expanded at x=Pi with view window [0..2*Pi, -10..10] using 1.3 seconds and neglible memory on a Pentium II 400 MHz.

The comments in my code give several pointers on how to produce these high-speed animations.

6.39.3 Douglas B. Meade (1.3.01)

Animate works best when the animation variable is continuous. It is possible to achieve this for your situation but it’s not intuitive or simple.

I prefer to create a list of plots and then animate these with the display command. For example,

> f := 2*cos(x); 
> 
> for k from 1 to 8 by 1 do 
>   tp[k]:=convert(taylor(f,x=0,k+1),polynom) 
> end do; 
> 
> P := [seq( plot([f,tp[k]],x=-10..10,y=-3..3), k=1..8 )]: 
> display( P, insequence=true );
 

6.39.4 Robert Israel (3.3.02)
 plots[display]( 
    [seq( 
       plot(tp[k], x=-10..10, title=sprintf("degree %d",k)), 
       k=1..8)], 
    insequence=true, view=[-10..10,-3..3]);
 

6.39.5 Alan Gold (4.3.02)

The animate command is not very versatile. I almost never use it. Instead, create plot structures for each of your functions:

for k from 1 by 1 to 8 do 
 pl[k]:=plot(tp[k],x=-10..10,view=[-10..10,-3..3]): 
od:
 

Then use display with the option insequence=true

with(plots): 
display([seq(pl[k],k=1..8)],insequence=true);
 

You might want to look at "Animations for the Calculus Classroom" in the Maple Applications Centre for some further examples.