Exercise 1


Assigned: 4/8/98Due: 4/13/98 (note the change)

A computer is really great for simulating random experiments very quickly. It isn't so good for getting exact probabilities or determining functions. However, it is possible to use the idea of fast random experiments to approximate probabilities or functions related to probabilities. This exercise will help you to become familiar with Matlab and to do some simple probability experiments.

Getting Started

  1. Run user-setup and select math/matlab/5.0.

  2. Edit your .cshrc file. In the personal customization area, add the line:
    setenv MATLABPATH /home/sigproc/sjreeves/matlab/teaching
    

  3. To make these changes go into effect without having to logout and log back in, type
    % source .cshrc
    
    at the command line of the window in which you are working.

  4. Invoke Matlab by typing matlab at the command line.

  5. To become familiar with some of the ``gee-whiz'' capabilities of Matlab, try running demo.

  6. Run intro to get an idea of the basic capabilities of Matlab.

  7. You can type doc at any time to get a hypertext version of the Matlab Help Desk or help <cmd> to get help on specific commands.

  8. Although this class will only touch on digital signal processing, the tips I give for using Matlab for DSP are very useful for this class as well.
Please do the following and answer the questions:
  1. Have you ever discussed random number generators in a programming class? If so, explain briefly what you were told. (This is a survey question, not a knowledge question. If you weren't taught this, say so.)

  2. We can simulate flipping a coin by generating random numbers from a uniform distribution in [0,1) and considering numbers < 0.5 to be tails and numbers >= 0.5 heads.

    Do the following in Matlab:

    trials = 100;
    flip = rand(trials,1);
    heads = (flip >= 0.5);
    percentheads = sum(heads)/trials
    
    What is the relative frequency of heads?

  3. Run the experiment again. Do you get the same answer? Explain.

  4. Run the experiment a few times with trial=1000 and with trial=100000. What is happening to the relative frequency as the number of trials increases? Why?

  5. Write a simple Matlab script to estimate the relative frequency of rolling a six with a die by generalizing the ideas in the script above. Submit the script.