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
| dropped.py
| Calculate the position of a ball dropped from a tower
|
| evenodd.py
| Check two integers to ensure one is even and the other odd
|
| fibonacci.py
| Print out the Fibonacci numbers up to 1000
|
| polar.py
| Convert from polar to Cartesian coordinates
|
| rydberg.py
| Print out the wavelengths of hydrogen lines
|
Chapter 3: Graphics and visualization
| circular.py
| Make a density plot from the data in a file
|
| hrdiagram.py
| Calculate and display a
Hertzsprung–Russell diagram for
a catalog of nearby stars
|
| lattice.py
| Create a 3D visualization of a simple
cubic lattice
|
| ripples.py
| 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
| qsho.py
| Calculate the internal energy of a quantum
simple harmonic oscillator at temperature T
|
Chapter 5: Integrals and derivatives
| gaussint.py
| Evaluate an integral using Gaussian quadrature
|
| intinf.py
| Evaluate an integral over an infinite domain
|
| trapezoidal.py
| 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
| atanh.py
| Calculate an inverse hyperbolic tangent by
Newton's method
|
| buckingham.py
| Find the minimum of the Buckingham potential
using golden ratio search
|
| ferromag.py
| Calculate the magnetization of a ferromagnet
|
| gausselim.py
| Solve simultaneous equations by Gaussian elimination
|
| springs.py
| Calculate the motion of system of masses and springs
|
| springsb.py
| Simpler program for the masses and springs
|
Chapter 7: Fourier transforms
| dft.py
| 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
| euler.py
| Solve a differential equation using Euler's method
|
| rk2.py
| Solve a differential equation using 2nd-order Runge-Kutta
|
| rk4.py
| Solve a differential equation using 4th-order Runge-Kutta
|
| odeinf.py
| Solve a differential equation out to infinity
|
| odesim.py
| Solve simultaneous first-order differential equations
|
| bulirsch.py
| Solve the nonlinear using the Bulirsch-Stoer method
|
| throw.py
| Calculate a trajectory using the shooting method
|
| squarewell.py
| Solve the Schrodinger equation in a square well
|
Chapter 9: Partial differential equations
| laplace.py
| Solve Laplace's equation using the Jacobi method
|
| heat.py
| Solve the heat equation using FTCS
|
Chapter 10: Random processes and Monte Carlo methods
| lcg.py
| Linear congruential random number generator
|
| decay.py
| Calculate the decay of a radioactive sample
|
| rutherford.py
| Rutherford scattering
|
| mcint.py
| Monte Carlo integration
|
| mcsim.py
| Monte Carlo simulation of an ideal gas
|
| salesman.py
| Solution of the traveling salesman problem
|
Useful programs
| gaussxw.py
| Calculate integration points for Gaussian quadrature
|
| banded.py
| Solve a banded system of linear equations
|
| dcst.py
| Fast discrete cosine and sine transforms
|
| colormaps.py
| Colormaps useful for physics visualizations
|