November 6, 2014 --- Class 21---Sample Mean Method (revisited), Inverse Transform
Method applied to exponential distribution, Box-Muller Method
Activities:
Sample Mean Method (revisited)
I left out a factor of 4 when computing the error our program should have
in the last class. When I prepared the notes for that class, I put in
the correct calculation. Please see notes for Class 20 for details.
I used Mathematica to visualize the variance for both the hit-or-miss
method and the sample mean method. Hit-or-miss is equivalent to a function
that is 1 for 0myfile.2
To take a file with one number per line and then print pairs of numbers
is also pretty easy.
awk '{ if( NR % 2 == 1) x=$i; else print x,$1}' myfile.2 >myfile.3
In Mathematica we could instead have used
Do[Write["myfile", v[[i,1]], " ", v[[i,2]]], {i, Length[v]}]
to print two words per line. Note that we really do need the
string of blanks in double quotes or the two numbers will have
no space between them. How annoying! It is good to learn the options
of the Export function.
The file that has two words per line will work for either the
scatter plot or histogram. However, it is useful to know these simple
awk commands.
We prepared one graph with the x and y
numbers from the Box-Muller method histogrammed separately. here are
appropriate commands:
#!/bin/csh
(awk '{print $1}' myfile | hist -n 40 -x -4 4 -g 2 -m 1;\
awk '{print $2}' myfile | hist -n 40 -x -4 4 -g 2 -m 2) | axis |
xplot
Autocorrelation
We briefly introduced the autocorrelation at the end of the class.