Computational Physics
Computational Physics
Problem Solving with Computers
RUBIN H. LANDAU
Professor of Physics
Oregon State University
´
MANUEL JOSE´ PAEZ
MEJI´ A
Professor of Physics
University of Antioquia
Contributors
Hans Kowallik and Henri Jansen
A Wiley-Interscience Publication
JOHN WILEY & SONS, INC.
New York / Chichester / Weinheim / Brisbane / Singapore / Toronto
v
With memory of Bertha Israel Landau
and “how’s your book coming along?”
Contents
Preface
xxi
Acknowledgments
xxv
Acronyms
xxvii
Part I GENERALITIES
1 Introduction
1.1 The Nature of Computational Science
1.1.1 How Computational Scientists Do It
1.2 Aims of This Book
1.3 Using this Book with the Disk and Web
2 Computing Software Basics
2.1 Problem 1: Making Computers Obey
2.2 Theory: Computer Languages
2.3 Implementation: Programming Concepts
2.4 Implementation: Fortran, area.f
2.5 Implementation: C, area.c
2.6 Implementation: Shells, Editors, and Programs
3
3
4
5
6
9
9
9
11
12
13
13
vii
viii
CONTENTS
2.7
2.8
2.9
2.10
2.11
2.12
2.13
2.14
2.15
2.16
2.17
2.18
2.19
2.20
2.21
2.22
2.23
2.24
2.25
Theory: Program Design
Method: Structured Programming
Method: Programming Hints
Problem 2: Limited Range of Numbers
Theory: Number Representation
Method: Fixed and Floating
Implementation: Over/Underflows, over.f (.c)
Model: Machine Precision
Implementation: limit.f (.c)
Problem 3: Complex Numbers, Inverse Functions
Theory: Complex Numbers
Implementation: complex.c (.f)
Exploration: Quantum Complex Energies
Problem 4: Summing Series
Method: Numeric
Implementation: Pseudocode
Implementation: Good Algorithm, exp-good.f (.c)
Implementation: Bad Algorithm, exp-bad.f (.c)
Assessment
14
16
18
20
20
21
23
23
24
25
25
27
28
29
29
29
30
30
30
3 Errors and Uncertainties in Computations
3.1 Problem: Living with Errors
3.2 Theory: Types of Errors
3.3 Model: Subtractive Cancellation
3.4 Assessment: Cancellation Experiment
3.5 Model: Multiplicative Errors
3.6 Problem 1: Errors in Spherical Bessel Functions
3.7 Method: Numeric Recursion Relations
3.8 Implementation: bessel.f (.c)
3.9 Assessment
3.10 Problem 2: Errors in Algorithms
3.11 Model: Errors in Algorithms
3.11.1 Total Error
3.12 Method: Optimizing with Known Error Behavior
3.13 Method: Empirical Error Analysis
3.14 Assessment: Experiment
31
31
32
33
34
36
37
38
40
40
40
41
41
42
43
44
4 Integration
4.1 Problem: Integrating a Spectrum
47
47
CONTENTS
4.2
4.3
4.4
4.5
4.6
Model: Quadrature, Summing Boxes
Method: Trapezoid Rule
Method: Simpson’s Rule
Assessment: Integration Error, Analytic
Method: Gaussian Quadrature
4.6.1 Scaling Integration Points
4.7 Implementation: integ.f (.c)
4.8 Assessment: Empirical Error Estimate
4.9 Assessment: Experimentation
4.10 Method: Romberg Extrapolation
4.10.1 Other Closed Newton–Cotes Formulas
Part II
ix
47
50
51
52
55
56
58
58
59
59
60
APPLICATIONS
5 Data Fitting
5.1 Problem: Fitting an Experimental Spectrum
5.2 Theory: Curve Fitting
5.3 Method: Lagrange Interpolation
5.3.1 Example
5.4 Implementation: lagrange.f (.c)
5.5 Assessment: Interpolating a Resonant Spectrum
5.6 Assessment: Exploration
5.7 Method: Cubic Splines
5.7.1 Cubic Spline Boundary Conditions
5.7.2 Exploration: Cubic Spline Quadrature
5.8 Implementation: spline.f
5.9 Assessment: Spline Fit of Cross Section
5.10 Problem: Fitting Exponential Decay
5.11 Model: Exponential Decay
5.12 Theory: Probability Theory
5.13 Method: Least-Squares Fitting
5.14 Theory: Goodness of Fit
5.15 Implementation: Least-Squares Fits, fit.f (.c)
5.16 Assessment: Fitting Exponential Decay
5.17 Assessment: Fitting Heat Flow
5.18 Implementation: Linear Quadratic Fits
5.19 Assessment: Quadratic Fit
5.20 Method: Nonlinear Least-Squares Fitting
63
63
64
65
66
66
67
68
68
69
70
71
71
71
71
73
74
76
77
78
80
81
82
82
x
CONTENTS
5.21 Assessment: Nonlinear Fitting
6 Deterministic Randomness
6.1 Problem: Deterministic Randomness
6.2 Theory: Random Sequences
6.3 Method: Pseudo-Random-Number Generators
6.4 Assessment: Random Sequences
6.5 Implementation: Simple and Not
random.f (.c); call.f (.c)
6.6 Assessment: Randomness and Uniformity
6.7 Assessment: Tests of Randomness, Uniformity
6.8 Problem: A Random Walk
6.9 Model: Random Walk Simulation
6.10 Method: Numerical Random Walk
6.11 Implementation: walk.f (.c)
6.12 Assessment: Different Random Walkers
7 Monte Carlo Applications
7.1 Problem: Radioactive Decay
7.2 Theory: Spontaneous Decay
7.3 Model: Discrete Decay
7.4 Model: Continuous Decay
7.5 Method: Decay Simulation
7.6 Implementation: decay.f (.c)
7.7 Assessment: Decay Visualization
7.8 Problem: Measuring by Stone Throwing
7.9 Theory: Integration by Rejection
7.10 Implementation: Stone Throwing, pond.f (.c)
7.11 Problem: High-Dimensional Integration
7.12 Method: Integration by Mean Value
7.12.1 Multidimensional Monte Carlo
7.13 Assessment: Error in N-D Integration
7.14 Implementation: 10-D Integration, int 10d.f (.c)
7.15 Problem: Integrate a Rapidly Varying Function¬
7.16 Method: Variance Reduction¬
7.17 Method: Importance Sampling¬
7.18 Implementation: Nonuniform Randomness¬
7.18.1 Inverse Transform Method
7.18.2 Uniform Weight Function w
82
83
83
83
84
86
87
87
88
89
89
90
91
91
93
93
93
94
95
95
97
97
97
97
98
99
99
101
101
101
102
102
103
103
103
105
CONTENTS
xi
7.18.3 Exponential Weight
7.18.4 Gaussian (Normal) Distribution
7.18.5 Alternate Gaussian Distribution
7.19 Method: von Neumann Rejection¬
7.20 Assessment¬
105
106
107
107
108
8 Differentiation
8.1 Problem 1: Numerical Limits
8.2 Method: Numeric
8.2.1 Method: Forward Difference
8.2.2 Method: Central Difference
8.2.3 Method: Extrapolated Difference
8.3 Assessment: Error Analysis
8.4 Implementation: Differentiation, diff.f (.c)
8.5 Assessment: Error Analysis, Numerical
8.6 Problem 2: Second Derivatives
8.7 Theory: Newton II
8.8 Method: Numerical Second Derivatives
8.9 Assessment: Numerical Second Derivatives
109
109
109
109
111
111
112
113
113
114
114
114
115
9 Differential Equations and Oscillations
9.1 Problem: A Forced Nonlinear Oscillator
9.2 Theory, Physics: Newton’s Laws
9.3 Model: Nonlinear Oscillator
9.4 Theory, Math: Types of Equations
9.4.1 Order
9.4.2 Ordinary and Partial
9.4.3 Linear and Nonlinear
9.4.4 Initial and Boundary Conditions
9.5 Theory, Math, and Physics:
The Dynamical Form for ODEs
9.5.1 Second-Order Equation
9.6 Implementation: Dynamical Form for Oscillator
9.7 Numerical Method: ODE Algorithms
9.8 Method (Numerical): Euler’s Algorithm
9.9 Method (Numerical): Second-Order Runge–Kutta
9.10 Method (Numerical): Fourth-Order Runge–Kutta
9.11 Implementation: ODE Solver, rk4.f (.c)
9.12 Assessment: rk4 and Linear Oscillations
117
117
117
118
119
119
120
121
121
122
122
123
124
124
126
127
127
128
xii
CONTENTS
9.13 Assessment: rk4 and Nonlinear Oscillations
9.14 Exploration: Energy Conservation
128
129
10 Quantum Eigenvalues; Zero-Finding and Matching
10.1 Problem: Binding A Quantum Particle
10.2 Theory: Quantum Waves
10.3 Model: Particle in a Box
10.4 Solution: Semianalytic
10.5 Method: Finding Zero via Bisection Algorithm
10.6 Method: Eigenvalues from an ODE Solver
10.6.1 Matching
10.7 Implementation: ODE Eigenvalues, numerov.c
10.8 Assessment: Explorations
10.9 Extension: Newton’s Rule for Finding Roots
131
131
132
133
133
136
136
138
139
141
141
11 Anharmonic Oscillations
11.1 Problem 1: Perturbed Harmonic Oscillator
11.2 Theory: Newton II
11.3 Implementation: ODE Solver, rk4.f (.c)
11.4 Assessment: Amplitude Dependence of Frequency
11.5 Problem 2: Realistic Pendulum
11.6 Theory: Newton II for Rotations
11.7 Method, Analytic: Elliptic Integrals
11.8 Implementation, rk4 for Pendulum
11.9 Exploration: Resonance and Beats
11.10 Exploration: Phase-Space Plot
11.11 Exploration: Damped Oscillator
143
143
144
144
145
145
146
147
147
148
149
150
12 Fourier Analysis of Nonlinear Oscillations
12.1 Problem 1: Harmonics in Nonlinear Oscillations
12.2 Theory: Fourier Analysis
12.2.1 Example 1: Sawtooth Function
12.2.2 Example 2: Half-Wave Function
12.3 Assessment: Summation of Fourier Series
12.4 Theory: Fourier Transforms
12.5 Method: Discrete Fourier Transform
12.6 Method: DFT for Fourier Series
12.7 Implementation: fourier.f (.c), invfour.c
12.8 Assessment: Simple Analytic Input
151
151
152
154
154
155
156
157
161
162
162
CONTENTS
12.9 Assessment: Highly Nonlinear Oscillator
12.10 Assessment: Nonlinearly Perturbed Oscillator
12.11 Exploration: DFT of Nonperiodic Functions
12.12 Exploration: Processing Noisy Signals
12.13 Model: Autocorrelation Function
12.14 Assessment: DFT and Autocorrelation Function
12.15 Problem 2: Model Dependence of Data Analysis ¬
12.16 Method: Model-Independent Data Analysis
12.17 Assessment
xiii
163
163
164
164
164
166
166
167
169
13 Unusual Dynamics of Nonlinear Systems
13.1 Problem: Variability of Bug Populations
13.2 Theory: Nonlinear Dynamics
13.3 Model: Nonlinear Growth, The Logistic Map
13.3.1 The Logistic Map
13.4 Theory: Properties of Nonlinear Maps
13.4.1 Fixed Points
13.4.2 Period Doubling, Attractors
13.5 Implementation: Explicit Mapping
13.6 Assessment: Bifurcation Diagram
13.7 Implementation: bugs.f (.c)
13.8 Exploration: Random Numbers via Logistic Map
13.9 Exploration: Feigenbaum Constants
13.10 Exploration: Other Maps
171
171
171
172
173
174
174
175
176
177
178
179
179
180
14 Differential Chaos in Phase Space
14.1 Problem: A Pendulum Becomes Chaotic
14.2 Theory and Model: The Chaotic Pendulum
14.3 Theory: Limit Cycles and Mode Locking
14.4 Implementation 1: Solve ODE, rk4.f (.c)
14.5 Visualization: Phase-Space Orbits
14.6 Implementation 2: Free Oscillations
14.7 Theory: Motion in Phase Space
14.8 Implementation 3: Chaotic Pendulum
14.9 Assessment: Chaotic Structure in Phase Space
14.10 Assessment: Fourier Analysis
14.11 Exploration: Pendulum with Vibrating Pivot
14.11.1 Implementation: Bifurcation Diagram
14.12 Further Explorations
181
181
182
183
184
184
187
188
188
191
191
192
193
194
xiv
CONTENTS
15 Matrix Computing and Subroutine Libraries
15.1 Problem 1: Many Simultaneous Linear Equations
15.2 Formulation: Linear into Matrix Equation
15.3 Problem 2: Simple but Unsolvable Statics
15.4 Theory: Statics
15.5 Formulation: Nonlinear Simultaneous Equations
15.6 Theory: Matrix Problems
15.6.1 Classes of Matrix Problems
15.7 Method: Matrix Computing
15.8 Implementation: Scientific Libraries, WWW
15.9 Implementation: Determining Availability
15.9.1 Determining Contents of a Library
15.9.2 Determining the Needed Routine
15.9.3 Calling LAPACK from Fortran, lineq.c
15.9.4 Calling LAPACK from C
15.9.5 Calling LAPACK Fortran from C
15.9.6 C Compiling Calling Fortran
15.10 Extension: More Netlib Libraries
15.10.1 SLATEC’s Common Math Library
15.11 Exercises: Testing Matrix Calls
15.12 Implementation: LAPACK Short Contents
15.13 Implementation: Netlib Short Contents
15.14 Implementation: SLATEC Short Contents
197
197
198
198
199
199
200
201
203
207
209
210
210
211
212
213
214
214
215
216
218
221
222
16 Bound States in Momentum Space
16.1 Problem: Bound States in Nonlocal Potentials
16.2 Theory: k-Space Schr o¨ dinger Equation
16.3 Method: Reducing Integral to Linear Equations
16.4 Model: The Delta-Shell Potential
16.5 Implementation: Binding Energies, bound.c (.f)
16.6 Exploration: Wave Function
231
231
232
233
235
236
237
17 Quantum Scattering via Integral Equations¬
17.1 Problem: Quantum Scattering in k Space
17.2 Theory: Lippmann–Schwinger Equation
17.3 Theory (Mathematics): Singular Integrals
17.3.1 Numerical Principal Values
17.4 Method: Converting Integral to Matrix Equations
17.4.1 Solution via Inversion or Elimination
239
239
240
241
242
243
245
CONTENTS
xv
17.4.2 Solving ¯ Integral Equations ¬
17.5 Implementation: Delta-Shell Potential, scatt.f
17.6 Exploration: Scattering Wave Function
245
246
248
18 Computing Hardware Basics: Memory and CPU
18.1 Problem: Speeding Up Your Program
18.2 Theory: High-Performance Components
18.2.1 Memory Hierarchy
18.2.2 The Central Processing Unit
18.2.3 CPU Design: RISC
18.2.4 CPU Design: Vector Processing
18.2.5 Virtual Memory
18.3 Method: Programming for Virtual Memory
18.4 Implementation: Good, Bad Virtual Memory Use
18.5 Method: Programming for Data Cache
18.6 Implementation 1: Cache Misses
18.7 Implementation 2: Cache Flow
18.8 Implementation 3: Large Matrix Multiplication
249
249
250
250
253
254
254
255
256
257
258
260
260
261
19 High-Performance Computing: Profiling and Tuning
19.1 Problem: Effect of Hardware on Performance
19.2 Method: Tabulating Speedups
19.3 Implementation 1: Baseline Program, tune.f
19.4 Method: Profiling
19.5 Implementation 2: Basic Optimization, tune1.f
19.6 Implementation 2: Vector Tuning, tune2.f
19.7 Implementation 3: Vector Code on RISC, tune3.f
19.8 Implementation 4: Superscalar Tuning, tune4.f
19.9 Assessment
263
263
263
264
265
266
269
270
271
273
20 Parallel Computing and PVM
20.1 Problem: Speeding Up Your Program
20.2 Theory: Parallel Semantics
20.2.1 Parallel Instruction and Data Streams
20.2.2 Granularity
20.2.3 Parallel Performance
20.3 Method: Multitasking Programming
20.3.1 Method: Multitask Organization
20.4 Method: Distributed Memory Programming
275
275
276
276
277
277
278
278
279
xvi
CONTENTS
20.5 Implementation: PVM Bug Populations, WWW
20.5.1 The Plan
280
280
21 Object-Oriented Programming: Kinematics ¬
21.1 Problem: Superposition of Motions
21.2 Theory: Object-Oriented Programming
21.2.1 OOP Fundamentals
21.3 Theory: Newton’s Laws, Equation of Motion
21.4 OOP Method: Class Structure
21.5 Implementation: Uniform 1-D Motion,
unim1d.cpp
21.5.1 Uniform Motion in 1-D, Class Um1D
21.5.2 Implementation: Uniform Motion in 2-D, Child
Um2D, unimot2d.cpp
21.5.3 Class Um2D: Uniform Motion in 2-D
21.5.4 Implementation: Projectile Motion, Child Accm2D,
accm2d.cpp
21.5.5 Accelerated Motion in Two Directions
21.6 Assessment: Exploration, shms.cpp
291
293
295
22 Thermodynamic Simulations: The Ising Model
22.1 Problem: Hot Magnets
22.2 Theory: Statistical Mechanics
22.3 Model: An Ising Chain
22.4 Solution, Analytic
22.5 Solution, Numerical: The Metropolis Algorithm
22.6 Implementation: ising.f (.c)
22.7 Assessment: Approach to Thermal Equilibrium
22.8 Assessment: Thermodynamic Properties
22.9 Exploration: Beyond Nearest Neighbors
22.10 Exploration: 2-D and 3-D Ising Models
297
297
297
299
301
301
304
305
305
307
307
23 Functional Integration on Quantum Paths¬
23.1 Problem: Relate Quantum to Classical Trajectory
23.2 Theory: Feynman’s Spacetime Propagation
23.3 Analytic Method: Bound-State Wave Function
23.4 Numerical Method: Lattice Path Integration
23.5 Method: Lattice Computation of Propagators
23.6 Implementation: qmc.f (.c)
309
309
309
312
314
316
319
283
283
284
284
285
285
286
287
288
289
CONTENTS
23.7 Assessment and Exploration
24 Fractals
24.1 Problem: Fractals
24.2 Theory: Fractional Dimension
24.3 Problem 1: The Sierpin´ ski Gasket
24.4 Implementation: sierpin.c
24.5 Assessment: Determining a Fractal Dimension
24.6 Problem 2: How to Grow Beautiful Plants
24.7 Theory: Self-Affine Connections
24.8 Implementation: Barnsley’s Fern, fern.c
24.9 Exploration: Self-Affinity in Trees
24.10 Implementation: Nice Trees, tree.c
24.11 Problem 3: Ballistic Deposition
24.12 Method: Random Depositions
24.13 Implementation: Ballistic Deposition, film.c
24.14 Problem 4: Length of the Coastline of Britain
24.15 Model: The Coast as a Fractal
24.16 Method: Box Counting
24.17 Problem 5: Correlated Growth, Forests and Films
24.18 Method: Correlated Ballistic Deposition
24.19 Implementation: column.c
24.20 Problem 6: A Globular Cluster
24.21 Model: Diffusion-Limited Aggregation
24.22 Method: DLA Simulation
24.23 Implementation: dla.c
24.24 Assessment: Fractal Analysis of DLA Graph
24.25 Problem 7: Fractals in Bifurcation Graph
Part III
xvii
321
323
323
324
324
325
326
327
328
329
329
330
330
331
333
333
333
334
335
336
337
337
337
338
339
339
340
PARTIAL DIFFERENTIAL EQUATIONS
25 Electrostatic Potentials
25.1 Introduction: Types of PDEs
25.2 Problem: Determining an Electrostatic Potential
25.3 Theory: Laplace’s Equation (Elliptic PDE)
25.4 Method, Numerical: Finite Difference
25.5 Method, Analytic: Polynomial Expansions
25.6 Implementation: Solution on Lattice, laplace.f
343
343
344
344
345
347
350
xviii
CONTENTS
25.7 Assessment and Visualization
25.8 Exploration
25.9 Exploration: Parallel-Plate Capacitor
25.10 Exploration: Field Between Square Conductors
350
351
351
353
26 Heat Flow
26.1 Problem: Heat Flow in a Metal Bar
26.2 Model: The Heat (Parabolic) PDE
26.3 Method, Analytic: Polynomial Expansions
26.4 Method, Numerical: Finite Difference
26.5 Analytic Assessment: Algorithm
26.6 Implementation: Heat Equation, eqheat.f (.c)
26.7 Assessment: Continuity, Numeric vs Analytic
26.8 Assessment: Visualization
26.9 Exploration
355
355
355
356
358
358
360
361
361
362
27 Waves on a String
27.1 Problem: A Vibrating String
27.2 Model: The Wave Equation (Hyperbolic PDE)
27.3 Method, Numerical: Time Stepping
27.4 Method, Analytic: Normal Modes
27.5 Implementation: eqstring.f (.c)
27.6 Assessment: Visualization
27.7 Exploration
365
365
365
367
368
370
371
371
Part IV NONLINEAR
PARTIAL DIFFERENTIAL EQUATIONS
28 Solitons, the KdeV Equation ¬
28.1 Introduction
28.2 Problem: Solitons
28.3 Theory: The Korteweg–de Vries Equation
28.4 Method, Analytic: Traveling Waves
28.5 Method, Numeric: Finite Difference
28.6 Implementation: KdeV Solitons, soliton.f (.c)
28.7 Assessment: Visualization
28.8 Exploration: Two Solitons Crossing
28.9 Exploration: Phase-Space Behavior
379
379
380
381
384
384
386
387
387
388
CONTENTS
28.10 Exploration: Shock Waves
xix
388
29 Sine–Gordon Solitons ¬
29.1 Problem 1: Particles from Field Equations
29.2 Theory: Circular Ring Solitons (Pulsons)
29.3 Problem 2: Dispersionless Dispersive Chains
29.4 Theory: Coupled Pendula
29.4.1 Dispersion in Linear Chain
29.4.2 Continuum Limit, the SGE
29.5 Solution: Analytic
29.6 Solution: Numeric
29.7 Implementation: 2-D Solitons, twodsol.f (.c)
29.8 Visualization
389
389
389
390
390
392
393
394
394
397
398
30 Confined Electronic Wave Packets ¬
30.1 Problem: A Confined Electron
30.2 Model: Time-Dependent Schr o¨ dinger Equation
30.3 Method, Numeric: Finite Difference
30.4 Implementation: Wave Packet in Well, sqwell.f
30.5 Assessment: Visualization, and Animation
30.6 Exploration: 1-D Harmonic Oscillator
30.7 Implementation: harmos.f
30.8 Problem: Two-Dimensional Confinement
30.9 Method: Numerical
30.10 Exploration: 2-D Harmonic Oscillator
30.11 Exploration: Single-Slit Diffraction, slit.f
399
399
399
401
403
403
404
404
404
406
407
408
Appendix A: Analogous Elements in Fortran and C
409
Appendix B: Programs on Floppy Diskette
411
Appendix C: Listing of C Programs
417
Appendix D: Listing of Fortran Programs
461
Appendix E: Typical Project Assignments
E.1 First Quarter (10 weeks)
E.2 Second Quarter (10 weeks)
501
501
502
xx
CONTENTS
Glossary
503
References
509
Preface
Applying computer technology is simply finding
the right wrench to pound in the correct screw.
—Anonymous
This is not the book I thought I’d be writing. When, about a decade ago, I initiated the discussions that led to our Computational Physics course, I thought
we would teach mainly physics in it. The Computer Science Department, I
thought, would teach the students what they needed to know about computers, the Mathematics Department would teach them what they needed to know
about numerical methods and statistics, and I would teach them what I knew
about applying that knowledge to solve physics problems using computers.
That’s how I thought it would be. But, by and large, I have found that the
students taking our Computational Physics course do not carry the subject
matter from these other disciplines with them, and so a lot of what I have put
into this book is material that, in a more perfect world, would be taught and
written by experts in other fields.
While that is why I feel this is not the book I thought I would be writing, I
believe it’s probably for the better. On the one hand, having a basic research
physicist tell students they need to know “this” in computer science and “that”
in mathematics, gets the message across that “this stuff really matters.” On
the other hand, it’s useful to have the physics, mathematics, and computer
science concepts conveyed in the language of a natural scientist and within
xxi
xxii
PREFACE
the context of solving a problem scientifically.
The official and detailed aims of this book are given in Chapter 1, and the
subjects covered are listed in the Table of Contents. This book differs from a
standard text in its underlying philosophy:
Hear and wonder,
see and follow,
do and understand,
a philosophy also followed in pioneering books such as Thompson, Koonin,
and Gould and Tobochnik. As applied in our book, students learn by solving
an exceptionally wide class of computational physics problems. When I
teach from it, I continually emphasize that it is the student’s job to solve each
problem, which includes understanding the results the computer gives. In the
process, the students are excited by applying scientific, mathematical, and
computational techniques that are often new to them (at least in combination).
As a consequence of having to interact with the materials from a number of
viewpoints, and often on their own, the materials become part of the personal
experiences of the students. For example, I have heard students comment
that “I never understood what was dynamic in thermodynamics until after
this simulation,” and “I would never have imagined that there could be such
a difference between upward and downward recursion,” as well as “Is that
what a random walk really looks like?” or “I don’t believe a pendulum can
really move like that!” In my experience, a teacher just doesn’t hear students
express such insight and interest in course material in lecture courses. The
students, in turn, are often stimulated to learn more about these subjects or to
understand them at greater depth when encountered elsewhere.
There is a price to pay for my unusually broad approach: the students
must work hard and cannot master material in great depth. The workload
is lightened somewhat by providing “bare bones” programs, and the level is
deepened somewhat by having references readily available. In addition, there
are appendixes listing the C and Fortran programs and the sections which
reference them, as well as source code on the diskette and the World Wide
Web (the “Web”). The names of the programs are also included in the titles
of the Implementation sections. By eliminating time-consuming theoretical
background (more properly taught in other places), and by deemphasizing
timidity-inducing discussions of error in every single procedure, the students
get many challenging projects “to work” for them and enjoy the stimulation
of experiencing the material. In the process, the students gain pride and
self-confidence immediately, and this makes for a fun course for everyone.
A sample of the problems actually solved during each of two 10-week
quarters is given in an appendix. I require the students to write up a mini-lab
report for each problem solved containing
Equations solved
Visualization
Numerical method
Discussion
Code listing
Critique
PREFACE
xxiii
The emphasis is to make the report an executive summary of the type given to
a boss or manager; just tell enough to get across that you know what you are
talking about, and be certain to convey what you did and your evaluation of it.
Recently, some students have written their reports as hypertext documents for
the Web. This medium appears ideal for computational projects; the projects
are always in a centralized place for the students and faculty to observe, the
original code is there to run or modify, and the visualizations are striking in
three-dimensional (3-D) color or animation.
An unusual aspect of this book is that, in one form or another, and to an
ever-increasing degree, it is enhanced by materials made available on the Web.
This is part of a research project which explores ways to better incorporate
high-performance computing techniques into science. In Ü1.3 we give the
Web addresses that lead you to these enhancements (they are also accessible
through my home page). Even though we cannot recommend the Web as a
pleasant way to read a book, we do recommend that students try out some
multimedia tutorials and obtain corrections or updates to the programs from
the Web. Your comments and corrections regarding the book and its Web
enhancements are welcomed.
There is more than enough material to use this book for a full year’s
course (I used it for a two-quarter course and had to pick and choose). It
is possible to teach a 10-week class, in which case I would advise moving
rapidly through the basic materials so that the students can experience some
applications. Chapters 2 and 3, Computing Software Basics and Errors and
Uncertainties in Computation, in Part I are essential background material.
Although placed in the middle of the book, students who are not familiar
with computer hardware may benefit from reading Chapter 18, Computing
Hardware Basics: Memory and CPU, before progressing too far into the
materials. Those chapters and sections marked with the ¬ symbol may be
treated as optional.
I have found that one or two lectures a week in which the instructor emphasizes the big points and makes it clear what the students “have” to do (and
when it is due), appears necessary to keep the course moving at a good pace.
Regardless of how the course is taught, most of the learning occurs when the
students sit down and experience the physics with their computers, referring
to the book or Web enhancements for assistance.
RUBIN H. LANDAU
Acknowledgments
This book was developed with a decade’s worth of students in the Computational Physics course at Oregon State University. I am deeply indebted to them
for their good-willed cooperation and enthusiasm, and codes. Some materials
developed by Henri Jansen have ingrained themselves into this book, and his
contributions are gratefully acknowledged. Hans Kowallik has contributed
as a student in the course, as a researcher preparing Web tutorials based on
these materials, and as a teacher developing materials, figures and codes; his
contributions kept the project on time and improved its quality.
I have also received helpful discussions, valuable materials, and invaluable
friendship and encouragement from Paul Fink, Melanie Johnson, Al Stetz, Jon
Maestri, Tom Marchioro II, Cherri Pancake, Pat Canan, Shashi Phatak, Paul
Hillard, and Al Wasserman. The support of the UCES project and their award
for the Web implementations of our projects, is sincerely acknowledged.
In many ways, this book was made possible by the U.S. National Science
Foundation (through laboratory development grants and through the NACSE
Metacenter Regional Alliance), the U.S. Department of Energy, and Oregon
State University. Thanks also go to the people at Wiley-Interscience, in
particular Greg Franklin, John Falcone, Lisa Van Horn, Rosalyn Farkas, and
Amy Hendrickson. My final formatting of this book in LaTeX was done at
the San Diego Supercomputer Center and the Institute for Nonlinear Science,
both at UCSD. Finally, I am especially grateful to my wife Jan, whose reliable
support, encouragement (and proofreading) is lovingly accepted.
RHL
xxv