October 14, 2004 --- Class 14 --- Random Walks, Biased Estimators
Activities:
Random walks
We continued the discussion started in the previous class of how
to make Mathematica generate random walks. Recall:
randomStep[x_] := x + 2 Random[Integer] - 1
w = NestList[randomStep, 0, 5000];
We can make 1000 random walks of length 5000 and print the
ending value from each walk
v = Table[ w = NestList[randomStep, 0, 5000]; w[[5000]], {i, 1000}]
Do[ Write["oct13.dat", v[[i]] ], {i, Length[v]}]
Note use of Length function to make sure all of v is printed without
needing to know how long it is.
We contrasted the time it took to generate these walks with the time
to generate the random walks using a C program. The C progam was much
faster, but there is more coding required. The C program is
~sg/rwalk_fsr.c
A simple histogram program hist was introduced. More about it will
appear later. We also used my blockerr program to find the mean and
error in the mean from a file with numbers. Alternatively, you may use
Mathematica for these operations. The following indented material was
not part of the class lesson, but you might find it useful.
Mathematica can also do its own histograms. These are part of the
Graphics add-on package.
Needs["Graphics`Graphics`"]
Histogram[v]
Mathematica can do statistical analysis. For this, you will need
the DescriptiveStatistics sub-package in the Statistics package:
Needs["Statistics`DescriptiveStatistics`"]
Mean[v]
Variance[v]
Biased Esimators Using Mathematica
We started by teaching Mathematica to do multiple integrals
analytically and then having it get a numerical result as described
in the handout. In the next class, we will make a table of values
from both analytic and numerical integration.