Preface to the Third Edition

Computer simulations are now an integral part of contemporary basic and applied physics and computation has become as important as theory and experiment. The ability to compute is now part of the essential repertoire of research scientists.

Since writing the first two editions of our text, more courses devoted to the study of physics using computers have been introduced into the physics curriculum, and many more traditional courses are incorporating numerical examples. We are gratified to see that our text has helped shape these innovations. The purpose of our book includes the following:

  1. To provide a means for students to do physics.
  2. To give students an opportunity to gain a deeper understanding of the physics they have learned in other courses.
  3. To encourage students to discover physics in a way similar to how physicists learn in the context of research.
  4. To introduce numerical methods and new areas of physics that can be studied with these methods.
  5. To give examples of how physics can be applied in a much broader context than it is discussed in the traditional physics undergraduate curriculum.
  6. To teach objejct oriented programming in the context of doing science.
Our overall goal is to encourage students to learn about science through experience and by asking questions. Our objective always is understanding, not the generation of numbers.

The major change in this edition is the use of the Java programming language instead of True Basic, which was used in the first two editions. We chose Java for some of the same reasons we originally chose True Basic. Java is available for all popular operating systems, and is platform independent, contains built-in graphics capabilities, is freely available, and has all the features needed to write powerful computer simulations. There is an abundance of free open source tools available for Java programmers, including the Eclipse integrated development environment. Because Java is popular, it continues to evolve, and its speed is now comparable to other languages used in scientific programming. In addition, Java is object oriented, which has become the dominant paradigm in computer science and software engineering, and therefore learning Java is excellent preparation for students with interests in physics and computer science. Java programs can be easily adapted for delivery over the Web. Finally, as for True Basic, the non-graphical parts of our programs can easily be converted to other languages such as C/C++, whose syntax is similar to Java.

When we chose True Basic for our first edition, introductory computer science courses were teaching Pascal. When we continued with True Basic in the second edition, computer science departments were experimenting with teaching C/C++. Finally, we are able to choose a language that is commonly taught and used in many contexts. Thus, it is likely that some of the students reading our text will already know Java and can contribute much to a class that uses our text.

Java provides many powerful libraries for building a graphical user interface and incorporating audio, video and other media. If we were to discuss these libraries, students would become absorbed in programming tasks that have little or nothing to do with physics. For this reason our text uses the Open Source Physics library, which makes it easy to write programs that are simpler and more graphically oriented than those that we wrote in True Basic. In addition, the Open Source Physics library is useful for other computational physics projects that are not discussed in this text, as well as general programming tasks. This library provides for easy graphical input of parameters, tabular output of data, plots, visualizations and animations, and the numerical solution of ordinary differential equations. It also provides several useful data structures. The Open Source Physics library was developed by Wolfgang Christian, with the contributions and assistance of many others. The book, Open Source Physics: A User's Guide with Examples by Wolfgang Christian, is available separately and discusses the Open Source Physics library in much more detail. A CD that comes with the User's Guide contains the source code for the Open Source Physics library, the programs in this book, as well as ready to run versions of these programs. The source code and the library also can be downloaded freely from www.opensourcephysics.org/sip.

The ease of doing visualizations is a new and important aspect of Java and the Open Source Physics library, givng Java an advantage over other languages such as C++ and Fortran, which do not have built-in graphics capabilities. For example, when debugging a program, it is frequently much quicker to detect when the program is not working by looking at a visual representation of the data, rather than by scanning the data as lists of numbers. Also, it is easier to choose the appropriate values of the parameters by varying them and visualizing the results. Finally, more insight is likely to be gained by looking at a visualization than a list of numbers. Because animations and the continuous plotting of data usually cause a program to run more slowly, we have designed our programs so that the graphical output can be turned off or implemented infrequently during a simulation.

Java provides support for interacting with a program during runtime. The Open Source Physics library makes this interaction even easier, so that we can write programs that use a mouse to input data such as the location of a charge, or toggle the value of a cell in a lattice. We also do not need to input how long a simulation should run and can stop the program at any time to change parameters.

As with our previous editions, we assume no background in computer programming. Much of the text can be understood by students with only a semester each of physics and calculus. Chapter 2 introduces Java and the Open Source Physics library. In Chapter 3 we discuss the concept of interfaces and how to use some of the important interfaces in the Open Source Physics library. Later chapters introduce more Java and Open Source Physics constructs as needed, but essentially all of the chapters after Chapter 3 can be studied independently and in any order. We include many topics that are sometimes considered too advanced for undergraduates, such as random walks, chaos, fractals, percolation, simulations of many particle systems, and topics in the theory of complexity, but we introduce these topics so that very little background is required. Other chapters discuss optics, electrodynamics, relativity, rigid body motion, and quantum mechanics, which require knowledge of the physics found in the corresponding standard undergraduate courses.

This text is written so that the physics drives the choice of algorithms and the programming syntax that we discuss. We believe that students can learn how to program more quickly with this approach because they have an immediate context, namely doing simulations, in which to hone their skills. In the beginning most of the programming tasks involve modifying the programs in the text. Students should then be given some assignments that require them to write their own programs by following the format of those in the text. The students may later develop their own style as they work on their projects.

Our text is most appropriately used in a project oriented course that lets students with a wide variety of backgrounds and abilities work at their own pace. The courses that we have taught using this text have a laboratory component. From our experience we believe that active learning where students are directly grappling with the material in this text is the most efficient. In a laboratory context students who already know a programming language can help those who do not. Also, students can further contribute to a course by sharing their knowledge from various backgrounds in physics, chemistry, computer science, mathematics, biology, economics, and other subjects.

Although most of our text is at the undergraduate level, many of the topics are considered to be graduate level, and thus would be of interest to graduate students. One of us regularly teaches a laboratory-based course on computer simulation with both undergraduate and graduate students. Because the course is project-oriented, students can go at their own pace and work on different problems. In this context, graduate and undergraduate students can learn much from each other.

Some instructors who might consider using our text in a graduate level context might think that our text is not sufficiently rigorous. For example, in the suggested problems we usually do not explicitly ask students to do an extensive data analysis. However, we do discuss how to estimate errors in Chapter 11. We encourage instructors to ask for a careful data analysis on at least one assignment, but we believe that it is more important for students to spend most of their time in an exploratory mode where the focus is on gaining physical insight and obtaining numerical results that are qualitatively correct.

There are four types of suggested student activities. The exercises, which are primarily found in the beginning of the text, are designed to help students learn specific programming techniques. The problems, which are scattered throughout each chapter, are open-ended and require students to run, analyze, and modify programs given in the text, or write new, but similar programs. Students will soon learn that the format for most of the programs is very similar. Starred problems require either significantly more background or work, and may require the writing of a program from scratch. However, the programs for these problems still follow a similar format. The projects at the end of most of the chapters are usually more time consuming and would be appropriate for term projects or independent student research. Many new problems and projects have been added to this edition while others have been improved and some have been eliminated. Instructors and students should view the problem descriptions and questions as starting points for thinking about the system of interest. It is important that students read the problems even if they do not plan to do them.

We encourage instructors to ask students to write laboratory reports for at least some of the problems. The appendix to Chapter 1 provides guidance on what these reports should include. Part of the beauty and fun of doing computer simulations is that one is forced to think about the choice of algorithm, its implementation, the choice of parameters, what to measure, and the results. Do the results make sense? What happens if you change a parameter? What if you change the algorithm? Much physics can be learned in this way.

Although all the programs discussed in the text can be downloaded freely, most are listed in the text to encourage students to read them carefully. Students might find some useful techniques that they can use elsewhere, and the discussion in the text frequently refers to the listings.

A casual perusal of the text might suggest that the text is bereft of figures. One reason that we have not included more figures is that most of the programs in the text have an important visual component in color. Black and white figures pale in comparison. Much of the text is meant to be read while working on the programs. Thus, students can easily see the plots and animations produced by the programs while they are reading the text.

As new technologies become available and the backgrounds and expectations of students change, the question of what is worth knowing needs to be reconsidered. Today calculators not only do arithmetic and numerical operations, but most can do algebra, calculus, and plotting. Students have lost the sense of number and most can only do the simplest mathematical manipulations in their head. On the other hand, most students feel comfortable using computers and gathering information off the Web. Because there exist programs and applets that can perform many of the simulations in this text, why should students learn how to write their own programs? We have at least two answers. First, most innovative scientific research involves writing programs that do not fit into the domains of existing software. More importantly, we believe that students obtain a deeper understanding of the physics and the algorithms themselves by writing and modifying their own programs. Just as we need to insure that students can carry out basic mathematical operations without a calculator so that they understand what these operations mean, we must do the same when it comes to computational physics.

The recommended readings at the end of each chapter have been selected for their pedagogical value rather than for completeness or for historical accuracy. We apologize to our colleagues whose work has been inadvertently omitted, and we would appreciate suggestions for new and additional references.

Because students come with a different skill set than most of their instructors, it is important that instructors realize that certain aspects of this text might be easier for their students than for them. Some instructors might be surprised that much of the code for organizing the simulations is hidden in the Open Source Physics library (although the source code is freely available). Some instructors will initially think that Chapter 2 contains too much material. However, from the student's perspective this material is not that difficult to learn. They are used to downloading files, using various software environments, and learning how to make software do what they want. The difficult parts of the text, where instructor input is most needed, is understanding the physics and the algorithms. Converting algorithms to programs also is difficult for many students, and we spend much time in the text explaining the programs that implement various algorithms. In some cases instructors will find it difficult to set up an environment to use Java and the Open Source Physics library. Because this task depends on the operating system, we have placed instructions on how to set up an environment for Java and Open Source Physics at opensourcephysics.org. This web site also contains links to updates of the evolving Open Source Physics library as well as other resources for this text including the source code for the programs in the text.

We acknowledge generous support from the National Science Foundation which has allowed us to work on many ideas that have found their way into this textbook. We also thank Kipton Barros, Mario Belloni, Doug Brown, Francisco Esquembre, and Joshua Gould for their advice, suggestions, and contributions to the Open Source Physics library and to the text. We thank Anne Cox for suggesting numerous improvements to the narrative and for hosting an Open Source Physics developer's workshop at Eckerd College. We are especially thankful to students and faculty at Clark University, Davidson College, and Kalamazoo College who have generously commented on the Open Source Physics project as they class tested early versions of this manuscript. Carlos Ortiz helped prepare the index for this book.

Many individuals reviewed parts of the text and we thank them for their assistance. They include Lowell M. Boone, Roger Cowley, Shamanthi Fernando, Alejandro L. Garcia, Alexander L. Godunov, Rubin Landau, Donald G. Luttermoser, Cristopher Moore, Anders Sandvik, Ross Spencer, Dietrich Stauffer, Jutta Luettmer-Strathmann, Daniel Suson, Matthias Troyer, Slavomir Tuleja, and Michael T. Vaughn. We thank all our friends and colleagues for their encouragement and support.

We are grateful to our wives, Patti Gould, Andrea Moll Tobochnik, and Barbara Christian, and to our children, Joshua, Emily, and Evan Gould, Steven and Howard Tobochnik, and Katherine, Charlie, and Konrad Christian for their encouragement and understanding during the course of this work. It takes a village to raise a child and a community to write a textbook.

No book of this length can be free of typos and errors. We encourage readers to email us about errors that they find and suggestions for improvements. Our plan is to continuously revise our book, so that the next edition will be more timely.

Harvey Gould
Clark University
Worcester, MA 01610
hgould@clarku.edu

Jan Tobochnik
Kalamazoo College
Kalamazoo, MI 49006-3295
jant@kzoo.edu

Wolfgang Christian
Davidson College
Davidson, NC 28036-6926
wochristian@davidson.edu