Animation Algorithm
Volume 9
Number 11
Column Tag C Workshop
Related Info: Color Quickdraw Gestalt Manager
From Algorithm to Animation
The making of a movie
By Jay Martin Anderson, Lancaster, Pennsylvania
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
About the author
Jay Anderson is Professor of Computer Science in the Department of Mathematics
at Franklin and Marshall College in Lancaster, Pennsylvania. Trained as a physical
chemist, he combines here his interest in quantum mechanics, mathematics, and
Macintosh software development.
He can be reached at j_anderson@acad.fandm.edu on Internet.
Description of the problem
In presenting an algorithm for the solution of a particular kind of differential
equation to a class in Computational Mathematics in the spring of 1992, I was led first
to illustrate the algorithm with a graph, then with a series of graphs, and finally with
an animated series of graphs. The product uses simply, but significantly, Color
QuickDraw and QuickTime. The result is an engaging, yet helpful look at the workings
of a numerical algorithm as applied to a textbook problem in quantum mechanics.
The algorithm.
The particular problem we solved arises in physics or chemistry courses in
quantum mechanics, for it helps to illustrate the concept of “tunneling.” From a
mathematics point of view, the problem is one of a subclass of differential equations.
Ordinary differential equations are equations which involve derivatives of a
function with respect to one independent variable; first-degree ordinary differential
equations involve only the first derivative. A system of first-degree ordinary
differential equations involves two or more dependent variables and their first
derivatives with respect to one independent variable. It is possible to write a single
second-degree differential equation as a system of two first-degree differential
equations.
The quantum-mechanical problem is this: particle, moving in only one
dimension, is influenced by no potential energy over a part of its range, and by a
constant potential energy (a “barrier”) over another part of its range. The quantum
mechanics student is challenged to find what allowed energies the particle may
assume, called eigenvalues or characteristic values of energy. If an energy
eigenvalue is less than the potential energy barrier, the particle is said to “tunnel
through the barrier,” and that state is referred to as “classically forbidden.” If an
energy eigenvalue is greater than the potential energy barrier, that state is called
“classically allowed.” In either case, the state is allowed by quantum mechanics and
is observed in the world of electrons, atoms, and molecules.
Trimming the problem to its bare essentials, we endeavor to find solutions to
the equation
where E is the (unknown) energy eigenvalue, and A is the constant potential energy.
This is a very simple example of the famous Schrödinger equation of quantum
mechanics, also called the “wave equation.” The function y(x), which satisfies this
equation, is called an eigenfunction or a wave function. We can make this one
second-degree differential equation into two first-degree differential equations by
substituting a new variable for the first derivative of y:
Bear in mind that, in our specific problem, A = 0 for some range of x, and A ≠
0 for some other range of x. In particular, we choose
A = 0 for -1 ≤ x < 0 A > 0 for 0 ≤ x ≤ 1
Figure 1. A region with a potential energy barrier
Finally, we are compelled to impose some constraints on the or eigenfunction y
as well:
The last condition means that the slope of the eigenfunction must be continuous
even where the potential energy changes value.
Well, enough for quantum mechanics and mathematics; on to some computer
science, or at least some computational mathematics. There are good algorithms for
solving systems of ordinary differential equations if both the value and the slope of
the eigenfunction are known at one value of the independent variable; these
algorithms are “initial value methods,” and a simple, but adequate method is the
Runge-Kutta method. The Runge-Kutta method begins with a value of y and dy/dx at x
= -1 and works forward towards x = +1 in small steps, to find the values of y along
the way.
But that is not what is needed here; in fact, we don’t know the value of dy/dx at
x = -1, but we do know the values of y at both x = -1 and x = +1. What we need is
not an initial value method but a “boundary value method,” for we know values at
both boundaries.
The “shooting method” is an example of a boundary value method. In the
shooting method, we guess an eigenvalue of E, the energy, and we presume an initial
value of dy/dx. Then we “shoot”: that is, we use an initial value method such as the
Runge-Kutta method to shoot towards the other boundary. If our “shot” hits the
other boundary condition, then we have a solution; if it doesn’t, we try again. We
continue trying until our shot hits the other boundary accurately enough to satisfy
us.
This method is computationally intensive, for it requires repeating the
Runge-Kutta method over and over again until arbitrary accuracy has been achieved
in shooting at the right boundary. The method carries with it, and compounds, all the
errors of the Runge-Kutta method, but it works fast enough and is accurate enough
for this problem to give students some insight into both methods for solving
boundary value problems, and the quantum-mechanical tunneling problem in
particular.
The desired effect
It is useful, in any method for solving ordinary differential equations, to be
able to graph the solution; it is particularly useful in the shooting method for solving
boundary value problems, to be able to graph approaches to the solution; that is, to
graph different “shots.” But it is most useful to be able to graph a series of shots as
they approach the shot which is the solution to the boundary value problem. This can
be done in an effective and engaging way with animation.
In addition, since this particular boundary value problem has many solutions
(in fact, there are an infinite number of eigenvalues E and eigenfunctions y which
satisfy the system of equations and its constraints), it is possible to show how the
shooting method finds the first eigenvalue, and then the second, and then the third,
and so forth. This leads us to a sequence of graphs which approach and find the first
solution, then approach and find the second solution, etc.
Finally, it would be nice to call a student’s attention to the solutions with
sound, or color, or both.
Our desired effect, then, is an animated graph, accompanied by visual or
audible cues that solutions have been found. This series should begin with values of E
less than the first eigenvalue, and extend to include the first few (I chose five)
eigenvalues. The result will be a sound movie of many shots, showing five solutions
to the problem.
The Shooting Method
As mentioned above, the shooting method is based on a method for solving an
initial value problem in ordinary differential equations, such as the Runge-Kutta
method. The Runge-Kutta method, and code in C or Pascal to implement it, can be
found in any of a number of standard textbooks, so there is no need to belabor that
point here. A library of numerical mathematics may also have source or object code
for the Runge-Kutta method.
To graph an individual “shot,” we must first design a Macintosh window to
receive the graph, and then develop a transformation to map the real-world
variables of y and x onto the window variables of horizontal and vertical pixels. This