97,99 €
The classic in the field for more than 25 years, now with increased emphasis on data science and new chapters on quantum computing, machine learning (AI), and general relativity
Computational physics combines physics, applied mathematics, and computer science in a cutting-edge multidisciplinary approach to solving realistic physical problems. It has become integral to modern physics research because of its capacity to bridge the gap between mathematical theory and real-world system behavior.
Computational Physics provides the reader with the essential knowledge to understand computational tools and mathematical methods well enough to be successful. Its philosophy is rooted in “learning by doing”, assisted by many sample programs in the popular Python programming language. The first third of the book lays the fundamentals of scientific computing, including programming basics, stable algorithms for differentiation and integration, and matrix computing. The latter two-thirds of the textbook cover more advanced topics such linear and nonlinear differential equations, chaos and fractals, Fourier analysis, nonlinear dynamics, and finite difference and finite elements methods. A particular focus in on the applications of these methods for solving realistic physical problems.
Readers of the fourth edition of Computational Physics will also find:
Computational Physics is ideal for students in physics, engineering, materials science, and any subjects drawing on applied physics.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 826
Veröffentlichungsjahr: 2024
Cover
Table of Contents
Title Page
Copyright
Preface
Acknowledgments
Part I: Basics
1 Introduction
1.1 Computational Physics and Science
1.2 This Book’s Subjects
1.3 Video Lecture Supplements
1.4 This Book’s Codes and Problems
1.5 Our Language: The Python Ecosystem
1.6 The Easy Way: Python Distributions
Note
2 Software Basics
2.1 Making Computers Obey
2.2 Computer Number Representations
2.3 Python Mini Tutorial
2.4 Programming Warmup
2.5 Python’s Visualization Tools
2.6 Plotting Exercises
2.7 Code Listings
Notes
3 Errors and Uncertainties
3.1 Types of Errors
3.2 Experimental Error Investigation
3.3 Errors with Power Series
3.4 Errors in Bessel Functions
3.5 Code Listing
Note
4 Monte Carlo Simulations
4.1 Random Numbers
4.2 Simulating a Random Walk
4.3 Spontaneous Decay
4.4 Testing and Generating Random Distributions
4.5 Code Listings
Notes
5 Differentiation and Integration
5.1 Differentiation Algorithms
5.2 Extrapolated Difference
5.3 Integration Algorithms
5.4 Gaussian Quadrature
5.5 Monte Carlo Integrations
5.6 Mean Value and N–D Integration
5.7 MC Variance Reduction
5.8 Importance Sampling and von Neumann Rejection
5.9 Code Listings
Note
6 Trial-and-Error Searching and Data Fitting
6.1 Quantum Bound States I
6.2 Bisection Search
6.3 Newton–Raphson Search
6.4 Magnetization Search
6.5 Data Fitting
6.6 Fitting Exponential Decay
6.7 Least-Squares Fitting
6.8 Nonlinear Fit to a Resonance
6.9 Code Listings
Notes
7 Matrix Computing and N–D Searching
7.1 Masses on a String and N–D Searching
7.2 Matrix Generalities
7.3 Matrices in Python
7.4 Exercise: Tests Before Use
7.5 Solution to String Problem
7.6 Spin States and Hyperfine Structure
7.7 Speeding Up Matrix Computing
7.8 Code Listing
Notes
8 Differential Equations and Nonlinear Oscillations
8.1 Nonlinear Oscillators
8.2 ODE Review
8.3 Dynamic Form of ODEs
8.4 ODE Algorithms
8.5 Solution for Nonlinear Oscillations
8.6 Extensions: Nonlinear Resonances, Beats, Friction
8.7 Code Listings
Notes
Part II: Data Science
9 Fourier Analyses
9.1 Fourier Series
9.2 Fourier Transforms
9.3 Discrete Fourier Transforms
9.4 Noise Filtering
9.5 Fast Fourier Transform
9.6 FFT Implementation
9.7 FFT Assessment
9.8 Code Listings
Notes
10 Wavelet and Principal Components Analysis
10.1 Part I: Wavelet Analysis
10.2 Wave Packets and Uncertainty Principle
10.3 Short-Time Fourier Transforms
10.4 Wavelet Transforms
10.5 Discrete Wavelet Transforms
10.6 Part II: Principal Components Analysis
10.7 Code Listings
Notes
11 Neural Networks and Machine Learning
11.1 Part I: Biological and Artificial Neural Networks
11.2 A Simple Neural Network
11.3 A Graphical Deep Net
11.4 Part II: Machine Learning Software
11.5 TensorFlow and SkLearn Examples
11.6 ML Clustering
11.7 Keras: Python’s Deep Learning API
11.8 Image Processing with OpenCV
11.9 Explore ML Data Repositories
11.10 Code Listings
Notes
12 Quantum Computing (G. He, Coauthor)
12.1 Dirac Notation in Quantum Mechanics
12.2 From Bits to Qubits
12.3 Entangled and Separable States
12.4 Logic Gates
12.5 An Intro to QC Programming
12.6 Accessing the
IBM Quantum Computer
12.7 Qiskit Plus IBM Quantum
12.8 The Quantum Fourier Transform
12.9 Oracle + Diffuser = Grover’s Search Algorithm
12.10 Shor’s Factoring
12.11 Code Listings
Notes
Part III: Applications
13 ODE Applications; Eigenvalues, Scattering, Trajectories
13.1 Quantum Eigenvalues for Arbitrary Potentials
13.2 Algorithm: ODE Solver + Search
13.3 Classical Chaotic Scattering
13.4 Projectile Motion with Drag
13.5 2- and 3-Body Planetary Orbits
13.6 Code Listings
Notes
14 Fractals and Statistical Growth Models
14.1 The Sierpiński Gasket
14.2 Growing Plants
14.3 Ballistic Deposition
14.4 Length of British Coastline
14.5 Correlated Growth
14.6 Diffusion-Limited Aggregation
14.7 Fractals in Bifurcations
14.8 Cellular Automata Fractals
14.9 Perlin Noise Adds Realism
14.10 Code Listings
Notes
15 Nonlinear Population Dynamics
15.1 The Logistic Map, A Bug Population Model
15.2 Chaos
15.3 Bifurcation Diagrams
15.4 Measures of Chaos
15.5 Coupled Predator–Prey Models
15.6 Code Listings
Notes
16 Nonlinear Dynamics of Continuous Systems
16.1 The Chaotic Pendulum
16.2 Phase Space
16.3 Chaotic Explorations
16.4 Other Chaotic Systems
16.5 Code Listings
17 Thermodynamics Simulations and Feynman Path Integrals
17.1 An Ising Magnetic Chain
17.2 Metropolis Algorithm
17.3 Fast Equilibration via Wang–Landau Sampling
17.4 Path Integral Quantum Mechanics
17.5 Lattice Path Integration
17.6 Implementation
17.7 Code Listings
Notes
18 Molecular Dynamics Simulations
18.1 MD
Versus
Thermodynamics
18.2 Initial, Boundary, and Large Conditions
18.3 Verlet Algorithms
18.4 MD for 16 Particles
18.5 Code Listing
Notes
19 General Relativity
19.1 Einstein’s Field Equations
19.2 Gravitational Deflection of Light
19.3 Planetary Orbits in GR Gravity
19.4 Visualizing Wormholes
19.5 Problems
19.6 Code Listings
20 Integral Equations
20.1 Nonlocal Potential Binding
20.2 Momentum-Space Schrödinger Equation
20.3 Scattering in Momentum Space
20.4 Code Listings
Part IV: PDE Applications
21 PDE Review, Electrostatics and Relaxation
21.1 Review
21.2 Laplace’s Equation
21.3 Finite-Difference Algorithm
21.4 Alternate Capacitor Problems
21.5 Electric Field Visualization
21.6 Code Listings
Note
22 Heat Flow and Leapfrogging
22.1 The Parabolic Heat Equation
22.2 Time Stepping (Leapfrog) Algorithm
22.3 Newton’s Radiative Cooling
22.4 The Crank–Nicolson Algorithm
22.5 Code Listings
Notes
23 String and Membrane Waves
23.1 A Vibrating String’s Hyperbolic Wave Equation
23.2 Time-Stepping Algorithm
23.3 von Neumann Stability Analysis
23.4 Beyond The Simple Wave Equation
23.5 Vibrating Membrane (2D Waves)
23.6 Analytical Solution
23.7 Numerical Solution
23.8 Code Listings
24 Quantum Wave Packets and EM Waves
24.1 Time-Dependent Schrödinger Equation
24.2 Split-Time Algorithm
24.3 Special Schrödinger Algorithm
24.4 Quantum Chaos
24.5 E&M Waves: Finite Difference Time Domain
24.6 Maxwell’s Equations
24.7 Split-Time FDTD
24.8 More E&M Problems
24.9 Code Listings
Note
25 Shock and Soliton Waves
25.1 The Continuity and Advection Equations
25.2 Shock Waves via Burgers’ Equation
25.3 Including Dispersion
25.4 KdeV Solitons
25.5 Pendulum Chain Solitons
25.6 Continuum Limit, the Sine-Gordon Equation
25.7 Code Listings
Note
26 Fluid Hydrodynamics
26.1 Navier–Stokes Equation
26.2 Flow Through Parallel Plates
26.3 Navier–Stokes Difference Equation
26.4 Vorticity Form of Navier–Stokes Equation
26.5 Assessment and Exploration
26.6 Code Lisitings
Notes
27 Finite Element Electrostatics
27.1 The Potential of Two Metal Plates
27.2 Finite Element Method
27.3 1D FEM Problems
27.4 2D FEM Exercises
27.5 Code Listings
Appendix Codes and Animations
References
Index
End User License Agreement
Chapter 2
Table 2.1 The IEEE 754 standard for primitive data types.
Table 2.2 Representation scheme for normal and abnormal IEEE singles.
Table 2.3 Representation scheme for IEEE doubles.
Table 2.4 Some common Matplotlib commands.
Chapter 3
Table 3.1 Approximate values for spherical Bessel functions (from Maple).
Chapter 4
Table 4.1 A table of a uniform, pseudo-random sequence generated by Python...
Chapter 5
Table 5.1 Elementary weights for uniform-step integration rules.
Table 5.2 Types of Gaussian integration rules.
Chapter 6
Table 6.1 Experimental values for a scattering cross section ( in the theor...
Chapter 7
Table 7.1 The operators of NumPy and their effects.
Chapter 8
Table 8.1 Comparison of ODE solvers for different equations.
Chapter 9
Table 9.1 Reordering for 16 data complex points.
Chapter 10
Table 10.1 PCA demonstration data.
Chapter 11
Table 11.1 Data for 18 elementary particles tabulated by Index, Name, and Ma...
Table 11.2 Fourteen elementary particles and their masses.
Chapter 18
Table 18.1 Parameter and scales for the Lennard–Jones potential.
Chapter 21
Table 21.1 The types of PDE, their discriminants, and examples of each.
Table 21.2 The relation between boundary conditions and uniqueness for PDEs....
Chapter 1
Figure 1.1 On the left a view of computational physics as a discipline encom...
Figure 1.2 A screenshot from a lecture module showing a dynamic table of con...
Chapter 2
Figure 2.1 A schematic view of a computer’s kernel and shells. The hardware ...
Figure 2.2 The limits of single-precision floating-point numbers and the con...
Figure 2.3 A flowchart illustrating a program to compute projectile motion. ...
Figure 2.4 Screen dumps of two - plots produced by
EasyVisual.py
using the...
Figure 2.5
Left
: Output from the program
3GraphVisual.py
that places three d...
Figure 2.6 Matplotlib plots.
Left
: Output of EasyMatPlot.py (Listing 2.3) sh...
Figure 2.7
Left
and
Right
Columns show two separate outputs, each of two fig...
Figure 2.8
Left
: A 3D wire frame.
Right
: A colored surface plot with wire fr...
Figure 2.9 A 3D scatter plot produced by the program
Scatter3dPlot.py
using ...
Figure 2.10 A comparison of a saw tooth function to the sum of its Fourier c...
Figure 2.11
Left
: A beam and a box supported at two points.
Right
: A screens...
Chapter 3
Figure 3.1 A schematic of the
N
steps in a random walk simulation that ends ...
Figure 3.2 A log–log plot of relative error
versus
the number of points used...
Figure 3.3 The error in the summation of the series for
versus N
for vario...
Figure 3.4
Left
: Specular reflection within a circular mirror in which the i...
Figure 3.5 The first four spherical Bessel functions (
x
) as functions of
x
Chapter 4
Figure 4.1
Left
: A plot of successive random numbers generated with a deli...
Figure 4.2 A plot of a uniform pseudorandom sequence
versus i
. The points ...
Figure 4.3
Left
: A schematic of the
N
steps in a random walk simulation that...
Figure 4.4
Left
: The steps taken in seven 2D random walk simulations.
Right
Figure 4.5 Fifty 2D random walk simulations exploring the diffusion of chemi...
Figure 4.6 Two self-avoiding random walks that simulate protein chains with ...
Figure 4.7
Circle
: A sample containing nuclei, each of which has the same ...
Chapter 5
Figure 5.1 A trajectory of a projectile experiencing air resistance.
Left
: F...
Figure 5.2 The integral is the area under the graph of from
a
to
b
. Here...
Figure 5.3 Different shapes used to approximate the areas under the curve.
L
...
Figure 5.4
Left
: Throwing stones into a pond as a technique for measuring it...
Figure 5.5 Log–log plots of the error in the integration of exponential deca...
Figure 5.6 The area under the curve is the same as that under the horizont...
Figure 5.7 The von Neumann rejection technique for generating random points ...
Chapter 6
Figure 6.1 A graphical representation of the steps involved in solving for a...
Figure 6.2 A graphical representation of the steps involved in solving for a...
Figure 6.3 Two examples of how the Newton–Raphson algorithm may fail if the ...
Figure 6.4 A function of the reduced magnetism at three reduced temperatur...
Figure 6.5 Three fits to data.
Dashed
: Lagrange interpolation using an deg...
Figure 6.6 A reproduction of the experimental measurement of Stetz
et al
. [1...
Figure 6.7 A linear least-squares best fit of a straight line to data. The d...
Figure 6.8 A linear least-squares best fit of a parabola to data. Here we se...
Chapter 7
Figure 7.1 Two masses with weights are connected by three pieces of string...
Figure 7.2 A free-body diagram for one weight in equilibrium. Balancing the ...
Chapter 8
Figure 8.1 A mass
m
(the block) attached to a spring with restoring force ...
Figure 8.2
Left
: The potentials of an harmonic oscillator (solid curve) and ...
Figure 8.3 A sequence of uniform steps of length
h
taken in solving a differ...
Figure 8.4 Euler’s algorithm for integration of a differential equation one ...
Figure 8.5 The rk2 algorithm for integration of a differential equation uses...
Figure 8.6 The logarithm of the relative error in the solution of an ODE obt...
Figure 8.7 The position versus time for oscillations within the potential ...
Chapter 9
Figure 9.1
Left
: A periodic sawtooth function.
Right
: The Fourier spectrum o...
Figure 9.2 A plot of the functions and . If the sampling rate is not high...
Figure 9.3
From bottom left to right
: A function that is a signal plus noise...
Figure 9.4 An input signal
f(t)
passes through a filter
h
that outputs the f...
Figure 9.5
Left
: An
CR
circuit arranged as a lowpass filter.
Right
: An
CR
c...
Figure 9.6 A delay-line filter in which the signal at different times is sca...
Figure 9.7 The rectangle function rect that is constant for a finite freque...
Figure 9.8 The basic butterfly operation in which elements and on the le...
Figure 9.9 The butterfly operations performing an FFT on the eight data on t...
Figure 9.10 A modified FFT in which the eight input data on the left are tra...
Chapter 10
Figure 10.1 The input time signal 10.1 we wish to analyze. The signal is see...
Figure 10.2 Four possible mother wavelets that can be used to generate entir...
Figure 10.3
Left
: A wave packet in time corresponding to the functional for...
Figure 10.4 Four wavelet basis functions (daughters) generated by scaling (
Figure 10.5 A schematic representation of the steps followed in performing a...
Figure 10.6 Comparison of an input and reconstituted signal 10.23 using Morl...
Figure 10.7 The continuous wavelet spectrum obtained by analyzing the input ...
Figure 10.8 A graphical representation of the relation between time and freq...
Figure 10.9 A eigenfrequency dyadic (power-of-2) filter tree used for discre...
Figure 10.10 An input signal (top) is processed by a tree of high- and low-b...
Figure 10.11 In successive passes, the filtering of the original signal at t...
Figure 10.12
Left
: The Daub4 e6 wavelet constructed by inverse transformati...
Figure 10.13 A beam of particles being observed by four detectors.
Figure 10.14
Left
: Samples of 2D data from a detector A showing the direct...
Figure 10.15 Sample data used in our demonstration PCA analysis.
Figure 10.16
Left
: The PCA basis vectors (eigenvectors of cov).
Right
: The ...
Chapter 11
Figure 11.1
Left
: A sketch of a neuron showing dendrites, a cell body, and s...
Figure 11.2 An AI neuron with two inputs and one output. The neuron body cal...
Figure 11.3 A simple neural network with two neurons in the input layer, two...
Figure 11.4 A flowchart of the steps in teaching a neural net, with the grad...
Figure 11.5 A deep neural net that classifies a square into different clas...
Figure 11.6 A screenshot of a TensorFlow calculation of the mass excess of t...
Figure 11.7
Left
: TensorFlow’s linear regression fit to the binding energies...
Figure 11.8 TensorFlow’s first (left) and final (right) fits to Hubble’s dat...
Figure 11.9 Clustered elementary particles from
KmeansCluster.py
showing thr...
Figure 11.10
Left
: Clustering of the data from Table 11.2. The Perceptron’s ...
Figure 11.11
Left
: The decrease in Loss with increasing epochs.
Right
: The l...
Figure 11.12
Left
: Ripe strawberries.
Right
: Not so ripe strawberries.
Figure 11.13
Left
: The 256 tones in each of three colors for ripe strawberri...
Figure 11.14
Left
: One frame from an animation in which the piston is moving...
Chapter 12
Figure 12.1 The Bloch sphere, a geometric representation of a two-level quan...
Figure 12.2 A quantum circuit for creating an entangled state .
Figure 12.3 Histogram of the state formed by application of X, Z, and H gate...
Figure 12.4 A screenshot of the dashboard for the
IBM Quantum Composer, with
...
Figure 12.5
Left
: A Quantum Composer circuit for generating the Bell state
Figure 12.6 The real and imaginary part of the density matrix for the stat...
Figure 12.7 Histogram of the Bell state found using Qiskit and the IBM Qua...
Figure 12.8
Left
: A quantum circuit for adding two bits.
Right
: The IBM Quan...
Figure 12.9 Quantum Fourier transform circuit for 2-qubits.
Figure 12.10
Left
: A schematic quantum circuit for an
oracle
.
Right
: An
orac
...
Figure 12.11 A circuit for Grover’s Algorithm that combines an oracle (O) an...
Figure 12.12
Left
: Output of Grover’s search for as run on a simulator.
Ri
...
Figure 12.13 A quantum circuit for phase estimation.
Chapter 13
Figure 13.1 A square well in bold, and the wave function within it. At the l...
Figure 13.2 Two guesses for the energy that are either too low or too high t...
Figure 13.3
Left
: A classic pinball machine in which the bumpers lead to mul...
Figure 13.4 The trajectories of a projectile fired with initial velocity i...
Figure 13.5
Left
: The components of the gravitational force on a planet at a...
Figure 13.6 A snapshot from the animated output of the code showing:
Left
:...
Chapter 14
Figure 14.1
Left
: The Sierpiński gasket, a statistical fractal containing 10...
Figure 14.2
Left
: A fractal fern generated by 30,000 iterations of the algor...
Figure 14.3 A simulation of the ballistic deposition of 20,000 particles ont...
Figure 14.4 Examples of the use of box counting to determine fractal dimensi...
Figure 14.5 Fractal dimensions of a line, box, and coastline determined by b...
Figure 14.6
Left
: A view of what might be the undergrowth of a forest or den...
Figure 14.7 A globular cluster of particles of the type that might occur in ...
Figure 14.8 Number 8 by the American painter Jackson Pollock.Some resear...
Figure 14.9 The rules for two versions of the Game of Life. The rules, given...
Figure 14.10 The coordinates used in adding Perlin noise. The rectangular gr...
Figure 14.11 The coordinates used in adding Perlin noise. A point within eac...
Figure 14.12 The mapping used in adding Perlin noise.
Left
: The numbers ,
Figure 14.13 Perlin noise mapping.
Left
: The point (
x, y
) is mapped to point...
Figure 14.14 After the addition of Perlin noise, the random scatterplot on t...
Chapter 15
Figure 15.1 The bug population
versus
the generation number for the four...
Figure 15.2 A bifurcation plot of attractor population
versus
growth rate
Figure 15.3 A bifurcation plot, , for the Gaussian map.
Figure 15.4 Fixed point bifurcations (top) and Lyapunov coefficient (bottom)...
Figure 15.5 Shannon entropy (top) and Lyapunov coefficient (bottom) for the ...
Figure 15.6
Left
: The time dependencies of the prey population of
p(t)
(sol...
Figure 15.7 A chaotic attractor for the 4D Lotka–Volterra model projected on...
Figure 15.8 The Lotka–Volterra model including a limit on prey population.
L
...
Figure 15.9 Lotka–Volterra model with predation efficiency and prey limitati...
Chapter 16
Figure 16.1
Left
: A pendulum of length
l
driven through resistive air (dotte...
Figure 16.2 The data screen (
left
) and the output screen (
right
) of the appl...
Figure 16.3
Top
: Phase space trajectories for a pendulum including “over the...
Figure 16.4 Three potentials and their behaviors in phase space. The differe...
Figure 16.5 Position
versus
time and position
versus
velocity for two initia...
Figure 16.6 The position
versus
time, phase space plot, and Fourier spectrum...
Figure 16.7 The behavior of a chaotic pendulum with slightly differing drivi...
Figure 16.8
Left
: The phase space plot for two pendulums with almost exactly...
Figure 16.9 A bifurcation diagram for the damped pendulum with a vibrating p...
Figure 16.10 Photographs of a double pendulum built by a student after runni...
Figure 16.11
Left
: Phase space trajectories for a double pendulum with and...
Figure 16.12 Square (a, c), circular (b, d), Sinai (e), and stadium billiard...
Figure 16.13 One, two, and three stationary disks on a flat billiard table s...
Figure 16.14 A 3D plot of a Lorenz attractor.
Figure 16.15 A period three solution for a forced Duffing oscillator.
Left
:
Chapter 17
Figure 17.1 The 1D lattice of spins used in the Ising model of magnetism. ...
Figure 17.2 An Ising model simulation on a 1D lattice of 100 initially align...
Figure 17.3 Simulation results from a 1D Ising model of 100 spins.
Left
: Ene...
Figure 17.4 The energy, specific heat, and magnetization as a function of te...
Figure 17.5 Wang–Landau sampling used in the 2D Ising model on an lattice....
Figure 17.6 In the Feynman path-integral formulation of quantum mechanics, a...
Figure 17.7
Left
: A space-time quantum path resulting from applying the Metr...
Figure 17.8
Left
: A path through a space-time lattice that starts and ends a...
Figure 17.9 The analytic and quantum Monte Carlo solution for the quantum bo...
Chapter 18
Figure 18.1 The molecule–molecule effective interaction arises from the many...
Figure 18.2 The Lennard–Jones effective potential used in many MD simulation...
Figure 18.3 An imagined infinite space generated by imposing periodic bounda...
Figure 18.4
Left
: Two frames from an animation of a 1D simulation. The space...
Figure 18.5 The kinetic, potential, and total energy for a 2D MD simulation ...
Figure 18.6
Left
: The temperature after equilibration as a function of initi...
Figure 18.7
Top Left
: Positions of particles at a single time.
Top Right
: Di...
Figure 18.8
Left
: The total energy versus temperature for 16 particles in a ...
Figure 18.9 A simulation of a projectile shot into a group of particles. The...
Chapter 19
Figure 19.1 Two free particles move along the infinitesimally close geodesic...
Figure 19.2 A light ray being bent by an angle due to the gravitational ef...
Figure 19.3
Left
: Three trajectories showing the bending of light rays cause...
Figure 19.4 Relativistic and Newtonian potentials for . The two dots corres...
Figure 19.5
Left
: An orbit corresponding to an energy at the maximum of the ...
Figure 19.6 An artist’s perception of the precession of the perihelion of Hg...
Figure 19.7 The Ellis wormhole connecting upper and lower (flatter) spaces. ...
Chapter 20
Figure 20.1
Left
: A projectile (dark particle at ) scatters from a dense me...
Figure 20.2 The grid of momentum values on which the integral equation is so...
Figure 20.3 Three different paths in the complex plane used to evaluate li...
Figure 20.4 The energy dependence of the cross section for angular momentum
Chapter 21
Figure 21.1
Left
: The shaded region of space within a square in which we det...
Figure 21.2 The analytic (Fourier series) solution of Laplace’s equation sum...
Figure 21.3 The lattice and algorithm for Laplace’s equation. The potential ...
Figure 21.4
Left
: A simple model of a parallel-plate capacitor within a box....
Figure 21.5
Left
: A visualization of the computed electric potential for a c...
Figure 21.6 A guess as to how charge may rearrange itself on finite conducti...
Figure 21.7
Left
: The geometry of a capacitor formed by placing two long, sq...
Figure 21.8 Computed equipotential surfaces and electric field lines for a r...
Chapter 22
Figure 22.1 A metallic bar insulated along its length with its ends in conta...
Figure 22.2 The algorithm for the heat equation in which the temperature, at...
Figure 22.3 A visualization of a numerical calculation of the temperature
ve
...
Figure 22.4 Temperature
versus
position and time when two bars at differing ...
Chapter 23
Figure 23.1
Left
: A stretched string of length tied down at both ends. The...
Figure 23.2 The solutions of the wave equation for four earlier space-time p...
Figure 23.3 The vertical displacement as a function of position and time
Figure 23.4
Left
: A uniform string suspended from its ends in a gravitationa...
Figure 23.5 The waves of a plucked catenary with friction at six different t...
Figure 23.6 A small section of an oscillating membrane and the forces that a...
Figure 23.7 The standing wave pattern on a square box top at three different...
Chapter 24
Figure 24.1 The probability density as a function of time and space for an e...
Figure 24.2 The probability density as a function of time for an electron co...
Figure 24.3 The probability density as a function of and at three differ...
Figure 24.4 The probability density as a function of position and time for a...
Figure 24.5
Left:
Classical trajectories for scatterings from one, two, and ...
Figure 24.6
Left
: The path followed by a classical ball bouncing elastically...
Figure 24.7 A single electromagnetic pulse traveling along the axis. The c...
Figure 24.8 The algorithm for using the known values of and at two earli...
Figure 24.9 The field (light colored) and the field (dark) at the initia...
Figure 24.10 One frame from the program in Listing 24.4, showing a linearl...
Figure 24.11 and fields at for a circularly polarized wave.
Figure 24.12
Left
: A transmission line that repeats every .
Right
: Two fram...
Chapter 25
Figure 25.1
Left
:Two computed shallow-water solitary waves crossing each oth...
Figure 25.2 A visualization showing the formation of a shock wave (sharp edg...
Figure 25.3 The formation of a tsunami. A single two-level waveform at time ...
Figure 25.4 A 1D chain of pendulums, coupled via torsion bars between the pe...
Figure 25.5 The dispersion relation for a linearized chain of pendulums.
Figure 25.6 A circular ring soliton at times 8, 20, 40, 60, 80, and 120. Thi...
Chapter 26
Figure 26.1 Side view of the flow of a stream around a submerged beam (
left
)...
Figure 26.2 The boundary conditions for two thin submerged plates. The surro...
Figure 26.3 Boundary conditions for flow around the beam in Figure 26.1. The...
Figure 26.4 Two visualizations of the stream function for Reynold’s number...
Figure 26.5
Left
: The vorticity as a function of and . Rotation is seen t...
Chapter 27
Figure 27.1 A finite element solution to Laplace’s equation for two metal pl...
Figure 27.2 Basis functions used in finite-element solution of the 1D Laplac...
Figure 27.3 Exact (line)
versus
FEM solution (points) for the two‐plate prob...
Figure 27.4
Left
: Decomposition of a 2D domain into triangular elements. Sma...
Cover
Table of Contents
Title Page
Copyright
Preface
Acknowledgments
Begin Reading
Appendix Codes and Animations
References
Index
End User License Agreement
iii
iv
xvii
xviii
xix
1
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
555
556
557
558
559
560
561
562
563
564
565
566
Fourth Edition
Rubin H. Landau
Manuel J. Páez
Cristian C. Bordeianu (D)
With contributions by Guangliang He
AuthorsProf. Rubin H. LandauOregon State UniversityCorvallisOR97331United States of America
Prof. Manuel J. PáezDepartamento FisicaUniversad de AntioquiaMedellinColombia
Prof. Cristian C. Bordeianu†University of BucharestStr. Mica nr. 7jud. Suceav725100Romania
Cover Image: © PASIEKA/Getty Images
All books published by WILEY-VCH are carefully produced. Nevertheless, authors, editors, and publisher do not warrant the information contained in these books, including this book, to be free of errors. Readers are advised to keep in mind that statements, data, illustrations, procedural details or other items may inadvertently be inaccurate.
Library of Congress Card No.: applied for
British Library Cataloguing-in-Publication DataA catalogue record for this book is available from the British Library.
Bibliographic information published by the Deutsche Nationalbibliothek The Deutsche Nationalbibliothek lists this publication in the Deutsche Nationalbibliografie; detailed bibliographic data are available on the Internet at <http://dnb.d-nb.de>.
© 2024 WILEY-VCH GmbH, Boschstraße 12, 69469 Weinheim, Germany
All rights reserved (including those of translation into other languages). No part of this book may be reproduced in any form – by photoprinting, microfilm, or any other means – nor transmitted or translated into a machine language without written permission from the publishers. Registered names, trademarks, etc. used in this book, even when not specifically marked as such, are not to be considered unprotected by law.
Print ISBN: 978-3-527-41425-3ePDF ISBN: 978-3-527-84332-9ePub ISBN: 978-3-527-84331-2
When the first edition of Computational Physics was published in 1997, who would have thought that we would be doing it again in 2024? Back then, we hoped that our writing might encourage the inclusion of more computation into the physics curriculum. Now, computational physics (CP) courses are taught widely (if only more with our book!). Yet, when Martin Preuss of Wiley asked if we might be interested in a fourth edition, the thought of getting to work with some recent developments in computation was just too appealing for us to resist. And so, here we are!
And who would have thought that our youngest coauthor, Christian Bordeianu, who joined us for the second and third editions, would not be around for this one! It is so sad that we must write without his enthusiasm, knowledge, good nature, and friendship.
This edition continues with the three main themes of previous ones:
That there is value when first learning CP to survey a broad range of topics in various specialties.
That the best way to learn CP is by doing it on a computer with examples, exercises, and problems.
That CP is part of computational science, which means that we are presenting CP as a mixture of physics, applied mathematics, and computer science, trying not to shortchange the latter two.
This edition has entirely new chapters on neural networks and machine learning, quantum computing (with Guangliang He), and general relativity, as well as an expanded coverage of principal component analyses and Python programming. Finally, there has been editing throughout the text to improve clarity and organization. This edition also continues our advocacy of a compiled-type programming language, and especially Python, as the best vehicle for learning CP. This is in contrast to computing environments such as Matlab and Mathematica, where the mathematics, algorithms, and details are kept “under the hood.” If computational results are to be scientifically sound, we believe it requires a physicist to understand the algorithms, their connections to mathematics, physics, the logic of a program, and, especially, the limits and uncertainties of the computation. Nevertheless, we appreciate how time-consuming and frustrating debugging programs may be, especially for beginners, and so we provide the reader with a large number of codes in the text and online at: sites.science.oregonstate.edu/~landaur/Books/Problems/Codes/. Our hope is that this leaves time for exploration, extensions, and analysis. It also provides experience in the modern work environment, in which one must incorporate new developments into the preexisting developments of others.
To make room for the new, we have (sadly) removed some of the old ones that were in previous editions. However, those materials can still be found in a Jupyter Notebook version of the previous edition online at sites.science.oregonstate.edu/~landaur/Books/CPbook/eBook/.
There are also video lectures at sites.science.oregonstate.edu/~landaur/Books/CPbook/eBook/Lectures/ and on YouTube’s Landau Computational Physics Course at www.youtube.com/playlist?list=PLnWQ_pnPVzmJnp794rQXIcwJIjwy7Nb2U.
These videos and the concordant slides cover most of the topics in the text and may be helpful in blended or hybrid courses.
We hope you enjoy our work and we look forward to your comments.
Tucson, May 2024Medellin, May 2024
Rubin H. Landau, Tucson
Manuel J. Páez, Medellin
Immature poets imitate;
mature poets steal.
— T. S. Elliot
Previous editions of this book and our computational physics courses would not have been possible without financial support from the National Science Foundation’s CCLI, EPIC, and NPACI programs, and the Physics Department of Oregon State University. Thank you, we hope we have made you proud.
Our CP developments have followed the pioneering paths paved by Thompson, Gould and Tobochnik, Christian, and Press et al. Indubitably, we have borrowed material from them and made it our own with no further thought.
We wish to acknowledge valuable contributions by Guangliang He, Hans Kowallik, Sally Haerer (video lecture modules), Paul Fink (deceased) Oscar A. Restrepo, Jaime Zuluaga, and Henri Jansen. It is our pleasure to acknowledge the invaluable friendship, encouragement, helpful discussions, and experiences we have had with many colleagues and students over the years. We are particularly indebted to Guillermo Avendaño-Franco, Saturo S. Kano, Melanie Johnson, Jon Maestri (deceased), David McIntyre, Shashikant Phatak, Viktor Podolskiy, C. E. Yaguna, and Zlatco Dimcovic. And, finally, it’s been a pleasure to work with Martin Preuss, Aswini Murugadass, and Judy Howarth at Wiley again.
In spite of everyone’s best efforts, there are still errors and confusing statements in the book and codes for which we are to blame.
Beginnings are hard
.
—Chaim Potok
Nothing is more expensive than a start
.
—Friedreich Nietzsche
We start this book with a description of how computational physics (CP) fits into the broader field of computational science, and how CP fits into physics. We describe the subjects we cover, the coordinated video lectures, and how the book may be used in a CP course. Finally, we get down to business by discussing the Python language and its many packages, some of which we’ll use. In Chapter2 we give an introduction to Python programming, and in Chapter7 we examine Python’s treatment of matrices.
As illustrated in Figure 1.1, we view CP as a bridge that connects physics, computer science (CS), and applied mathematics. Whereas CS studies computing for its own intrinsic interest and develops the hardware and software tools that computational scientists use, and while applied mathematics develops and studies the algorithms that computational scientists use, CP focuses on using all of that to do better and new physics. Furthermore, just as an experimentalist must understand many aspects of an experiment to ensure that her measurements are accurate and believable, so should every physicist undertaking a computation understand the CS and math well enough to ensure that her computations are accurate and precise.
As CP has matured, we see it not only as a bridge among disciplines, but also as a specialty containing core elements of its own, such as data-mining tools, computational methods, and a problem-solving mindset. To us, CP’s commonality of tools and viewpoint with other computational sciences makes it a good training ground for students, and a welcome change from the overspecialization found in so much of physics.
As part of this book’s emphasis on problem solving, we strive to present the subjects within a problem-solving paradigm, as illustrated on the right of Figure 1.1. Ours is a hands-on, inquiry-based approach in which there are problems to solve, a theory or an appropriate model to apply, an appropriate algorithm to use, and an assessment of the results. This approach can be traced back to the post-World War II research techniques developed at US national laboratories. They deserve the credit for extending the traditional experimental and theoretical approaches of physics to also include simulation. Recent developments have also introduced powerful data mining tools, such as neural networks, artificial intelligence, and quantum computing.
Figure 1.1 On the left a view of computational physics as a discipline encompassing physics, applied mathematics, and computer science. On the right is a broader view of computational physics fitting into various components of scientific problem solving.
We do not intend this book to be a scholarly exposition of the foundations of CP. Instead, we employ a learn-by-doing approach with many exercises, problems, and ready-to-run codes. We survey many of the subjects that constitute CP at a level appropriate for undergraduate education, except maybe for the latter parts of some chapters. Our experience is that many graduate students and professionals may also benefit from this survey approach in which a basic understanding of a broad range of topics facilitates further in-depth study.
Chapters 1 –8 cover basic numerics, ordinary differential equations with (many) applications, matrix computing using well-developed linear algebra libraries, and Monte-Carlo methods. Some powerful data mining tools such as discrete Fourier transforms, wavelet analysis, principal component analysis, and neural networks are covered in the middle of the book.
A traditional way to view the materials in this text is in terms of their use in courses. For a one-quarter class, we used approximately the first-third of the text, with its emphasis on computing tool familiarity with a compiled language [CPUG, 2009]. The latter two-thirds of the text, with its greater emphasis on physics, has typically been used in a two-quarter (20-week) course. What with many of the topics taken from research, these materials can easily be used for a full year’s course, and for supplementary research projects.
As an extension of the concept of a “text,” we provide some 60 video lecture modules (as in Figure 1.2) that cover almost every topic in the book. The modules were originally a mix of Flash, Java, HTML, and mpeg, but with Flash no longer supported, we provide them as mp4 videos and PDF slides. They are available on our website: https://sites.science.oregonstate.edu/∼landaur/Books/CPbook/eBook/Lectures, as well as on our YouTube channel under Landau Computational Physics Course: https://www.youtube.com/playlist?list=PLnWQ_pnPVzmJnp794rQXIcwJIjwy7Nb2U.
Figure 1.2 A screenshot from a lecture module showing a dynamic table of contents, a talking head, video controls, a slide with live scribbling, and some old man. (Originally in Flash, now as mpegs.)
The video lectures can be used to preview or review materials, as part of an online course, or in a blended course in which they replace some lectures, thereby freeing up time for lab work with the instructor.
Separate from the problems and exercises throughout the text, almost every chapter starts off with a keynote “Problem” that leads into the various steps in computational problem solving (Figure 1.1). The additional problems and exercises distributed throughout the chapters are essential ingredients for learning, and are meant to be worked through. This entails studying the text, writing, debugging, and running programs, visualizing the results, and expressing in words what has been performed, and what can be concluded. We asked our students to write up mini lab reports containing
Equations solved
Numerical method
Code listing
Visualization
Discussion
Critique
Although we recognize that programming is a valuable skill for scientists, we also know that it is incredibly exacting and time-consuming. In order to lighten the workload, we provide programs for most of the problems in the text, both at the end of each chapter and online at: sites.science.oregonstate.edu/∼landaur/Books/CPbook/Codes.
A complete list is given in the Appendix. We recommend that these codes be used as guides for the reader when writing their own programs, or, at the least, tested and extended to solve the problem at hand. We have been told that learning how to use someone else’s code is a valuable workplace skill to develop; as with programs encountered in a workplace, they should be understood before use!
The codes in this edition of Computational Physics employ the computer language Python. Previous editions have employed Java, Fortran, and C, and used post-computation tools for visualization.1 Python’s combination of language plus packages now makes it the standard for the explorative and interactive computing that typifies present-day scientific research.
Although valuable for research, we have also found Python to be the best language yet for teaching and learning CP. It is free, robust (programs don’t crash), portable (programs run without modifications on various devices), universal (available for most every computer system), has a clean syntax that permits rapid learning, has dynamic typing (changes data types automatically as needed), has high-level, built-in data types (such as complex numbers), and built-in visualization. Furthermore, because Python is interpreted, students can learn the language by executing and analyzing individual statements within an interactive shell, or within a notebook environment, or by running an entire program in one fell swoop. Finally, it is easy to use the myriad of free Python packages supporting numerical algorithms, state-of-the-art visualizations, as well as specialized toolkits that rival those in Matlab and Mathematica/Maple. And did we mention, all of this is free?
Although we do not expect the readers to be programming experts, it is essential to be able to run and modify the sample codes in this book. For learning Python, we recommend the online tutorials [PyTut, 2023; Pguide, 2023; Plearn, 2023], the book [Langtangen, 2016], and the many books in the “Python for Scientists and Engineers” genre. For general numerical methods, [Press et al., 2007] is the standard, and fun to read. The NITS Digital Library of Mathematical Functions [NIST, 2022] is a convenient reference for mathematical functions and numerical methods.
Python has developed rapidly since its first implementation in December 1989 [History, 2022]. The rapid developments of Python have led to a succession of new versions and the inevitable incompatibilities. The codes presented in the book are in the present standard, Python 3. The major difference from Python 2 is the print statement:
The Python language plus its family of packages comprise a veritable ecosystem for computing. A package, or library, or module, is a collection of related methods, or classes of methods, that are assembled and designed to work together. Inclusion of the appropriate packages extends the language to meet the specialized needs of various science and engineering disciplines [CiSE, 2015]. The Python Package Index [PyPi, 2023], a repository of free Python packages, currently contains 425,320 projects and 7,313,641 files. In this book, we use:
Jupyter Notebooks:
A web-based, interactive Python computing environment combining live code, type-set equations, narrative text, visualizations, and whatever. Some of our programs ( suffix) were developed in Jupyter, and our programs using Vpython work only within Jupyter. There is a previous edition of this text in notebook form at
sites.science.oregonstate.edu/∼landaur/Books/CPbook/eBook
.
The interactive Python shell, IPython can also be used within Jupyter.
Numpy (Numerical Python):
A comprehensive library of mathematical functions, random number generators, linear algebra routines, Fourier transforms, and most everything else. Permits the use of fast, high-level multidimensional arrays (explained in
Chapter 7
). The successor to both
Numeric
and
NumArray
, NumPy is used by Visual and Matplotlib.
Matplotlib (Mathematics Plotting Library):
A 2D and 3D graphics library that uses NumPy, produces publication-quality figures in a variety of hard copy formats, and that permits interactive graphics. Similar to Matlab’s plotting (except Matplotlib is free and doesn’t need its license renewed yearly).
Pandas (Python Data Analysis Library):
A collection of high-performance, user-friendly data structures, and data analysis tools (used in
Chapter 11
).
SymPy (Symbolic Python):
A system for symbolic mathematics using pure Python (no external libraries) that provides a simple computer algebra system including calculus, differential equations, etc. Similar to Maple or Mathematica, with the
Sage
package being even more complete. Examples in
Section 2.3.6
.
Visual (Vpython):
The Python language plus the no-longer-supported
Visual
graphics module (superseded by GlowScript). Particularly easy for creating educational 3D demonstrations and animations. Still useful as and within Jupyter Notebooks.
Although most Python packages are free, there is true value for both users and vendors to distribute a collection of packages that have been engineered and tuned to work well together, and that can be installed in one fell swoop. (This is similar to what Red Hat and Debian distributions do for Linux.) These distributions can be thought of as complete, Python ecosystems and are highly recommended. In particular, all you really need to do to get started with Python computing for this book is to load:
AnaConda:
A free Python distribution including more than 8000 packages for science, mathematics, engineering, machine learning, and data analysis. Anaconda installs in its own directory and so runs independently from other Python installations on your computer. Go to
https://www.anaconda.com/products/distribution
to download Anaconda. Once you install
Anaconda
, the
Navigator
should open, and it will let you choose all that you will need.
Spyder IDE:
The Scientific PYthon Development EnviRonment. An Integrated Development Environment (IDE) with advanced editing, interactive testing of code, debugging, and more.
Jupyter Notebook:
The Web-based interactive computing notebook environment used for editing and running type-set-like documents, while also running Python code within the documents. As we have already said, a notebook () version of an earlier edition of this text is at
sites.science.oregonstate.edu/∼landaur/Books/CPbook/eBook
.
Powershell Prompt:
A powerful terminal that runs
conda
commands under the Windows shell environments (Command Prompt) and . Apple has a
Terminal
app where you will find a command prompt.
Conda:
A package management and environment system included in Anaconda that finds, installs, and updates packages and their dependencies for you.
In Chapter 11 we describe how to load and run Google’s TensorFlow package for machine learning, and in Chapter 12 we describe how to load and run the Quantum Computing packages, Cirq, IBM Quantum, and Qiskit.
1
All of our codes, even the old ones, are available online.
This chapter discusses the computing basics of communications, number representations, Python programming, and visualizations. Since we want to do science, there is a particular emphasis on the limits of floating point arithmetic.
The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct.
— Donald E. Knuth
As anthropomorphic as your view of your computer may be, keep in mind that computers always do exactly as they are told. This means that you must tell them exactly everything you want them to do. Of course, the programs you run may have to be at such a high level with such convoluted logic that you may not have the endurance to figure out the details of just what they are telling the computer to do, but it is always possible in principle (except maybe not with AI). So your first problem is to obtain enough understanding so that you feel sufficiently in control, no matter how illusionary, to figure out what the computer is doing.
Before you tell the computer to obey your orders, you need to understand that life is not simple for computers. The instructions they understand are in a basic machine language1 that tells the hardware to do things like move a number stored in one memory location to another location, or to do some simple binary arithmetic. Very few computational scientists talk to computers in a language computers can understand. When writing and running programs, we usually communicate through shells, in high-level languages (Python, Java, Fortran, and C), or through problem-solving environments (Maple, Mathematica, and Matlab). Eventually, our commands or programs are translated into the basic machine language that the hardware understands.
A shell is a command-line interpreter, that is, a set of small programs run by a computer that responds to the commands (the names of the programs) that you key in. Usually you open a special window to access the shell, and this window is called a shell as well. It is helpful to think of these shells as the outer layers of the computer’s operating system (OS) in Figure 2.1, within which lies a kernel of elementary operations. (The user seldom interacts directly with the kernel, except possibly when installing programs or when building an OS from scratch.) It is the job of the shell to run programs, compilers, and utilities that do things like moving and copying files. There can be different types of shells on a single computer, or multiple copies of the same shell running at the same time.
Operating systems have names such as Unix, Linux, DOS, MacOS, and MS Windows. An operating system is no more than a group of programs used by the computer to communicate with users and devices, to store and read data, and to execute programs. The OS tells the computer what to do in an elementary way. The OS views you, other devices, and programs as input data for it to process; in many ways, it is the indispensable office manager. While all this may seem complicated, the purpose of the OS is to let the computer do the nitty-gritty work so that you can think higher-level thoughts and communicate with the computer in something closer to your normal everyday language.
When you submit a program to your computer in a high-level language, the computer may use a compiler to process it. A compiler is another program that treats your program as a foreign language and uses a built-in dictionary and set of rules to translate it into basic machine language. As you can probably imagine, the final set of instructions is quite detailed and long, and the compiler may make several passes through your program to decipher your logic and translate it into a fast code. The translated statements form an object or compiled code, and when linked together with other needed subprograms, form a load module that can be loaded into the computer’s memory and read, understood, and followed by the computer.
Languages such as Fortran and C use compilers to read your entire program and then translate it into basic machine instructions. Interpreted languages such as Python, BASIC, and Maple translate or interpret each line of your program as it is entered, and thus permit line-by-line interactions. Compiled languages usually lead to more efficient programs and permit the use of vast subprogram libraries. Interpreted languages give a more immediate response to the user and thereby appear “friendlier.” The Python and Java languages are actually a mix of the two. When you first compile your program, Python interprets it into an intermediate, universal byte code, which gets stored as a or file. This file can be transported to and used on other computers, although not with different versions of Python. Then, when you run your program, Python recompiles the byte code into a machine-specific and fast-running compiled code.
Figure 2.1 A schematic view of a computer’s kernel and shells. The hardware is in the center surrounded by increasingly higher-level software.
Computers may be powerful, but they are finite. A problem in computer design is how to represent an arbitrary number using a finite amount of memory space, and then how to deal with the limitations arising from this representation. As a consequence of computer memories being based on the magnetic or electronic realizations of a spin pointing up or down, the most elementary units of computer memory are the two binary integers (bits) 0 and 1. This means that all numbers are stored in memory in