Engr383 - applied stochastic processes - generate random


Lab Description

You will generate random sequences responding to several probability mass functions studied in class

Perform the following tasks:
1. Implement a function, my_rnd_generator, that returns a sequence of N random numbers. The function should accept the following arguments:
N: an integer specifying how long the sequence of random numbers will be.
v: a vector that corresponds to the sample space of the random variable.
p: a vector that corresponds to the probabilities for each element in v.

For example, to generate a vector, r, that corresponds to 10,000 outcomes of tossing a fair die, you should call the function as follows
N = 10000;
v = [1 2 3 4 5 6];
p = ones(1,6)/6;
r = my_rnd_generator(N,v,p);

To generate the biased die toss from lab 3, the function should be called as follows:
N = 10000;
v = [1 2 3 4 5 6];
p = [.1 .1 .1 .1 .1 .5];
r = my_rnd_generator(N,v,p);

Note that your function should adjust automatically for pmfs of various lengths (i.e. not only length 6) and shapes (i.e. not only uniform).

Hint: There are many ways to do this, including existing Matlab functions. You can use anything you want. One way to go about it is using the code below (by Kurt Hornik, used in Octave, a free software very similar to Matlab):
u = rand (1, n);
m = length (p);
s = reshape (cumsum (p / sum (p)), m, 1);
rnd = v (1 + sum ((s * ones (1, n)) <= ((ones (m, 1) * u))));
You may use any part of this code, or a variation of it, but of course I expect a detailed explanation of how it works.

2. For a random variable uniform in the range [a, b], generate a random sequence, r, of at least 100,000. Calculate the following:
a. Theoretical mean, μ.
b. Theoretical variance, σ2.
c. Sample mean, μs, i.e. average of all samples in r. Verify your result using Matlab'smean() function.

d. Sample variance, σ2s, i.e. average of all squared samples in r, minus the square of the sample mean. Verify your result using Matlab'svar()function.

e. In a figure partitioned in a 3×1 grid, plot the following:

i. The first 100 samples in r.Note that plotting all of the samples would not generate a very interesting figure.

ii. The theoreticalpmf, also showing μ and σ2.

iii. The histogram of r, also showing μs and σ2s. Note that the histogram should be very similar to the pmf (since you used at least 100,000 samples.

An example for U(-12,4), i.e. uniform discrete random variable for the inclusive interval [-12, 4], is shown in Figure 1. Please make sure that you display your results exactly as shown in Figure 1. To generate a title for the whole figure, you may use the function suplabel.m. This function is attached in Appendix A. For the example, I used the following code to invoke suplabel:

tt = ['N = ', num2str(N),', Uniform RV, U(',num2str(a),...
',',num2str(b),')'];
suplabel(tt,'t');

f. Generate plots for a couple of arbitrary ranges, including the [12, 4] Iused in the example.

1561_Figure.jpg

Figure 1. Example for part 2.

Note: You can embed greek letters in Matlabtitles and labels by typing a backward slash followed by the greek letter. For example, \Sigma for Σ and \sigma for σ. Use _ and ^ for subscripts and superscripts, respectively. For example \sigma_X^2 generates σX2

3. Repeat step 2 for the binomial distribution. Generate plots for:

a. n=24 and p = 0.2, 0.5 and 0.9, respectively.

b. Two more values for n with a at least a couple of different p values.

4. Repeat step 2 for the geometric distribution. Note that the sample space of the geometric random variable extends to infinity. Please cut of your plots at, say, n=50. If you sum over all 50probabilities in your pmf, you will not get 1, as you are ignoring the low probability samples for k>50. It will be interesting to observe how the plot varies for different ps. Generate plots for p = .1, .2, .5 and .7. What happens if you let p = 0.01 while maintaining n=50?

5. Repeat step 2 for the Poisson distribution. Once again, cut off your plots at n=50. Generate plots for α = 0.5, 3, 9, 24, and 40.

Attachment:- Appendix.rar

Solution Preview :

Prepared by a verified Expert
Applied Statistics: Engr383 - applied stochastic processes - generate random
Reference No:- TGS02211693

Now Priced at $50 (50% Discount)

Recommended (91%)

Rated (4.3/5)