PHYS 306:  Computational Physics Lab

Winter 2009

Homework #1
(Due:  February 10, 2009)



  1. Do in-class exercise 3.1. Turn in your programs, as well as all requested output and graphs.

  2. Write a program to generate $N=10,000$ points $\{x_i\}$ distributed according to the (unnormalized) distribution

    \begin{displaymath}
p(x) \propto xe^{-x}
\end{displaymath}

    for $0\le x\le 1$. Draw a properly normalized histogram of the points $\{x_i\}$ with binning interval 0.05, and compare it to the normalized $p(x)$ by plotting it on the same graph.

  3. Use Monte-Carlo integration to estimate the volume contained within a sphere of radius 1 ($x^2+y^2+z^2<1$) that also lies below the plane $x+y+z=\frac12$ (i.e. $x+y+z<\frac12$) and above the plane $x+y+2z=0$. Perform your calculations with $N$ random points in the volume under consideration, for $N =
100, 1000, 10000, 100000$, and $1000000$. Turn in your program and the results of the integration (i.e. your estimate of the volume), along with an error estimate, for each value of $N$.









Steve McMillan 2010-04-22