Bringing together idiomatic Python programming, foundational numerical methods, and physics applications, this is an ideal standalone textbook for courses on computational physics. All the frequently used numerical methods in physics are explained, including foundational techniques and hidden gems on topics such as linear algebra, differential equations, root-finding, interpolation, and integration. Accompanying the mathematical derivations are full implementations of dozens of numerical methods in Python, as well as more than 250 end-of-chapter problems. Numerical methods and physics examples are clearly separated, allowing this introductory book to be later used as a reference; the penultimate section in each chapter is an in depth project, tackling physics problems which cannot be solved without the use of a computer. Written primarily for students studying computational physics, this textbook brings the non-specialist quickly up to speed with Python before looking in detail at the numerical methods often used in the subject.
Author(s): Alex Gezerlis
Edition: 1
Publisher: Cambridge University Press
Year: 2020
Language: English
Commentary: Vector PDF
Pages: 606
City: Cambridge, UK
Tags: Python; Ordinary Differential Equations; Numerical Methods; Nonlinear Equations; Partial Differential Equations; NumPy; Linear Algebra; SciPy; Integration; Physics; Splines; Approximation Algorithms; Monte Carlo Simulations
Copyright
Contents
Preface
List of codes
1 Idiomatic Python
1.1 Why Python?
1.2 Code Quality
1.3 Summary of Python Features
1.3.1 Basics
1.3.2 Control Flow
1.3.3 Data Structures
1.3.4 User-Defined Functions
1.4 Core-Python Idioms
1.4.1 List Comprehensions
1.4.2 Iterating Idiomatically
1.5 Basic Plotting with matplotlib
1.6 NumPy Idioms
1.7 Project: Visualizing Electric Fields
1.7.1 Electric Field of a Distribution of Point Charges
1.7.2 Plotting Field Lines
1.8 Problems
2 Numbers
2.1 Motivation
2.2 Errors
2.2.1 Absolute and Relative Error
2.2.2 Error Propagation
2.3 Representing Real Numbers
2.3.1 Basics
2.3.2 Overflow
2.3.3 Machine Precision
2.3.4 Revisiting Subtraction
2.3.5 Comparing Floats
2.4 Rounding Errors in the Wild
2.4.1 Are Roundoff Errors Random?
2.4.2 Compensated Summation
2.4.3 Naive vs Manipulated Expressions
2.4.4 Computing the Exponential Function
2.4.5 An Even Worse Case: Recursion
2.4.6 When Rounding Errors Cancel
2.5 Project: the Multipole Expansion in Electromagnetism
2.5.1 Potential of a Distribution of Point Charges
2.5.2 Expansion for One Point Charge
2.5.3 Expansion for Many Point Charges
2.6 Problems
3 Derivatives
3.1 Motivation
3.1.1 Examples from Physics
3.1.2 The Problem to Be Solved
3.2 Analytical Differentiation
3.3 Finite Differences
3.3.1 Noncentral-Difference Approximations
3.3.2 Central-Difference Approximation
3.3.3 Implementation
3.3.4 More Accurate Finite Differences
3.3.5 Second Derivative
3.3.6 Points on a Grid
3.3.7 Richardson Extrapolation
3.4 Automatic Differentiation
3.4.1 Dual Numbers
3.4.2 An Example
3.4.3 Special Functions
3.5 Project: Local Kinetic Energy in Quantum Mechanics
3.5.1 Single-Particle Wave Functions in One Dimension
3.5.2 Second Derivative
3.6 Problems
4 Matrices
4.1 Motivation
4.1.1 Examples from Physics
4.1.2 The Problems to Be Solved
4.2 Error Analysis
4.2.1 From a posteriori to a priori Estimates
4.2.2 Magnitude of Determinant?
4.2.3 Norms for Matrices and Vectors
4.2.4 Condition Number for Linear Systems
4.2.5 Condition Number for Simple Eigenvalues
4.2.6 Sensitivity of Eigenvectors
4.3 Solving Systems of Linear Equations
4.3.1 Triangular Matrices
4.3.2 Gaussian Elimination
4.3.3 LU Method
4.3.4 Pivoting
4.3.5 Jacobi Iterative Method
4.4 Eigenproblems
4.4.1 Power Method
4.4.2 Inverse-Power Method with Shifting
4.4.3 QR Method
4.4.4 All Eigenvalues and Eigenvectors
4.5 Project: the Schr¨ odinger Eigenvalue Problem
4.5.1 One Particle
4.5.2 Two Particles
4.5.3 Three Particles
4.5.4 Implementation
4.6 Problems
5 Roots
5.1 Motivation
5.1.1 Examples from Physics
5.1.2 The Problem(s) to Be Solved
5.2 Nonlinear Equation in One Variable
5.2.1 Conditioning
5.2.2 Order of Convergence and Termination Criteria
5.2.3 Fixed-Point Iteration
5.2.4 Bisection Method
5.2.5 Newton’s Method
5.2.6 Secant Method
5.2.7 Ridders’ Method
5.2.8 Summary of One-Dimensional Methods
5.3 Zeros of Polynomials
5.3.1 Challenges
5.3.2 One Root at a Time: Newton’s Method
5.3.3 All the Roots at Once: Eigenvalue Approach
5.4 Systems of Nonlinear Equations
5.4.1 Newton’s Method
5.4.2 Discretized Newton Method
5.4.3 Broyden’s Method
5.5 Minimization
5.5.1 One-Dimensional Minimization
5.5.2 Multidimensional Minimization
5.5.3 Gradient Descent
5.5.4 Newton’s Method
5.6 Project: Extremizing the Action in Classical Mechanics
5.6.1 Defining and Extremizing the Action
5.6.2 Discretizing the Action
5.6.3 Newton’s Method for the Discrete Action
5.6.4 Implementation
5.7 Problems
6 Approximation
6.1 Motivation
6.1.1 Examples from Physics
6.1.2 The Problems to Be Solved
6.2 Polynomial Interpolation
6.2.1 Monomial Basis
6.2.2 Lagrange Interpolation
6.2.3 Error Formula
6.2.4 Hermite Interpolation
6.3 Cubic-Spline Interpolation
6.3.1 Three Nodes
6.3.2 General Case
6.3.3 Implementation
6.4 Trigonometric Interpolation
6.4.1 Fourier Series
6.4.2 Finite Series: Trigonometric Interpolation
6.4.3 Discrete Fourier Transform
6.5 Least-Squares Fitting
6.5.1 Chi Squared
6.5.2 Straight-Line Fit
6.5.3 General Linear Fit: Normal Equations
6.6 Project: Testing the Stefan–Boltzmann Law
6.6.1 Beyond Linear Fitting
6.6.2 Total Power Radiated by a Black Body
6.6.3 Fitting to the Lummer and Pringsheim Data
6.7 Problems
7 Integrals
7.1 Motivation
7.1.1 Examples from Physics
7.1.2 The Problem to Be Solved
7.2 Newton–Cotes Methods
7.2.1 Rectangle Rule
7.2.2 Midpoint Rule
7.2.3 Integration from Interpolation
7.2.4 Trapezoid Rule
7.2.5 Simpson’s Rule
7.2.6 Summary of Results
7.2.7 Implementation
7.3 Adaptive Integration
7.3.1 Doubling the Number of Panels
7.3.2 Thoughts before Implementing
7.3.3 Implementation
7.4 Romberg Integration
7.4.1 Richardson Extrapolation
7.4.2 Romberg Recipe
7.4.3 Implementation
7.5 Gaussian Quadrature
7.5.1 Gauss–Legendre: n = 2 Case
7.5.2 Gauss–Legendre: General Case
7.5.3 Other Gaussian Quadratures
7.6 Complicating the Narrative
7.6.1 Periodic Functions
7.6.2 Singularities
7.6.3 Infinite Intervals
7.6.4 Multidimensional Integrals
7.6.5 Evaluating Different Integration Methods
7.7 Monte Carlo
7.7.1 Random Numbers
7.7.2 Monte Carlo Quadrature
7.7.3 Monte Carlo beyond the Uniform Distribution
7.7.4 Implementation
7.7.5 Monte Carlo in Many Dimensions
7.8 Project: Variational Quantum Monte Carlo
7.8.1 Hamiltonian and Wave Function
7.8.2 Variational Method
7.9 Problems
8 Differential Equations
8.1 Motivation
8.1.1 Examples from Physics
8.1.2 The Problems to Be Solved
8.2 Initial-Value Problems
8.2.1 Euler’s Method
8.2.2 Second-Order Runge–Kutta Methods
8.2.3 Fourth-Order Runge–Kutta Method
8.2.4 Simultaneous Differential Equations
8.3 Boundary-Value Problems
8.3.1 Shooting Method
8.3.2 Matrix Approach
8.4 Eigenvalue Problems
8.4.1 Shooting Method
8.4.2 Matrix Approach
8.5 Project: Poisson’s Equation in Two Dimensions
8.5.1 Examples of PDEs
8.5.2 Poisson’s Equation via FFT
8.6 Problems
Appendix A Installation and Setup
Appendix B Number Representations
B.1 Integers
B.2 Real Numbers
B.2.1 Single-Precision Floating-Point Numbers
B.2.2 Double-Precision Floating-Point Numbers
B.3 Problems
Appendix C Math Background
C.1 Taylor Series
C.2 Matrix Terminology
C.3 Probability
C.3.1 Discrete Random Variables
C.3.2 Continuous Random Variables
Bibliography
Index