Tutorial 6:  Animation

by R. Dover, IMSA

Below are two simple animations of 2-D graphs dealing with the period and the amplitude of the sine function.

Periods

Executing the cell below will create all of the graphs.  Select the cell bracket which contains all of the graphics.  From the "Cell" menu, choose "Animate Selected Graphics."  Use the controls at the bottom left to change the speed and direction of the animation.  Click anywhere in the notebook to end the animation.

Do[Plot[Sin[n x],  {x,  -2 π,  2  π}],  {n,  1,  
        4}]

Above, by default, n takes on the values 1, 2, 3, and 4.  To add more detail, make the step size smaller, say .5.  (Edit the command so that the end will read {n,1,4,.5}.)  Note that there are trade-offs.  The additional graphics often make the animation smoother and thus, it will probably look nicer, but they do require much more memory as well.

At some point, stop the action using the Pause/Play button.  Now press the down arrow (or up arrow) to cycle through the graphs one by one.

Amplitudes

Here, we'll use the command "Table" instead of "Do."  In this case, they are essentially the same.

Table[
      Plot[n Sin[x],  {x,  -6,  6}],  {n,  1,  4}]

Look at the graphs first.  Then run the animation.  Not particularly useful, huh?  The problem is that Mathematica chooses the range automatically.  The scale changes, but the graphs do not.  We'll correct this problem by adding the "PlotRange" command.  Try it again.

Table[
      Plot[n Sin[x],  {x,  -6,  6},  
        PlotRange  ->  {-5,  5}],  {n,  1,  4}]

Edit the line above to add more graphs or to change the values of n.

This example of amplitudes hopefully makes the point that the desired results may not happen as automatically as one would hope.  Understanding and being able to use additional commands will often be crucial.  Also, one often begins to create an animation with very few frames, making sure of the outcome, before reducing the step size.

Your turn...

Define a function f.  Plot f.  Then create an animation of f(x) + c, where c is a constant.  After you've done that one, then have some fun.  (If you're looking for more suggestions, try animating the color of a graph.)