HW053
Math 2984 - Fall 2017
Intro to Mathematical Problem Solving


TASK: Given the frequencies of an event with outcomes that have unequal likelihoods, do a simulation.


COMMENT: An event has N possible outcomes, which we think of as outcomes 1, 2, ..., N. The outcomes are not equally likely. We watch the event happen M times, and write down in the vector F the frequency of each event. We want to use the frequencies to compute probabilities P, and use the probabilities to make a cumulative probability vector C.

You will write a function which will get as input the vector F. You need to count the entries in F to get N. You need to sum the entries in F to get M. You need to compute the probability vector P. Then you need to compute the cumulative probability vector C.

To do the simulation, create a BIN row vector with N columns. Run a FOR loop J=1:M times. Each time pick a random value R and find the first entry I such that R < C(I). Increment the I-th bin.

Compare your observed data against your simulated data by making two bar plots, one using F, and one using BIN.


INSTRUCTIONS:

        function hw053 ( f )

        n = how many entries are there in F?
        m = what is the sum of the entries of F?
        p = create probabilities P from frequencies F
        c = use a for loop to compute the cumulative sums, or 
             find a MATLAB function which will compute them.

        bin = row vector with N columns
        j goes from 1 to m, to simulate m outcomes
          r is random
          i goes from 1 to n, to check each cumulative probability
            if r is less than c(i), increment i-th bin and break.

        bar ( 1:n, f )
        bar ( 1:n, bin )
      


CHECK: For a frequency vector like F = [ 12, 34, 56, 78, 90 ], you might get a simulated data bar plot like this:


SUBMIT: Your function file should be named "hw053.m", and begin with:

        % hw053.m
        % YOUR NAME
        % This script (describe what it does)