Exercise 2


Assigned: 4/27/98Due: 5/1/98

Using the computer we can generate a large number of samples from a random variable. We will explore some of the concepts from random variables -- the density function, transformation of random variables, and conditional density -- by examining relative frequencies of random numbers.

Please do the following and answer the questions:

  1. As we discussed in class, a density function is just a histogram with infinitesimally wide bins and an infinite number of samples. Use rand to generate 100 random numbers. From these numbers, create a 10-bin histogram and display using hist. What is the expected shape of the histogram? Why does the plot vary from its expected shape? Run the experiment a couple more times with a new set of random numbers. Describe what happens to the plot.

  2. Rerun the experiment above with 10000 random numbers. How does the bar plot change from the exercise above? Why?

  3. Run the experiment with randn, 10000 random numbers, and 30 bins. What is the shape of the histogram?

  4. Generate 10000 random numbers using randn and then multiply each number by 2. Display a 30-bin histogram, and describe the change compared to the exercise above. Explain any differences you observe. What does multiplying by 2 do to the variance?

  5. Some transformations of random variables are difficult to do analytically. However, they are straightforward to simulate. Generate a set of 10000 random phases in the range [0,2pi) using rand and scaling by 2pi. Transform the phase variable by computing the sine of the phase. NOTE: You don't need to use loops. Just use:

    sn = sin(2*pi*u);
    

    where u is the vector obtained from rand.

    Look at the 100-bin histogram of the phases and the transformed values. Do they look the same or similar in shape? Submit a plot of the two histograms.

  6. Consider a conditional density function based on a Gaussian random variable with mean=3 and variance=1 conditioned on X > 4. Approximate the conditional density function using a histogram by first generating 10000 samples from this Gaussian random variable using randn and then adjusting the mean and variance appropriately. Then extract only those values that are > 4. Try the following syntax to do the extraction:

    xnew = xold(xold>4);
    
    Then find the 30-bin histogram and compare this to the histogram of the Gaussian without the condition. Explain how the condition changes the density function. Submit a plot of the conditional histogram.

  7. Suggest another exercise that would help you understand this material better.