Computational Physics
Programs That Can Be Checked in 15 chapters — from “A falling body that knows about air: the first simulation” to “Rules on a lattice: diffusion, percolation and growth”.
Chapters
- A falling body that knows about air: the first simulation
- Quadratic drag and the state of a fall
- The update rule
- Variables and functions in a listing
- The loop, and keeping every step
- The order of update
- The terminal speed check
- Step dependence of the landing time
- Three first errors in the loop
- Summary
- Problems
- Numbers a machine can hold, and the two errors that follow
- Binary place value and binary64
- Machine epsilon and the rounding model
- Cancellation in a subtraction
- Conditioning of a problem
- Truncation error and the order of a method
- The total error and its best step
- Overflow, underflow and special values
- Summary
- Problems
- Arrays: a field is a rectangle of numbers
- The array and its shape
- Elementwise arithmetic without a loop
- Broadcasting, and the grid it builds
- A scalar field in three lines
- Reduction along an axis, and masking
- Slicing, and allocating rather than growing
- How much faster, and the equality check
- Summary
- Problems
- Seeing the answer: plots that can be trusted
- Axes, units and the minimum honest plot
- Line plots and uncertainties on a plot
- Logarithmic and log-log axes as instruments
- The residual plot decides a fit
- Field maps, a vector field and histograms
- Animating a time series, and three deceptions
- Summary
- Problems
- A workspace that can be rerun next year
- The repository and the commit
- The difference between two commits
- The seed register and the pinned environment
- The known-answer test, and two more
- One command regenerates the book
- Summary
- Problems
- Where a function vanishes, and what lies between the points
- A physical question as a root problem
- Bisection cannot fail, and is slow
- Newton-Raphson and quadratic convergence
- Newton's three failures, and the secant rule
- Stopping criteria, and what they guarantee
- The Lagrange polynomial and the Runge phenomenon
- The natural cubic spline and its tridiagonal system
- Summary
- Problems
- Differentiating and integrating numbers
- The integral that has no elementary answer
- The central difference and its best step
- Second differences and Richardson extrapolation
- The trapezium rule and Simpson's rule
- Adaptive subdivision and Gaussian quadrature
- An integrable singularity, and how to remove it
- Choosing a rule
- Summary
- Problems
- Letting the computer do the algebra
- A symbol is not a value
- The expression tree, simplification and exact arithmetic
- Symbolic differentiation and the Part II error terms
- The pendulum series to fourth order
- Solving equations symbolically, and where algebra stops
- The bridge back to numbers
- Summary
- Problems
- Finding the best parameters: minimisation and fitting
- Two fits, and the objective function
- One-dimensional minimisation by golden section
- Gradient descent and the ill-conditioned valley
- The Gauss-Newton step
- Uncertainties from curvature
- Checking an uncertainty by synthetic data
- Local minima, and reporting a fit
- Summary
- Problems
- Stepping the equations of motion: four integrators measured
- The first-order system form
- Euler's method, local and global error
- Euler's instability on an oscillator
- Euler-Cromer and the order of two lines
- Velocity Verlet, second order and reversible
- Fourth-order Runge-Kutta and its cost
- Accuracy, order, stability and choosing the step
- Summary
- Problems
- An orbit that must not drift
- The orbit as a four-component system
- Two conserved quantities, not one
- A bounded energy error
- Eccentric orbits and the perihelion problem
- A precession that is not there
- Kepler's third law from your own output
- Summary
- Problems
- When trajectories separate: the driven pendulum and the logistic map
- The driven damped pendulum
- The phase portrait and the Poincare section
- Measuring sensitive dependence
- The system or the program
- The logistic map and period doubling
- The bifurcation diagram and the Feigenbaum ratio
- What can be predicted about a chaotic system
- Summary
- Problems
- Spectra of sampled signals
- Two vibrations, one sampled record
- The discrete transform as a finite sum
- Bin frequency and the power spectrum
- The Nyquist frequency and aliasing
- Leakage and windowing
- The four pendulum spectra
- Transform cost and reporting a spectrum
- Summary
- Problems
- Drawing numbers: random walks and Monte Carlo
- Pseudorandom numbers from a rule
- The error on a Monte Carlo estimate
- Inverse-transform and rejection sampling
- Simulating decay two ways
- Monte Carlo integration in many dimensions
- The random walk
- From the walk to the diffusion equation
- Reporting a Monte Carlo result
- Summary
- Problems
- Rules on a lattice: diffusion, percolation and growth
- The lattice as a field
- The five-point stencil and its scheme
- The stability condition
- Boundaries, and the similarity solution
- The implicit alternative, once
- Site percolation and its threshold
- The fractal dimension, measured
- Cellular automata
- Reporting a lattice result
- Summary
- Problems