Animation and 3D Plots

Beyond producing static two-dimensional plots, Mathematica can produce three
dimensional plots and can animate series of two and
three-dimensional graphs.

Briefly, most of the animation features can be utilized directly in the Mathematica
``front end''. Additional features can be found in a set of functions
contained within the Graphics/Animation package library. All of these features
can be used in conjunction with the various plotting functions

Mathematica comes with a very large set of additional functions which
are included in the form of ``packages'' that you load as you need them.
The set of packages includes those dedidcated to
Linear Algebra, various aspects of graphics, Statistics,
and several more. By invoking the
command,

Needs["Graphics`Animation`"]


we can utilize the animation (and other)
functions contained in the Graphics/Animation library.
Note that once we have invoked this command
it is valid for the rest of our Mathematica session. To find out more about
the relevant commands, use either the Mathematica book or
the on-line help facilities of Mathematica to
learn about the Needs function (For example, but inputting

?Needs

in a Mathematica session.

Also, if you are using a notebook interface to
Mathematica you can see what functions are defined

To try out the animation and 3D graphics features, let's consider another
physical phenomena which crosses many disciplines, that of wave propagation.
In general there are two types of waves, transverse and
compressional. A transverse wave occurs when the impulse starting the
wave propagation is perpendicular to the direction of the resulting traveling
wave. Examples of transverse waves include, waves on a string (like plucking a
guitar), water waves, and light. A compressional wave occurs when the
impulse starting the wave is parallel to the direction the wave travels.
Examples of compressional waves include sound and earthquakes.

Let's consider the motion of transverse waves. For those of you that are
interested, the equation for transverse waves is given as,

 2             2
d u 1 d u
--- = --- ---
2 2 2
d t v d x

where u is the position of the wave as a function of space and time and
v is the velocity of the wave. While the equation might look complicated
at first, it actually has a fairly simple solution which can be expressed
in terms of a cosine. For a one-dimensional wave we have,

u(x,t) = A cos((2 &pgr;/&lgr;) (x - vt))

where A is the amplitude of the wave (i.e., the ``height'') and
&lgr; is the wavelength (the length of a wave is measured from crest to crest---or
from any two like points). Depending on our choice of the amplitude and
wavelength, the solution should look very familiar to us---like a cosine wave
that moves in time. We can utilize Mathematica's animation features to see this.
Let's set A=1.0,&lgr;=5.0, and v=2.0. Then the wave is a function of two variables,
x and t, given by

u[x_,t_]:=Cos[(2 Pi/5.0)*(x-2.0 t)];

Now we make a ``table'' of plots of this function using the Animate function
which we loaded via the Graphics/Animation package

Animate[
Plot[u[x,t], {x, 0, 10}],
{t, 0, 2Pi, Pi/8}
];

This is the solution of a wave traveling along a string (the type of
wave you would create by taking a rope and moving it up and down or by
dropping a stone into a calm pond). If you are using the Mathematica front
end for this lesson you should be able to select the collection of plots and
make them ``scroll'' on the screen like a cartoon. If you run this in a constant
loop, it may remind you of the output of an oscilloscope (or a scene
from an old science fiction movie) - depending on our fast your
computer is processing the information.

Now experiment with different values for A, v, and
&lgr; to see how they influence the shape of the wave. It will be more
convenient if you make a new function, wave, that explicitly makes all
of these parameters variables. For example,

wave[x_,t_,a_,v_,lam_]:= 
a Cos[(2Pi/lam)*(x-v*t)];

While the solution for the traveling wave along a string isn't too complex,
things change when the waves are moving in two and three dimensions,
often times with different amplitudes and wave speeds along each direction.
Let's look at a couple of waves at different instances in time for a
two-dimensional wave. Let's start off with the simplest case of a wave in the
x direction and one in the y direction which have exactly the same parameters:

Plot3D[
wave[x,1,1,2,5]+wave[y ,1,1,2,5],
{x, 0, 2Pi}, {y, 0, 2Pi}
];

This is the type of wave motion you would obtain by moving a piece of
cloth---such as a sheet---up and down). For the above parameter values,
the wave should appear symmetric. Notice how difficult it would be to
reconstruct such a surface just from a set of numbers or two
dimensional plots.

Usually it is important that the values for v and &lgr; in the two functions above match.
The velocity and wavelength are physical parameters related to the
material in which the wave is propagating. If these parameters are not the same
in each direction then usually that means you have made a mistake, since otherwise
what we are plotting would not make sense physically. However, there are some
substances, called anisotropic materials, which do have different wave velocities
and wavelengths in different directions. We will not deal with these here, so for us
v and &lgr; should always agree.

Using this same physical problem, we can
illustrate another type of visualization. Mathematica can also make contour
plots
of two dimensional data.

ContourPlot[
wave[x,1,1,2,5]+wave[y ,1,1,2,5],
{x, 0, 2Pi}, {y, 0, 2Pi}
];

(notice that as our Mathematica commands get longer and more complicated
we use tricks like indenting to make what we are doing a little clearer)

What you should see is something that reminds you of a topographical
map. The contours represent lines of equal values of the function, i.e., places of
the same amplitude. This is a direct analogy to a topographical map
which represents lines of equal elevation. Similar graphs can be used
to show places of equal temperature, or equal voltage, etc.
Iso-contour maps are used in almost every field of science and
engineering.

Let's look at another time instance; notice how the pattern has shifted.

ContourPlot[
wave[x,2,1,2,5]+wave[y,2,1,2,5],
{x, 0, 2Pi}, {y, 0, 2Pi}
];


Comparing this to our previous contour plot an interesting pattern should
emerge. Just as strings have different frequencies which give a
so-called standing wave at which they vibrate (these are called
normal modes). Vibrating surfaces have many more different
combinations of frequencies at which they can vibrate and produce what
are called nodal lines. Along these lines there is no motion of
the surface. An 18th century scientist, Ernst Chladni, figured this
out by placing sand on the surface of a flat plate and then vibrating
the plate with a violin bow. This caused the sand to distribute along
the nodal lines and form interesting patterns. What you are seeing is
the two dimensional projection of these patterns. Note: If you
want to try this at home, just get a flat metal plate and some sand
and vibrate the edges with a bow or tightly held cord.

By using three-dimensional graphics, we can look at the nodal lines as they
appear throughout the surface and also, we can animate the wave propagation in
three-dimensions. Let's try a three-dimensional animation! We substitute
the variable t into the above function, and again make a ``table'' of plots for
different values of t.

Animate[
Plot3D[
wave[x,t,1,2,5]+wave[y,t,1,2,5],
{x, 0, 2Pi}, {y, 0, 2Pi}
],
{t, 0, 10, 2}
];

Where we have made t a variable which we allow
to vary from 1 to 10. Now experiment with the values
for &lgr; in the original 3D plot and see how the waves (and nodal
patterns) change.

Continue to experiment and change the amplitudes and velocities of the wave
and notice their effects. You are now practicing a form of computational
science---you are using scientific visualization to investigate complex
wave phenomena that would be otherwise impossible with pencil and paper or
sets of data points. Hopefully this will give you a feeling for the power
of scientific visualization and some of its many uses.