Companion Website

Computational Physics

From Equations to Simulation

Codes

Source codes are organized by chapter. Where available, matching implementations are provided in MATLAB, Python, C++, and Fortran.

The same descriptive filename stem is used across programming languages whenever the implementations correspond to the same numerical example.

Browse by chapter

Chapter 4

Numerical Errors and Uncertainty in Computation

Short experiments on floating-point precision, cancellation, and summation order. One file in each language contains all three demonstrations.

View Chapter 4 codes →

Chapter 5

Interpolation

Programs for general polynomial interpolation, Runge/Chebyshev interpolation, and cubic splines.

View Chapter 5 codes →

Chapter 6

Numerical Differentiation

Programs for calculating first and second derivatives from tabulated data and for improving centered differences with Richardson extrapolation.

View Chapter 6 codes →

Chapter 7

Numerical Integration

Programs for Newton–Cotes, Gaussian quadrature, adaptive integration, improper and oscillatory integrals, and multidimensional integration.

View Chapter 7 codes →

Chapter 8

Linear Systems and Eigenvalue Problems

Programs for Gaussian elimination, SOR, tridiagonal solves, matrix inversion, and selected or complete symmetric eigenvalue calculations.

View Chapter 8 codes →

Chapter 9

Initial Value Problems for Ordinary Differential Equations

Six programs for fixed-step Euler, Heun, and RK4; adaptive RKF45 for scalar equations and systems; damped spring and projectile motion; and fixed-step velocity Verlet for an orbit.

View Chapter 9 codes →

Chapter 10

Boundary Value Problems for Ordinary Differential Equations

Six programs for shooting, finite differences, boundary-condition choices, Newton iteration, Numerov eigenvalues, and a Schrödinger matrix problem.

View Chapter 10 codes →

Chapter 11

Solving Nonlinear Equations

Programs for bisection, false position, Newton's method, the secant method, and locating multiple roots by interval scanning.

View Chapter 11 codes →

Chapter 13

Optimization and Data Fitting

Eleven practical programs for local and heuristic optimization, least-squares fitting, polynomial model comparison, and bootstrap uncertainty, in four languages.

View Chapter 13 codes →