[Edu-sig] Physics simulations

Bruce Sherwood bas@andrew.cmu.edu
Sat, 12 Feb 2000 15:52:24 -0500

Concerning physics simulations: There is a long history going back over 30
years of physicists writing simulations of physical phenomena for students
to play with. I claim that mostly this by itself has had little pedagogical
value. The Ph.D. physicist learned a lot from the simulation, but the
introductory student didn't have the background to ask or address
interesting questions using the tool. One exception to this gloomy
assessment is the situation where the instructor assigns carefully
articulated tasks for students to work on using the simulation as a tool.
It is attractive to imagine that just sitting the student down in front of
a wonderful simulation will lead to learning, but in most cases it doesn't.

I also want to draw people's attention to the fact that there already
exists a widely used general simulation package, called "Interactive
Physics." Using a graphical interface, an instructor can set up something
as complicated as a tumbling tower of blocks, and instrument the simulation
with graphs and meters to display velocity, energy, etc. There is a player
that students can use to run these instructor-prepared simulations. There
is a third-party cooperative effort to share setups. So all of this already
exists. Many physics teachers have gone beyond the gee-whiz to incorporate
this tool into their teaching in a sensible and thoughtful way.

An important distinction can be made between simulations and
visualizations. A simulation is always somewhat suspect, because it
necessarily leaves out some aspects of the real world. This is why many
instructors appropriately reject replacing lab experiences with
simulations. Visualizations normally are not subject to this problem. For
example, my colleague Ruth Chabay has produced QuickTime movies showing
electric and magnetic fields in three-dimensional space. We use these
movies as lecture-demonstration tools to help students visualize the 3D
aspects of fields. There is no issue here of inadequacy of the model,
because the movies don't simulate physical processes; rather they teach
about the vector representation used by physicists to reason about fields.
You can see or download these movies at


A rather different use of Python that interests our group is to have
students write their own computer models from scratch, rather than merely
manipulating parameters in someone else's computer model. Currently in our
modern mechanics curriculum (and to a lesser extent in our electricity and
magnetism curriculum) we have students write programs in our cT programming
language, with no black boxes. Many of the programs that the students write
are numerical integrations of Newton's second law. Here is the guts of a
typical student-written program for integrating the equations of motion for
a planet going around a stationary star (initial conditions would be set by
the student's program before entering this loop):

while 1:
   r = sqrt(x**2+y**2)
   F = G*M*m/r**2
   Fx = F*x/r
   Fy = F*y/r
   px = px+Fx*dt
   py = py+Fy*dt
   x = x+(px/m)*dt
   y = y+(py/m)*dt
   plot a disk at x,y

This is the simplest possible, crude integration algorithm. We have
students progressively cut the step size dt until the behavior doesn't
change. Today's computers are fast enough that this is adequate for our
purposes: we don't have to teach fancy Runge-Kutta techniques.

In merely two 50-minute periods we teach the students a subset of cT
adequate for writing these and related programs, and they immediately get a
spacecraft to the Moon, followed by orbits, spring-mass motion, etc., all
with 2D graphical output in the form of visualizing the actual motion as
well as graphs of energy, etc. We can't afford to spend more than two
periods teaching the language, because this is a physics course, not a
programming or computer science course. A sizable minority of our freshman
college science students have never written a computer program before, and
many of the others have never written a program with graphics output.

The goal, largely met, is to teach students the value of computer modeling,
and to fix clearly in their minds the fundamental nature of the "Newtonian
synthesis" -- that knowledge of positions and momenta at this moment let
you predict new positions and momenta a moment dt into the future, and
iterate. This view of Newtonian mechanics does not come across in the
traditional mechanics curriculum, which is dominated by known motions
(blocks sliding down inclines) from which something about the forces is
inferred, so that open-ended prediction of motion into the future plays a
minor role.

We have glimpsed the possibilities of teaching Python rather than cT in
those two 50-minute periods, with the possibility of students getting 3D
output for free! Python, like cT, has a simple surface syntax, without lots
of extra semicolons, braces, etc., and with meaningful indentation. As an
existence proof we have written Python programs that look sufficiently
similar to the cT programs that our students have successfully written that
we can be confident that brief instruction would be sufficient to get them
into computer modeling right away.

Python offers us three important things that we can't get from cT as it
stands, and we don't feel that cT is an adequate base to get there from
here. The first is 3D graphics. Dave Scherer, a computer science sophomore
at Carnegie Mellon, is developing an engine that lives as a separate thread
from the student's Python program and continually (many times a second)
updates a picture of the current positions of objects whose positions the
student is calculating (he uses OpenGL as the underlying engine). The
effect is that the student would write a purely computational program, with
no graphics statements, and for free get an animated 3d display. And also
for free, the graphics window lets you move the mouse to view the scene
from any position.

The second thing Python offers is object orientation. The student creates
objects such as sun = sphere() and earth = sphere() and then computes their
motions. This doesn't necessarily lead into teaching the student to create
classes, but it takes some first steps in the student's education about
OOP, because the student thinks about the display objects as objects, for
which we have some evidence that this is advantageous. In contrast, in cT
an animation is produced by erasing a disk here and plotting a disk there,
and the disk is just pixels on the screen, not an object that cT remembers
anything about. Students are sometimes puzzled that they can't change a
position merely by changing x and y, or that a ball plows through a wall on
the screen because those pixels aren't being considered by anyone.

The third thing Python offers is the possibility of writing vector
operations as single statements rather than as two (or three) separate
statements. We probably wouldn't start students this way, but at some point
during the course it may be appropriate to have them write something like

earth.position = earth.position + (earth.momentum/m)*dt

rather than writing

earth.x = earth.x + (earth.px/m)*dt
earth.y = earth.y + (earth.py/m)*dt
earth.z = earth.z + (earth.pz/m)*dt

The possible value in this is that it is a powerful idea to think of
vectors as single entities, not merely as two (or three) separate


In alphabetic order, let me introduce our Carnegie Mellon group. We think
we can make a real contribution to one aspect of CP4E, that of enabling
students in a physics course to write their own 3D graphics programs. We
are studying a variety of issues that must be addressed to make Python 
plus 3D viable for science students who have not programmed before.
These issues include making more robust and easy to use an integrated
development environment and the installation procedure, as well as the
purely 3D issues. We realize that if we address these problems we may
serve wider needs than our own, but we find it useful to take a very narrow
focus (the novice-programmer physics students) in order to make progress.

I should mention for completeness that our focus is rather different from
that of Randy Pausch at Carnegie Mellon. In Pausch's course on creating
virtual worlds, students use Python to control 3D models. Our focus is
rather on physics students writing simulations in the context of 3D
scientific visualization.

David Andersen <dma+@andrew.cmu.edu>
System designer in CIL (Center for Innovation in Learning). Wrote much of
the system software for the PLATO computer-based education system at the
University of Illinois in the 70's and 80's, including major contributions
to the TUTOR authoring language. Initiator of the MicroTutor language
(1977). For the last ten years has been further developing and maintaining
the cT programming language (which is a granddaughter of TUTOR and a
daughter of MicroTutor). Extensive cross-platform experience, including
Windows, Macintosh, and Unix/Linux.

Ruth Chabay <rchabay+@andrew.cmu.edu>
Ph.D. physical chemist, senior research scientist in CIL and Department of
Physics. Contributed to the PLATO system software in the 70's. Has written
award-winning and commercial educational software in chemistry and physics,
including 3D visualizations of electric and magnetic fields, and of the
ball-and-spring model of a solid. Co-author with Bruce Sherwood of a new
textbook for introductory university physics incorporating computer
modeling. Devised a very rapid introduction of computer modeling for
physics students. Regularly teaches physics courses at Carnegie Mellon in
which computing plays a major role.

Ari Heitner <aheitner@andrew.cmu.edu>
Ian Peters <itp@gnu.org>
David R Scherer <dscherer@andrew.cmu.edu>
Ari, Ian, and Dave are sophomores at Carnegie Mellon. Ari and Dave are
majoring in computer science, and Ian is a double major in physics and
computer science. They all come from the excellent Thomas Jefferson High
School in Alexandria VA. Dave Scherer is the person who introduced Python
to us and proposed building a novice 3D graphics computing environment on
top of Python. Dave and Ari were members of the TJ team that built "Fire
and Darkness," a 3D computer game that won the national prize last year at
the First Independent Games Festival. All three of the students were in our
physics course last year and had experience with student computer modeling
of physical phenomena. 

Dave is rapidly developing a module that runs in parallel to Python,
updating the screen with often enough to give smooth 3D animations, with
user mouse actions enabling change of point of view of the scene. His
module talks to OpenGL. Programs using Dave's module don't make explicit
graphics calls but simply update screen positions of objects such as
spheres and curves.

Bruce Sherwood <bas@andrew.cmu.edu>
Ph.D. physicist, a principal research scientist in CIL and professor in the
Department of Physics. Contributed to the PLATO system software in the
70's, including in particular contributions to the TUTOR and MicroTutor
languages. Has written award-winning and commercial educational software in
physics. Initiated the development of the cT programming language. Has
written book and on-line software documentation. Co-author with Ruth Chabay
of a new textbook for introductory university physics incorporating
computer modeling. Regularly teaches physics courses at Carnegie Mellon in
which computing plays a major role.