Box Muller

From Statistical, Dynamic, and Computational Models

Jump to: navigation, search

Objective

Using a very limited understanding of Matlab, generate some values and determine how they are distributed before and after a transformation.

Assignment

One way to generate a random number take from a Gaussian distribution is to use the Box-Muler formula

w = sin(2πv)( − 2lnu)1 / 2

where u and v are real numbers generated from a uniform distribution by Matlab's rand() command. Write a script that

  1. Generates N uniformly distributed random numbers twice, storing them in an arrays u and v
  2. Displays a histogram of the untransformed variables with the
hist(u,25)    % 25 is the number of bins used in the histogram, experiment with this

command. Are they indeed uniform? What happens when N increases?

  1. Computes w from the two uniform distributions. Notice that you are going to have to be very careful with .*, and .^ type operation.
  2. Generate a second, transformed histogram.
  3. Explore, by running the script numerous times, how much the value used for N impacts the Gaussian.

Note that to open a second figure, you use

figure(2)
hist(w,25)

figures can be cleared with

clf()

and closed with

close()

both of which can take a numerical value and impact a particular figure.

Personal tools