Reading and references:
For each of the following exercises create the specified files with your answer(s). Submit your homework using the course submit utility as usual.
Your code should print two numbers per line: the time and the number of atoms that decayed in the time interval at that time. To be precise, print the time at the end of the interval.
Run your program with the input file ~p6720/examples/radioactive/indecay. Plot the output number of decays vs time (use points), and then, in the same plot, plot the theoretical prediction for the number of decays (use lines),
N*dt/tau exp(-t/tau) .Convert the plot to a pdf file called decay.pdf for submitting. You may use gnuplot or (if you are brave) pyplot for making the plot from your calculation. If you use gnuplot, you can combine two plots by separating the plot specifications with a comma. That is, if plot A and plot B make two separate plots, then plot A, B combines them into one plot. To plot the function above, write it as a function of x, not t. If you need to convert from Postscript to pdf, use the Unix utility epstopdf. If you use pyplot, save the figure to a pdf file using plt.savefig("figure.pdf").
Run your program with the input file ~p6720/examples/radioactive/inpoisson. Check that the number of atoms has not changed very much during this experiment. Create a histogram that shows the number of time intervals in your experiment that had 0 decays, the number that had 1 decay, etc. You may use the course hist utility or try your hand with matplotlib.pyplot.hist. You should arrange so that the histogram bins are centered on the integers.
The theoretical expectation is that the histogram is proportional to a Poisson distribution, based on the expected average number of decays in the interval dt, namely
d = N*dt/tauThe theoretical expression is
N(k) = M dk e-d/k!where M = T/dt is the number of time intervals in your experiment and k! is the factorial k(k-1)(k-2)...1. So on the same plot as your histogram, plot this prediction (as points). The easiest way to do this is to write a small Python code that writes out k and N(k) for integer k from 0 to 20 or so. Note that math.factorial(k) evaluates the factorial. Put the output numbers in a file, so you can use it as input to gnuplot.
Convert the plot to a pdf file called poisson.pdf for submitting.