Computational Physics
Motivation
I once took a class on computational physics in grad school, but the class was taught using Fortran 90, which is usually used for intense numerical applications in academia and maybe industry, but not much else. I wanted to learn some Python and also review and learn more about computational techniques, so I decided to work my way through Mark Newman’s Computational Physics. My solutions to the exercises can be found here.
Thoughts
The most interesting thing I learned was the idea of Richardson extrapolation. The book introduces this through Romberg integration and the Bulirsch-Stoer method of solving ordinary differential equations.
Here’s the basic idea. Suppose you have a method to approximate some quantity , and that this method depends on a small parameter in such a way that the approximations get better and better the smaller is. As a concrete example, think of computing a definite integral and as the step size in a numerical integration method such as the trapezoidal rule.
The idea of Richardson extrapolation is that by approximating with two different (appropriately related) values of , you can combine them to get a new estimate with a much smaller error estimate. How those values of should be related and how you combine them depend on the specifics of what you’re computing.
For example, in Romberg integration you compute an estimate with step size , then compute a second estimate with a step size . You get a new, better estimate by adding to a term proportional to .
Examples
Adaptive Bulirsch-Stoer
![An oscillating chemical reaction modeled by a pair of coupled ODEs. Oscillating chemical reaction](/static/8c52e0bf5b9dc3dc7d4c93eb342ce8ea/d67fd/bulirsch-stoer.png)
In the example above, we solve the coupled, nonlinear ordinary differential equations
with with initial conditions and accuracy of per unit time. We solved this system using an adaptive Bulirsch-Stoer method. See my solution here.
Adaptive trapezoidal rule
![The dots represent the endpoints of the integration slices used in the trapezoidal rule. Notice that there are fewer slices in regions where f(x) changes less rapidly. Adaptive trapezoidal rule example](/static/a6253a0e3bb8c0182f7fe7bf48810976/d67fd/adap_trap.png)
Another example is using an adaptive trapezoidal rule to estimate the value of
We use the trapezoidal rule to compute the integral, but the step size is automatically adjusted so that the error estimate for each integration slice is no greater than some target value (so that the overall error is bounded). See my solution here.
2D Ising model
Of course we also simulate the well-known 2D ferromagnetic Ising model. We perform a Markov chain Monte Carlo simulation of the Ising model on a 100 × 100 square lattice with zero magnetic field and nearest-neighbor interactions.
![The system after ten million simulation steps. Note we are near the critical temperature. The blue stands for a down spin, and orange stands for an up spin. system of spins on 100 by 100 lattice](/static/a494b0ee34068b421bac1608f5a0f5ad/8710b/ising-model.png)
![The average magnetization per spin of the system during each step of the simulation. Note we are near the critical temperature. plot of magnetization](/static/a10ca361dafde4785c363d233f961f35/6af66/magnetization.png)