Physics 281 - Computational Physics

Wednesday/Friday Section

Fall 2015

Python Examples

Example Scripts

A script is a file with a set of python statements that we wish to run. It's the same as typing the statements into ipython.

fall.py - the falling ball calculation.

Example Modules

A module is a file that defnes functions, classes, and/or other variables that we want to use with other pieces of python code.

itest.py - simple module with docstring documentation.

PyPlot Examples

plot_example.py - a simple example script illistrating the plot method.

figure_example.py - example script which uses more than one figure.

hold_example.py - example script that uses the hold method.

Python Class Example

MyVector.py - demonstration of python class to manage vector data and operations.

Examples from Class

Bisector Script

bisector.py - example script using bisector algorithm.

Interpolation Example Script

interpolation_example.py - example script using linear interpolation.

Error on the Mean

error_of_the_mean_demo.py - program to make Monte Carlo simulation of error of the mean.

Histogram Example

histogram_demo.py - demo program to illustrate construction of a histogram.

Least Squares Examples

ls_example.py - program to do least squares fit to a line.

Differential Equations Examples

first_order_deq.py - solution of radioactive decay problem by Euler's method. A first order differential equation.

second_order_deq.py - solution of falling ball problem by Euler's method. A second order differential equation.

second_order_deq_2o_rk.py - solution of falling ball problem by Second Order Runge-Kutta method. A second order differential equation.

Partial Differential Equations Examples

heat_eqn.py - solution to heat (diffusion) equation. 100 cm bar with boundary conditions V=0 at one end and V=100 at the other end.

Ph281 Home