0% found this document useful (0 votes)
73 views6 pages

Modeling Physics With Easy Java Simulations

This document describes the Easy Java Simulations (Ejs) modeling and authoring tool and how it can be used to teach mechanics concepts with computer modeling. Ejs allows both experts and novices to quickly prototype, test, and distribute packages of Java simulations. It simplifies the modeling process by breaking it into documentation, modeling, and interface design activities. As an example, the document discusses the Pendulum model available in Ejs, including its description, variables, and how auxiliary Cartesian variables are computed from dynamical polar variables through constraints. Ejs makes modeling more engaging for students by enabling them to modify and adapt existing models.

Uploaded by

MoFa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
73 views6 pages

Modeling Physics With Easy Java Simulations

This document describes the Easy Java Simulations (Ejs) modeling and authoring tool and how it can be used to teach mechanics concepts with computer modeling. Ejs allows both experts and novices to quickly prototype, test, and distribute packages of Java simulations. It simplifies the modeling process by breaking it into documentation, modeling, and interface design activities. As an example, the document discusses the Pendulum model available in Ejs, including its description, variables, and how auxiliary Cartesian variables are computed from dynamical polar variables through constraints. Ejs makes modeling more engaging for students by enabling them to modify and adapt existing models.

Uploaded by

MoFa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

Modeling Physics with

Easy Java Simulations


Wolfgang Christian, Davidson College, Davidson, NC

Francisco Esquembre, Universidad de Murcia, Murcia, Spain

M
odeling has been shown to correct weak- what science is about.2
nesses of traditional instruction by en- Wells, Hestenes, and Swackhamer point out that
gaging students in the design of physical introductory mechanics courses are organized around
models to describe, explain, and predict phenomena.1 a small number of basic models that are adapted to
Although the modeling method can be used without various contexts. Constant acceleration, simple har-
computers, the use of computers allows students to monic motion, Newton’s universal law of gravitation,
study problems that are difficult and time consuming, and energy/momentum conservation form the core
to visualize their results, and to communicate their of this course. Ready-to-use models and associated
results with others. This combination of computer curricular material described for these topics are avail-
modeling with theory and experiment can achieve in- able on the Open Source Physics (OSP) website in the
sight and understanding that cannot be achieved with ejs_tpt_modeling.jar archive.3
only one approach. This paper describes the Easy Java The OSP Launcher shown in Fig. 1 is a Java
Simulations (Ejs) modeling and authoring tool and program that contains mechanics models and docu-
shows how it can be used to teach mechanics concepts mentation in a single archive known as a Launcher
with computer modeling. package.4 Clicking on an item in the table of contents
A model is a surrogate object or a conceptual rep-
resentation of a physical system and/or its properties,
and modeling is the process whereby we construct
this representation. Computer modeling requires (1)
a description and an analysis of the problem, (2) the
identification of the variables and the algorithms, (3)
the implementation on a specific hardware-software
platform, (4) the execution of the implementation
and analysis of the results, (5) refinement and gener-
alization, and (6) the presentation of results. A com-
puter simulation is an implementation of a model that
allows us to test the model with different initial condi-
tions with the objective of learning about the model’s
behavior. The applicability of the results of the simu-
lation to those of the real (physical) system depends
Fig. 1. An Ejs Launcher package contains compiled ready-
on how well the model describes reality. The process to-use models. Clicking on a Launch Node runs the model.
of devising more general and more accurate models is Right-clicking on a Launch Node passes the model to the Ejs
authoring tool.

The Physics Teacher ◆ Vol. 45, November 2007 DOI: 10.1119/1.2798358 475
tree (left-hand side of the Launcher window) loads choice.6 Executing the EjsConsole.jar file in the
an html page that describes the model. Users execute installation directory creates an empty Ejs workspace,
(run) models in our package by double clicking on the as shown in Fig. 2.
“Launch Nodes” (green arrows) in the tree. Easy Java Simulations is well-suited for education
Users without vendor-installed Java must, of because it is simple to use and combines authoring
course, first download and install Java in order to run with powerful modeling tools. Its dynamic and highly
our models.5 Running a Java program on a modern interactive user interface greatly reduces the amount
operating system is straightforward because a typical of programming required to implement an idea. Even
(default) Java installation recognizes a Java archive experienced programmers find Ejs useful, because it is
(jar) file as a compiled Java program. Users need only faster and easier to:
double-click on the jar file to run our models.
Although the models in our mechanics package • Develop a prototype of an application in order to
are compiled and ready-to-use Java applications, an test an idea or algorithm.
important pedagogic feature is that our package is • Create user interfaces without programming.
created in such a way that users can return to Ejs at • Create models whose structure and algorithms
any time to examine, modify, and adapt the models. nonprogrammers can inspect and understand.
The Launcher package contains a small Extensible
• Encourage students or colleagues (who may be
Markup Language (XML) description of each model, new to Java) to create their own simulations.
and right-clicking on a Launch Node passes this XML
document to the modeling tool, thereby allowing us- • Quickly prepare simulations to be distributed as
applets or as stand-alone programs.
ers to examine and modify the model. Ejs can repack-
age the modified model in a new jar file for redistribu- • Create a package containing multiple programs
tion or submission to an instructor as a completed and the associated curricular material.
exercise.
Easy Java Simulations simplifies the modeling
Ejs Modeling process by breaking it into activities that are selected
Easy Java Simulations is a Java program that en- using radio buttons: (1) documentation, (2) model-
ables both programmers and novices to quickly and ing, and (3) interface design. The model’s html-based
easily prototype, test, and distribute packages of Java documentation is accessed by selecting “Descrip-
simulations. It can be downloaded from the Ejs web- tion.” The physics is accessed by selecting “Model,”
site and installed (unzipped) into a directory of their which provides access to the data and the methods
(Java code) by which the model can change. A plot
is a visual representation of data and is an example
of a “View.” Because it is possible to have multiple
views of the same data and because the model and its
views are controlled by buttons and other on-screen
components, Ejs provides a graphical drag-and-drop
editor for the user interface, which eliminates much
coding. The Ejs model-view-controller paradigm is
well known in computer science and provides a solid
foundation for software development.

Pendulum Model
Screen shots are no substitute for a live demonstra-
tion, and we encourage readers to load, inspect, and
run the Pendulum model described in this paper. Ex-
Fig. 2. The Easy Java Simulations user ecute the EjsConsole.jar program in the directory
interface (with annotations).

476 The Physics Teacher ◆ Vol. 45, November 2007


Fig. 4. A table of variables that describes the state of a
simple pendulum.
Fig. 3. A description of the Pendulum model.
Descriptions are html pages that can be created within Corresponding program variables are defined in
or imported into Ejs. “Variables” tables as shown in Fig. 4. Because the
where Ejs was installed to start Ejs. Then click on the Pendulum model uses 10 variables, we have chosen
file-folder icon on the Ejs taskbar to open a file-brows- to create three tables. The table of dynamic variables
er to load the Pendulum model. The Pendulum.xml contains values that evolve in time while the constants
file is located in the users/davidson/wochristian/ table contains parameters, such as g and L, which
tpt_modeling subdirectory in the “Simulations” remain fixed. The x, y, vx, and vy auxiliary variables
directory. Use the “Save As” icon on the Ejs taskbar to store Cartesian position and velocity vector com-
create a copy of this file in your own working direc- ponents of the pendulum bob. These variables are
tory. computed from the dynamical (polar) variables by
Narratives, such as the pendulum description entering a small amount of Java code into the model’s
shown in Fig. 3, are an essential component of model- “Constraints” page.
ing, and Ejs makes it straightforward for modelers to
include html-based documentation. Right-clicking x= L*Math.sin(theta);
within the workpanel allows users to edit existing y = -L*Math.cos(theta);
vx = omega*L*Math.cos(theta);
html pages and to create additional pages. Teachers
vy = omega*L*Math.sin(theta);
can, for example, author a student exercise that uses
our existing Pendulum model. The “Constraints” panel contains additional code,
Selecting “Model” reveals a series of subpanels such as an energy computation, that is executed at the
specifying the different parts of the model: definition end of every evolution step or when the user drags an
of variables, initialization, evolution of the system, on-screen object. The most difficult aspect to remem-
constraints or relationships among variables, and cus- ber when entering these code fragments is to use the
tom methods. Each panel provides tools that facilitate multiplication character * and to place a semicolon at
the creation of these parts. For example, if we ignore the end of each statement.
friction, a simple pendulum obeys the differential Creating separate tables to group variables is an ef-
equation fective way to organize data in Ejs models. Although
the Pendulum model uses only floating point (deci-
d 2q g
2
= − sin (q ), mal) numbers, it is also possible to define integer and
dt l Boolean variables and arrays of other variables. (See
where q corresponds to the pendulum’s angular the examples in the Launcher package for this article.)
displacement from the vertical, l is the pendulum’s Newton’s second law can be converted to two first-
length, g is the acceleration due to gravity, and t is order equations by adding an angular velocity variable
the time. w to the model. Both angular position q and veloc-

The Physics Teacher ◆ Vol. 45, November 2007 477


order equations.
The “Evolution” page shown in Fig. 5 contains
the differential equations for the pendulum using the
model’s variables. Ejs will solve the given system of
differential equations using the numerical algorithm
specified in the field below the equation. The initial
position q0 and initial velocity w0 are advanced by a
time step Δt to obtain new values q1 and w1, respec-
tively, and this process is repeated 10 times per sec-
ond.
Solving a system of first-order differential equa-
tions efficiently using numerical algorithms is not
Fig. 5. The Ejs equation editor showing the pendulum’s sys- a trivial task, but Ejs removes many of the barriers.
tem of ODEs.
Pressing the run icon (green triangle) on the Ejs task-
bar generates the necessary Java code so that students
and instructors can focus their attention on the physi-
cal model. But the numerical method is not a “black
box” either. Modelers can select both the algorithm
and the algorithm’s time step, and advanced users can
download and examine the algorithm’s Java code from
the Open Source Physics website.3 Simple tests such
as comparing solutions with different algorithms or
with different time steps are usually all that are needed
to determine the validity of the algorithm. Testing the
validity of a solution is an important but often over-
looked step in computational modeling.
Selecting “View” in the Ejs workspace displays the
structure of the simulation’s user interface, as shown
Fig. 6. The “Tree of Elements” for the simulation (left) shows in Fig. 6. The “Tree of Elements” shows that this
the graphical elements (right) of the pendulum simulation. model has a frame (window) with two buttons and a
Double-clicking on an element in the tree shows a table of
plotting panel. The plotting panel contains a line rep-
element properties.
resenting the pendulum arm and a circle representing
ity w are now independent functions of time and have the pendulum bob. There is a second frame contain-
their own rate of change: ing another plotting panel and a trace. This trace will
dq display the bob’s angle q with respect to time t.
=w High-level data visualizations, such as the q plot in
dt
the pendulum model, are created in Ejs without pro-
dw g gramming by dragging objects from the “Elements”
= − sin(q ).
dt l pallet into the “Tree of Elements.” Element properties
The process of defining velocity variables, such as are then associated with variables from the model (or
w, to reduce the order of a differential equation (but expressions that use them) in order to create a true
increase the number of equations) can be extended to dynamic and interactive visualization of the phenom-
higher-order derivatives as needed. Because higher- enon under study. If you right-click on the “trace”
order differential equations can be converted into a element you will obtain the properties table for that
system of coupled first-order equations, we need only element. Observe that the angle and time variables in
consider general methods of solving systems of first- Fig. 4 are assigned to the trace’s ordinate and abscissa
inputs on Fig. 7. The “Evolution” page (Fig. 5) con-

478 The Physics Teacher ◆ Vol. 45, November 2007


trols the temporal evolution of the Pendulum model
and the trace automatically collects q(t) as the model
evolves.
In order to position the bob on the screen, we as-
sociate the model’s x and y auxiliary variables with
the pendulum bob’s (blue circle) position properties.
Right-clicking on the bob and selecting the proper-
ties menu item displays the table shown in Fig. 8.
The “Visibility and Interaction” section of the table
specifies how the bob reacts to mouse actions. Pressing Fig. 7. Table of properties for the trace element in the view.
on the bob stops the animation using an Ejs-defined
_pause method. (Clicking on an icon next to the
text field displays a list of methods.) Dragging the bob
computes new q and w values using a user-created
newPosition method in the model.
The newPosition method that is invoked in
response to a mouse-drag is defined on the model’s
“Custom” code page. This method starts by comput-
ing the bob’s angle from the Cartesian mouse coor- Fig. 8. Table of properties for the bob element in the view.
dinates (x, y). The (x, y) values are adjusted to ensure
that the pendulum length remains fixed, and the is packaged with other mechanics examples in the
velocity variables are set to zero. Finally, data in the q ejs_tpt_modeling.jar archive. The first example
plot are cleared. Users can compare different plots by in the package models Newton’s first law without
right-clicking within the plot to create a copy before differential equations. The second example models
dragging the bob to a new position. one-dimensional free fall with first-order differential
public void newPosition () { // invoked during a drag action equations for position and velocity. The models in the
// length is constant archive increase in complexity and show additional
theta = Math.atan2(x,-y); // computes the angle
x = L*Math.sin(theta); // computes x given a length Ejs features, but even advanced models, such as Kep-
y = -L*Math.cos(theta); // computes y given a length lerian orbits from an inverse-square-law force, require
omega = 0.0; // zero angular velocity
vx = vy = 0.0; // zeros velocity components almost no Java programming. Teachers who customize
t = 0.0; // resets time our examples or who develop their own models and
_view.resetTraces(); // clears the plot
curricular material can use the “Package” icon on the
right-hand side of the Ejs workspace to create ready-
It is important to note that the newPosition method to-use Launcher packages containing collections of
on the “Custom” page and the conversion from polar models for distribution to students and colleagues.
to Cartesian coordinates on the “Constraints” page are We are in the process of creating a database of Ejs
the only Java code within the pendulum model. Ejs models and of related curricular material on the BQ
creates a complete and ready-to-distribute Java appli- Learning website that in-service physics teachers can
cation and a complete Java applet with an associated use to implement computer-based interactive engage-
html page from the XML-based pendulum model in ment methods in their classrooms.7 The database is
the _apps directory when the run icon is pressed. free and open and is based on XML standards for easy
indexing in digital libraries.
Conclusion Ejs promotes an integrated understanding of the
The Pendulum model illustrates many concepts in modeling process by exposing and providing access
introductory mechanics and is easy to extend to in- to the underlying assumptions in the physical model.
clude damping and forcing and to improve the analy- It encourages revision and testing of the model and
sis with phase-space and energy graphs. This model the distribution of the model including narrative and

The Physics Teacher ◆ Vol. 45, November 2007 479


documentation. It is both simple to use and suffi- are available from Sun Microsystems at http://java.sun.
ciently advanced to handle complex models that occur com/javase. The Apple Computer OS X operating sys-
in professional practice. Finally, the BQ database en- tem ships with Java installed.
ables teachers to quickly access, revise, and adapt Ejs 6. F. Esquembre, Creación de Simulaciones Interactivas en
models for their own teaching and to distribute their Java (Prentice Hall, Madrid, 2005). The Ejs program,
revisions. documentation, and examples can be downloaded from
http://www.um.es/fem/Ejs.
Acknowledgments 7. The BQ Learning database contains many Ejs models.
We would like to thank Mario Belloni, Anne Cox, These models can be accessed at http://www.
bqlearning.org.
and Fu-Kwun Hwang for useful conversations
regarding the development of Ejs models. The PACS codes: 01.50.ht, 45.00.00
Launcher program used to distribute ready-to-use
Ejs models was developed by Douglas Brown. The Wolfgang Christian is the Brown Professor of Physics at
Davidson College, where he has taught since 1983. He
BQ database is maintained by William Junkin and received his BS and PhD in physics from North Carolina
Anne Cox. Easy Java Simulations is an Open Source State University at Raleigh. He is author or coauthor of
nine books, including: Open Source Physics: A User’s
Physics project and this project is supported by the
Guide with Examples, An Introduction to Computer
National Science Foundation (DUE-0442581). Simulation Methods, Physlet Quantum Physics, Physlet
Physics, Physlets: Teaching Physics with Interactive
Curricular Material, Just-in-Time Teaching, and Waves
References
and Optics: Volume 9 of the Computational Physics Upper
1. M. Wells, D. Hestenes, and G. Swackhamer, “A model- Level Software series. He has been the books editor of
ing method for high school physics instruction,” Am. J. the APS journal Computers in Physics. He is a fellow
Phys. 63, 606–619 (July 1995). of the American Physical Society and past chair of the
Forum on Education. His research interests are in the
2. F.E. Cellier and J. Greifeneder, Continuous System Mod- areas of computational physics and instructional software
eling (Springer, New York, 2006). design.
3. W. Christian, Open Source Physics: A User’s Guide with Department of Physics, Davidson College, Davidson,
Examples (Addison Wesley, New York, 2007). Simula- NC 28035-6910, USA; wochristian@davidson.edu
tions developed using the OSP library and OSP tools
Francisco Esquembre received a PhD in mathematics
are available at http://www.opensourcephysics.org. in 1991 from the Universidad de Murcia, Spain, where
Resources for Ejs modeling are located in the modeling he is currently Assistant Professor of Mathematics. From
subdirectory; http://www.opensourcephysics.org/ 1995 until 1999 he was General Director for Universities
modeling. and Research for the Regional Ministry of Education, and
from 2002 to 2006 he was head of the Transfer Research
4. W. Christian, M. Belloni, and D. Brown, “An open Office of the University of Murcia. He is the author of
source XML framework for authoring curricular mate- Creación de Simulaciones Interactivas en Java and coau-
rial,” Comp. Sci. Eng. 8 (5), 51-58 (Sept./Oct. 2006). thor of Fislets. His academic expertise includes differential
equations, dynamical systems, and numerical analysis.
5. Java is freely available under the GNU open source His teaching interests are computer assisted teaching and
GPL license and installing it is no more difficult than learning as well as simulation of scientific processes for
installing other third-party software such as Acrobat or didactical purposes.
Flash readers. The most popular Java implementations Departamento de Matemáticas, Universidad de
Murcia, 30071 Murcia, Spain; fem@um.es

480 The Physics Teacher ◆ Vol. 45, November 2007

You might also like