PHYCS 3730/6730
Exercise 03 (lab03)

Python coding exercises


Exercise 1.

Create a 2-D grid of x,y points in the unit square ([0,0]->[1,1]) using numpy's meshgrid routine. Use this grid to estimate the value of a f=exp(-x**2-0.5*y**2) over this domain. Test convergence by varying the number of grid points. Compare your results with a Monte Carlo integrator.

Exercise 2.

A select group is invited to attend a special event. 30 invites are sent out, but the acceptance rate ("Yes" on the RSVP) is 30%. What is the likelihood that more than 12 will accept? And how many in the case that 50% of the invitees will only accept if one specific invitee accepts (chance of that is 40%)?

Exercise 3.

Draw N = 10000 samples from each of three distributions, (1) uniform (P(x)=1 on [0,1]), (2) exponential (p(x)~exp(-x) for x>=0), and (3) normal. Plot histograms for each case and calculate mean, std.dev., var, skewness (<(x-mu)^3/sigma^3> and kurtosis (sometimes called "excess kurtosis", (<(x-mu)^4/sigma^4>-3).

Exercise 4.

A measurement x=1.0 has error that is normally distributed with sigma=0.1. Use a Monte Carlo method to determine 68.3% confidence limits. Repeat for the case of y=exp(x). Use conventional propogation of errors (to first order) to get an analytical estimate and compare with your numerical value.

Exercise 5.

Implement the Box-Muller algorithm for generating a normal RNG.