You are on page 1of 9

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/265022969

An Introduction to Computer Simulation Methods

Article · January 1988

CITATIONS READS

321 15,736

3 authors:

Harvey Gould Jan Tobochnik


Clark University Rutgers, The State University of New Jersey
149 PUBLICATIONS   11,197 CITATIONS    114 PUBLICATIONS   6,597 CITATIONS   

SEE PROFILE SEE PROFILE

Wolfgang Christian
Davidson College
118 PUBLICATIONS   8,749 CITATIONS   

SEE PROFILE

All content following this page was uploaded by Wolfgang Christian on 11 May 2015.

The user has requested enhancement of the downloaded file.


An Introduction to Computer Simulation
Methods

Harvey Gould, Jan Tobochnik, and Wolfgang Christian

July 31, 2005


Contents

1 Introduction 8
1.1 Importance of computers in physics . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 The importance of computer simulation . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3 Programming languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4 Object oriented techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.5 How to use this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2 Tools for Doing Simulations 19


2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2 Simulating free fall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.3 Getting started with object oriented programming . . . . . . . . . . . . . . . . . . 27
2.4 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.5 The Open Source Physics library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.6 Animation and Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.7 Model-View-Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

3 Simulating Particle Motion 54


3.1 Modified Euler algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.2 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.3 Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.4 Specifying the state of a system using arrays . . . . . . . . . . . . . . . . . . . . . 61
3.5 The ODE interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.6 The ODESolver interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.7 Effects of Drag Resistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.8 Two-Dimensional Trajectories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.9 Decay processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.10 ∗ Visualizing Three-Dimensional Motion . . . . . . . . . . . . . . . . . . . . . . . . 78

1
CONTENTS 2

3.11 Levels of Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

4 Oscillations 95
4.1 Simple Harmonic Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.2 The Motion of a Pendulum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.3 Damped Harmonic Oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.4 Response to External Forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
4.5 Electrical Circuit Oscillations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
4.6 Accuracy and Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
4.7 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

5 Few-Body Problems: The Motion of the Planets 118


5.1 Planetary Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
5.2 The Equations of Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
5.3 Circular and Elliptical Orbits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.4 Astronomical Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.5 Log-log and Semilog Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
5.6 Simulation of the Orbit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
5.7 Impulsive Forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
5.8 Velocity Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
5.9 A Mini-Solar System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
5.10 Two-Body Scattering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
5.11 Three-body problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
5.12 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

6 The Chaotic Motion of Dynamical Systems 154


6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
6.2 A Simple One-Dimensional Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
6.3 Period Doubling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
6.4 Universal Properties and Self-Similarity . . . . . . . . . . . . . . . . . . . . . . . . 166
6.5 Measuring Chaos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
6.6 *Controlling Chaos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
6.7 Higher-Dimensional Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
6.8 Forced Damped Pendulum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
6.9 *Hamiltonian Chaos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
6.10 Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
6.11 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
CONTENTS 3

7 Random Processes 212


7.1 Order to Disorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
7.2 Random Walks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
7.3 Modified Random Walks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
7.4 The Poisson Distribution and Nuclear Decay . . . . . . . . . . . . . . . . . . . . . 232
7.5 Problems in Probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
7.6 Method of Least Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
7.7 Applications to Polymers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
7.8 Diffusion Controlled Chemical Reactions . . . . . . . . . . . . . . . . . . . . . . . . 249
7.9 Random Number Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
7.10 Variational Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
7.11 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Appendix 10: Random Walks and the Diffusion Equation . . . . . . . . . . . . . . . . . 265

8 The Dynamics of Many Particle Systems 272


8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
8.2 The Intermolecular Potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
8.3 Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
8.4 The Numerical Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
8.5 Periodic Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
8.6 A Molecular Dynamics Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
8.7 Thermodynamic Quantities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
8.8 Radial Distribution Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
8.9 Hard disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
8.10 Dynamical Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
8.11 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
8.12 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

9 Normal Modes and Waves 332


9.1 Coupled Oscillators and Normal Modes . . . . . . . . . . . . . . . . . . . . . . . . 332
9.2 Numerical Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
9.3 Fourier Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
9.4 Two-Dimensional Fourier Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
9.5 Fourier Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
9.6 Power Spectrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
9.7 Wave Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
9.8 Interference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
CONTENTS 4

9.9 Fraunhofer Diffraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371


9.10 Fresnel Diffraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Appendix 9A: Complex Fourier Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Appendix 9B: Fast Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Appendix 9C: Plotting Scalar Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382

10 Electrodynamics 386
10.1 Static Charges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
10.2 Electric Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
10.3 Electric Field Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
10.4 Electric Potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
10.5 Numerical Solutions of Boundary Value Problems . . . . . . . . . . . . . . . . . . . 399
10.6 Random Walk Solution of Laplace’s Equation . . . . . . . . . . . . . . . . . . . . . 408
10.7 *Fields Due to Moving Charges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
10.8 *Maxwell’s Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
10.9 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Appendix A: Plotting Vector Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429

11 Numerical and Monte Carlo Methods 433


11.1 Numerical Integration Methods in One Dimension . . . . . . . . . . . . . . . . . . 433
11.2 Simple Monte Carlo Evaluation of Integrals . . . . . . . . . . . . . . . . . . . . . . 443
11.3 Multidimensional Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
11.4 Monte Carlo Error Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
11.5 Nonuniform Probability Distributions . . . . . . . . . . . . . . . . . . . . . . . . . 451
11.6 Importance Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
11.7 Metropolis Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
11.8 *Neutron Transport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459

12 Percolation 474
12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
12.2 The Percolation Threshold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
12.3 Finding Clusters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
12.4 Critical Exponents and Finite Size Scaling . . . . . . . . . . . . . . . . . . . . . . . 494
12.5 The Renormalization Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
12.6 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
CONTENTS 5

13 Fractals and Kinetic Growth Models 514


13.1 The Fractal Dimension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
13.2 Regular Fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
13.3 Kinetic Growth Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
13.4 Fractals and Chaos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
13.5 Many Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
13.6 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547

14 Complex Systems 554


14.1 Cellular Automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
14.2 Self-Organized Critical Phenomenon . . . . . . . . . . . . . . . . . . . . . . . . . . 568
14.3 The Hopfield Model and Neural Networks . . . . . . . . . . . . . . . . . . . . . . . 576
14.4 Growing Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
14.5 Genetic Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
14.6 Lattice Gas Models of Fluid Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
14.7 Overview and Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605

15 Monte Carlo Simulations of Thermal Systems 617


15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
15.2 The Microcanonical Ensemble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
15.3 The Demon Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
15.4 The Demon as a Thermometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
15.5 The Ising Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
15.6 The Metropolis Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
15.7 Simulation of the Ising Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
15.8 The Ising Phase Transition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
15.9 Other Applications of the Ising Model . . . . . . . . . . . . . . . . . . . . . . . . . 651
15.10Simulation of Classical Fluids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
15.11Optimized Monte Carlo Data Analysis . . . . . . . . . . . . . . . . . . . . . . . . . 661
15.12∗ Other Ensembles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666
15.13More Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
15.14Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
CONTENTS 6

16 Quantum Systems 701


16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
16.2 Review of Quantum Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702
16.3 Bound State Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707
16.4 Time Development of Eigenstate Superpositions . . . . . . . . . . . . . . . . . . . . 712
16.5 The Time-Dependent Schrödinger Equation . . . . . . . . . . . . . . . . . . . . . . 718
16.6 Fourier Transformations and Momentum Space . . . . . . . . . . . . . . . . . . . . 724
16.7 Variational Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
16.8 Random Walk Solutions of the Schrödinger Equation . . . . . . . . . . . . . . . . . 730
16.9 Diffusion Quantum Monte Carlo . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736
16.10Path Integral Quantum Monte Carlo . . . . . . . . . . . . . . . . . . . . . . . . . . 740
16.11Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743
Appendix A: Visualizing Complex Functions . . . . . . . . . . . . . . . . . . . . . . . . 745

17 Visualization and Rigid Body Dynamics 751


17.1 Two-Dimensional Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . 751
17.2 Three-Dimensional Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . 756
17.3 The Three-DimensionalOpen Source Physics Library . . . . . . . . . . . . . . . . . 761
17.4 Dynamics of a Rigid Body . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765
17.5 Quaternion Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769
17.6 Quaternion equations of motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772
17.7 Rigid Body Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 778
17.8 Motion of a spinning top . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783
17.9 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 786

18 Seeing in Special and General Relativity 794


18.1 Special Relativity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794
18.2 General Relativity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799
18.3 Dynamics in Polar Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
18.4 Black Holes and Schwarzschild Coordinates . . . . . . . . . . . . . . . . . . . . . . 802
18.5 Particle and Light Trajectories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804
18.6 Seeing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
18.7 General Relativistic Dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
18.8 ∗ The Kerr Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
18.9 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809
18.10References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809
View publication stats

CONTENTS 7

19 Epilogue: The Unity of Physics 811


19.1 The Unity of Physics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 811
19.2 Spiral Galaxies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812
19.3 Numbers, Pretty Pictures, and Insight . . . . . . . . . . . . . . . . . . . . . . . . . 814
19.4 Constrained Dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816
19.5 What are Computers Doing to Physics? . . . . . . . . . . . . . . . . . . . . . . . . 819

You might also like