0% found this document useful (0 votes)
16 views10 pages

Box-Muller Transform in Fortran Code

The document discusses the Box-Muller transform, which uses uniformly distributed random variables to generate independent standard normal random variables. It describes implementing the transform in Fortran code to generate random numbers from any normal distribution by adding the standard normal values to the mean and scaling by the standard deviation. The code is shown smearing an array of data by varying percentages using randomly generated values from the Box-Muller transform.

Uploaded by

Tenis Vijesti
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views10 pages

Box-Muller Transform in Fortran Code

The document discusses the Box-Muller transform, which uses uniformly distributed random variables to generate independent standard normal random variables. It describes implementing the transform in Fortran code to generate random numbers from any normal distribution by adding the standard normal values to the mean and scaling by the standard deviation. The code is shown smearing an array of data by varying percentages using randomly generated values from the Box-Muller transform.

Uploaded by

Tenis Vijesti
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like