Computational Physics with
Python


The Python programming language is an excellent choice for learning, teaching, or doing computational physics. It is a well-designed, modern programming language that is simultaneously easy to learn and very powerful. It includes a range of features tailored for scientific computing, including features for handling vectors, inverting and diagonalizing matrices, performing Fourier transforms, making graphs, and creating 3D graphics.

This page contains a selection of resources I've developed for teachers and students interested in computational physics and Python.

Book chapters

I'm in the process of writing a book on computational physics using the Python programming language. Here are some of the completed chapters, which you're welcome to print out, use in class, or just read for yourself. These are drafts and they may contain the occasional typo, but I believe them to be reasonably error-free. If you spot any mistakes I'd be happy to hear about them.

Example programs

The following files contain copies of the example programs from the chapters above. All programs are in Python version 3, but they will work fine in version 2 also (technically version 2.6 or later) if you add this line to the beginning of the program:

from __future__ import print_function,division
The file names below correspond to the names printed in the margins of the chapter pages next to each program.

Chapter 2:

Chapter 3:

Chapter 4:

Chapter 5:

Data sets

Here are some data sets that accompany the chapters and problem sets above:

Miscellaneous useful code

Here are a few other pieces of Python code that are useful for some of the exercises.


Last modified: February 3, 2012

Special thanks to Gus Evrard, Brad Orr, Len Sander, and Bruce Sherwood for Python info and comments.

Sources for data sets:

Mark Newman