Computational Physics - Department of Physics

(Axel Boer) #1

368 11 Outline of the Monte Carlo Strategy


x(y) =P(y) =

∫y
0

(n− 1 )ban−^1
(a+bx)n
dy′,

resulting in


x(y) = 1 −

1

( 1 +b/ay)n−^1

,

or
y=
a
b


(

( 1 −x)−^1 /(n−^1 )− 1

)

.

With the random variablex∈[ 0 , 1 ]generated by functions likeran 0 , we have again the appro-
priate random variableyfor a new PDF.


11.4.1.4 Normal Distribution


For the normal distribution, expressed here as


g(x,y) =exp(−(x^2 +y^2 )/ 2 )dxdy.

it is rather difficult to find an inverse since the cumulative distribution is given by the error
functioner f(x)


erf(x) =√^2
π

∫x
0

e−t^2 dt.

We obviously would like to avoid computing an integral everytime we need a random variable.
If we however switch to polar coordinates, we have forxandy


r=

(

x^2 +y^2

) 1 / 2

θ=tan−^1
x
y

,

resulting in
g(r,θ) =rexp(−r^2 / 2 )drdθ,


where the angleθcould be given by a uniform distribution in the region[ 0 , 2 π]. Following
example 1 above, this implies simply multiplying random numbersx∈[ 0 , 1 ]by 2 π. The variable
r, defined forr∈[ 0 ,∞)needs to be related to to random numbersx′∈[ 0 , 1 ]. To achieve that,
we introduce a new variable
u=


1

2 r

(^2) ,
and define a PDF
exp(−u)du,
withu∈[ 0 ,∞). Using the results from example 2 for the exponential distribution, we have
u=−ln( 1 −x′),
wherex′is a random number generated forx′∈[ 0 , 1 ]. With
x=rcos(θ) =



2 ucos(θ),

and
y=rsin(θ) =



2 usin(θ),

we can obtain new random numbersx,ythrough


x=


−2 ln( 1 −x′)cos(θ),
Free download pdf