Playing with random numbers
February 24, 2016
BoxMuller transform
Suposse u and v are indepedent random variables that are
uniformly distributed in the interval (0,1). Let
z0 = Rcos = 2ln(u )cos (2 v )
p
z1 = Rsin = 2ln(u )sin(2 v )
p
Then z0 and z1 are indepedent random variables with a standard
normal distribution.
The derivation is based on a property of a two-dimensional Cartesian system,
where X and Y coordinates are described by two independent and normally
distributed random variables, the random variables for R
2 and (shown above)
in the corresponding polar coordinates are also independent.
Implementation in code
Fortran code is used to smear array of data using Box -Miller
transform. The implementation in fortran code generates values
from any normal distribution with mean and variance 2 . If Z is
a standard normal deviate, then x = Z + will have a normal
distribution with mean and standard deviation .
x (i ) = x (i ) + perc (z0 + )
x (i + 1) = x (i + 1) + perc (z1 + )
perc - embedded variable by us (from UNTZ), determining
percentage of smearing
percentage=0.05
3
original
nEW
2.5
1.5
0.5
-0.5
-1
0 10 20 30 40 50 60
percentage=0.07
3
original
nEW
2.5
1.5
0.5
-0.5
-1
0 10 20 30 40 50 60
percentage=0.10
3
original
nEW
2.5
1.5
0.5
-0.5
-1
0 10 20 30 40 50 60
}
percentage=0.15
3
original
nEW
2.5
1.5
0.5
-0.5
-1
0 10 20 30 40 50 60
percentage=0.25
3
original
nEW
2.5
1.5
0.5
-0.5
-1
0 10 20 30 40 50 60
percentage=0.40
3
original
nEW
2.5
1.5
0.5
-0.5
-1
0 10 20 30 40 50 60
percentage=1.00
3
original
nEW
2.5
1.5
0.5
-0.5
-1
0 10 20 30 40 50 60