Programs and data

This page contains Python programs and data that accompany the book Computational Physics by Mark Newman. You're welcome to download and use these resources freely. Comments and questions are welcome.

Resources are listed by chapter, programs first, then data files, if any. Also included are the programs from Appendix E. There are no programs or data for chapters 1 or 11.

All the resources on this page can be downloaded at once, as a single zip file, by clicking here.

Chapter 2: Python programming for physicists Calculate the position of a ball dropped from a tower Check two integers to ensure one is even and the other odd Print out the Fibonacci numbers up to 1000 Convert from polar to Cartesian coordinates Print out the wavelengths of hydrogen lines

Chapter 3: Graphics and visualization Make a density plot from the data in a file Calculate and display a Hertzsprung–Russell diagram for a catalog of nearby stars Create a 3D visualization of a simple cubic lattice Calculate and display the interference pattern generated by two circular sets of waves
circular.txt Data for the circular pattern in Fig. 3.5
millikan.txt Photon frequencies and stopping voltages from Millikan's photoelectric experiment
stars.txt Catalog of temperatures and magnitudes for 7860 nearby stars
stm.txt STM measurements of the (111) surface of silicon
sunspots.txt Data on sunspots since 1749

Chapter 4: Accuracy and speed Calculate the internal energy of a quantum simple harmonic oscillator at temperature T

Chapter 5: Integrals and derivatives Evaluate an integral using Gaussian quadrature Evaluate an integral over an infinite domain Evaluate an integral using the trapezoidal rule
altitude.txt Altitude in meters of points on the Earth's surface
stm.txt STM measurements of the (111) surface of silicon
velocities.txt Velocity of a particle over time

Chapter 6: Solution of linear and nonlinear equations Calculate an inverse hyperbolic tangent by Newton's method Find the minimum of the Buckingham potential using golden ratio search Calculate the magnetization of a ferromagnet Solve simultaneous equations by Gaussian elimination Calculate the motion of system of masses and springs Simpler program for the masses and springs

Chapter 7: Fourier transforms Calculate a DFT the slow way
blur.txt Digitized blurry image
dow.txt Daily closing values of the Dow from 2006 to 2010
dow2.txt Daily closing values of the Dow from 2004 to 2008
piano.txt Waveform of a single note played on a piano
pitch.txt An oscillating signal with noise
sunspots.txt Data on sunspots since 1749
trumpet.txt Waveform of a single note played on a trumpet

Chapter 8: Ordinary differential equations Solve a differential equation using Euler's method Solve a differential equation using 2nd-order Runge-Kutta Solve a differential equation using 4th-order Runge-Kutta Solve a differential equation out to infinity Solve simultaneous first-order differential equations Solve the nonlinear using the Bulirsch-Stoer method Calculate a trajectory using the shooting method Solve the Schrodinger equation in a square well

Chapter 9: Partial differential equations Solve Laplace's equation using the Jacobi method Solve the heat equation using FTCS

Chapter 10: Random processes and Monte Carlo methods Linear congruential random number generator Calculate the decay of a radioactive sample Rutherford scattering Monte Carlo integration Monte Carlo simulation of an ideal gas Solution of the traveling salesman problem

Useful programs Calculate integration points for Gaussian quadrature Solve a banded system of linear equations Fast discrete cosine and sine transforms Colormaps useful for physics visualizations