next up previous contents
Next: Histogram Plotter Up: Monte Carlo of a Previous: Hints and Tips

Possible Extension

Write some other Monte Carlo generators, but this time generate accord to some simple integratable function say X2 or sin(X). A little bit of theory here may be of use:-

Starting with a random number r in the range $0\leq r<1$ we seek a method that will generate x in the range a to b according to f(x). This requires that the probability of a value in the range x to $x+\delta x$be generated from a random number in the range r to $r+\delta r$must be proportional to

\begin{displaymath}f(x)\delta x\end{displaymath}

But the probability that the random number will lie in the range r to $r+\delta r$ is just $\delta r$. So

\begin{displaymath}\delta r~~\alpha~~f(x)\delta x.\end{displaymath}

Taking the limit and integrating gives

\begin{displaymath}r~~\alpha~~\int f(x)dx\end{displaymath}

and imposing the boundary conditions x=a when r=0and x=b when r=1 leads to

\begin{displaymath}r~~=~~{\displaystyle\int_a^x f(x)dx\over\displaystyle\int_a^b f(x)dx}\end{displaymath}

So, for example, to generate a point between 0. and 1. according to X2 use $r^{1 \over 3}$, where r is a random number between 0. and 1.

Write a program to generate points randomly inside a sphere.


next up previous contents
Next: Histogram Plotter Up: Monte Carlo of a Previous: Hints and Tips
n west (APC)
2000-03-08