Exercise 1


Assigned: 08/25/11Due: 08/30/11

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. To start MATLAB on a PC in the COE, simply go to Start->Programs and start MATLAB from the menu.
  2. To become familiar with some of the ``gee-whiz'' capabilities of MATLAB, try running demo and then clicking on `Graphics'' and then ``Fourier series expansion''. Pay attention to the text that is generated in the window. This text shows the MATLAB commands that were used to generate the examples. You may also wish to explore some of the other examples by clicking on different buttons.
  3. Run intro to get an idea of the basic capabilities of MATLAB.
  4. You can type doc at any time to get a hypertext version of the MATLAB Reference Guide or help <cmd> to get help on specific commands (assuming this is installed on the machine where you are).
  5. If you need help on a MATLAB function and the hyperlink doesn't work, simply type "help <function>" at the MATLAB prompt.
  6. 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. 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?

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

  3. Run the experiment ten times each with trial=1000 and with trial=100000. What is happening to the variation of the relative frequency as the number of trials increases? Why?

  4. Write a simple MATLAB script by generalizing the ideas in the script above. The script should estimate the relative frequency of obtaining a 2 by spinning a spinner with 5 equally likely numbers in the 1-5 range . Report your answers with trial=100000, and include the script in your write-up. The method of turning in the write-up will be described shortly.

    NOTE: All out-of-class work is to be done independently. Sharing of programming tips and discussing general concepts is ok. Collaborating on experiments or code-writing is not. Any such collaboration on these assignments will be considered an act of academic dishonesty and will be treated accordingly.