Preface to the First Edition

Computer simulation is now an integral part of contemporary basic and applied science and is approaching a role equal in importance to the traditional experimental and theoretical approaches. Hence, the ability to compute is part of the essential repertoire of research scientists and educators.

The philosophy of this book is expressed well by the Chinese proverb (source unknown to us):

I hear and I forget. I see and I remember. I do and I understand.

We ask not how can the computer be used to teach physics, but how can students be trained to teach the computer. Our primary goal is to create an environment in which the reader teaches the computer to simulate physical systems. Our experience is that an active involvement with computer simulations leads to a greater intuitive understanding of physical concepts. Other goals of the book are to introduce molecular dynamics and Monte Carlo methods, to integrate simple but realistic research-type problems into the undergraduate curriculum, and to teach by example structured programming techniques.

Much of the material in this text has been used in a one semester course entitled Computer Simulation Laboratory offered at Clark University. Prerequisites for the course are one semester each of physics and calculus. A background in computer programming is not necessary. The interests of the undergraduate and graduate students in the course have included physics, chemistry, biology, mathematics, computer science, geography and electrical engineering. The physics and programming background of these students has ranged from minimal to extensive. We have found that many computer simulations are accessible to those with a limited background in physics and that students with a stronger background can gain additional insight into material that they have already studied. The course is organized in the same way as other laboratory courses at Clark with two weekly lectures in which the subject matter is presented and student progress is reviewed. Programming methods are introduced in the context of a regularly scheduled laboratory. The course is project oriented and allows students the freedom to work at their own pace and to pursue problems consistent with their own interests and backgrounds.

We believe that computer simulation has become sufficiently important for courses of this kind to be taught at other institutions. However, other uses of this book might work equally well. For example, this book could be used as a supplement to an introductory physics course for honors students and in intermediate level courses on classical mechanics, waves, electricity and magnetism, statistical and thermal physics, quantum mechanics, and physical chemistry. The text can also form the basis of a numerical methods course. Although the book begins with basic concepts in physics and calculus, we believe that in general the most successful use of the book will be at the intermediate level.

The programming language used in the body of the text is True BASIC. Translations of several of the programs into Pascal and FORTRAN 77 are listed in the appendices to each part of the book. True BASIC is our language of choice because it is easy to learn and use, has true subroutines, excellent graphics capabilities, and is identical on the IBM PC and compatible computers and the Apple Macintosh computer. Readers familiar with street BASIC should have few problems adapting the programs in the text as long as they clearly distinguish local and global variables. In our view, the similarities of BASIC, FORTRAN and Pascal are much greater than their differences.

We believe you can learn programming the same way we did---in the context of a discipline. Although the book is as independent as possible of any particular brand of computer, we strongly recommend that readers with little programming experience should write their programs on a personal computer. Personal computers are easier to use than mainframe computers and also offer readily available graphics capabilities. The problems in the text should be done with a programming manual and a physics text as handy references.

Each chapter contains a brief discussion of the important physical concepts, followed by program listings, problems, and relevant questions. The discussion, programs and problems are interrelated and the discussions will be more readily understood after the problems are completed. We regard the program listings as text for the reader rather than source code for the computer. Our programs are designed to be simple and easy to read, rather than elegant or efficient. To do most of the problems, the reader must understand the logic of the programs and hence the logic of the underlying physical system. Most of the problems require at least some modification of the programs. We believe that typing in the programs line-by-line will help you learn programming more easily. Most of the programs are short and you are encouraged to change the programs. The problems are organized so that the earlier ones in a chapter provide the basis for the later problems in the same chapter and in following chapters. Problems denoted by an asterisk are either more advanced or require significantly more time than the average problem and are not a prerequisite for work in succeeding chapters. 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.

We emphasize classical physics in Part I and statistical physics in Part II. These areas reflect our own research interests but also are areas in which the methods of computer simulation can be introduced most easily. We also discuss waves, optical phenomena, electricity and magnetism, and quantum mechanics. Each part of the book contains enough material for a semester course on computer simulation. Part I of the text emphasizes the simulation of deterministic systems. Chapter 1 discusses the uses of the computer in physics and the nature of several popular computer languages. Chapter 2 introduces the Euler method for the numerical integration of first order differential equations. Since many readers are familiar with the Euler method, the main purpose of the chapter is to introduce the core syntax of True BASIC. Although this introduction might cover too much material for those without programming experience, remarkably little additional syntax is used in the remainder of the text. Chapters 3--5 use a modified form of the Euler method to simulate falling objects, planetary motion, and oscillatory motion. Chapter 5 also includes a section on electrical circuits and an appendix on other numerical methods for the solution of Newton's equation of motion. Chapter 6 introduces the method of molecular dynamics. Unless the reader has access to large scale computing (or the next generation of microcomputers), only a qualitative picture of thermal phenomena can be obtained from the simulations. However this method is important in physics and chemical physics and the ideas underlying it are straightforward extensions of the previous chapters. Chapter 7 introduces non-linear dynamical systems and the use of the computer to discover new knowledge. Chapters 8 and 9 mainly contain traditional material on oscillations and waves, and electrostatics and magnetostatics. Much of the material in these two chapters is oriented toward visual demonstrations.

Each chapter in Part II of the text applies a random sampling technique, known generally as Monte Carlo methods, to problems in statistical physics and quantum mechanics. Chapter 10 introduces Monte Carlo methods in the context of numerical integration. Although this chapter does not directly discuss physical phenomena, it allows us to survey the various methods in a well known context. Chapter 11 is devoted to random walks and their application to physical phenomena. Chapters 12 and 13 treat current research areas which are becoming important in many fields of science. In these chapters we discuss percolation, simple ideas of phase transitions and the renormalization group, fractals, local growth laws, and cellular automata. Many of the applications are not difficult to formulate but yield complex behavior which is visually interesting. Chapter 14 discusses an example of the approach to equilibrium and methods for computing the entropy. Chapter 15 uses a relatively new method to simulate the microcanonical ensemble and to discover the canonical Boltzmann distribution. Chapter 16 introduces Monte Carlo methods for simulating thermal systems. In Chapter 17 we discuss Monte Carlo and more traditional numerical methods for treating quantum systems. Chapter 18 briefly discusses how the same methods can solve many apparently unrelated problems.

The availability of personal computers and the demands from industry for meaningful computer literacy is putting pressure on all disciplines to incorporate computer related material into the basic curriculum. Thus far, most physics departments have used computers as a tool for data analysis and for demonstrations. Some physics departments now offer courses in computational physics and in measurement and control processes. However, the impact on the curriculum as measured by greater student understanding, increased numbers of physics students, or changes in textual material has been negligible. We realize that the nontrivial use of computers in physics education will take many years to accomplish. We hope that this book makes a contribution to that end, and we welcome your comments, suggestions and encouragement.

We have taken care to check our programs for errors and typos. It is our experience however that few programs remain error free forever, and we make no guarantee that the programs in this text are totally free of error. Instructors who adopt this book for a course may request a program disk (IBM PC or Macintosh format) at no charge from Addison-Wesley.

Many colleagues and students have generously commented on preliminary drafts of chapters of the manuscript and have given general encouragement and advice. We particularly wish to thank Harold Abelson, David Ben Avraham, John Davies, Hugh DeWitt, Lisa Dundon, Fereydoon Family, Jim Gi-ven, Jim Gunton, Marilyn Jimenez, Gabor Kalman, Tom Keyes, Robert Kilmoyer, Bill Klein, Roger Kohin, Christopher Landee, Francois Leyvraz, Jon Machta, Gene Mazenko, Bill Michalson, Robert Pelcovits, Joseph Priest, Stan Rajnak, Sidney Redner, Peter Reynolds, Qun Ru, David Stork, Oriol Valls, Gerard Vichniac, George Weiss, Pieter Visscher, and Ju-xing Yang. Needless to say, all errors, omissions and unclear passages are our responsibility.

The course on which this book is based could not have been developed without an initial donation of personal computers from IBM to Clark University and a small grant for course development from the National Science Foundation. One of us also wishes to thank the Mellon Committee of Clark University for support of curriculum development and the Digital Equipment Corporation for support of a related project involving the incorporation of computers into the undergraduate curriculum. We would also like to acknowledge the hospitality of the Department of Physics at Boston University where parts of the book were written.

Special thanks go to Stacey Bressler, Sherry Howlett, and Greg Smedsrud of the Apple Computer Corporation for their interest in our project. It would be difficult to imagine writing this book without the use of a Macintosh computer and an Apple LaserWriter, both donated to us by the Apple Computer Corporation. Many thanks are due to Bruce Spatz, former science editor at Addison-Wesley, for his support, interest, and patience, Sharon Van Gundy for finding some of our grammatical errors and to Mona Zeftel for producing the manuscript in camera-ready form. The text was produced using Textures and MacWrite; the figures were drawn by the authors using MacPaint, MacDraw, and Cricket Graph.

We are grateful to our wives, Patti Gould and Andrea Moll Tobochnik, and to the Gould children, Joshua, Emily and Evan, for their encouragement and understanding during the course of this work.