Skip to content
## provide an estimate of the probability.

### provide an estimate of the probability.

### Winter 2018 ENGR 383 â€“ APPLIED STOCHASTIC PROCESSES Department of Engineering & Design at Eastern Washington University LAB #2: DISCRETE RANDOM VARIABLES Objective To become familiar with histograms and various families of discrete random variables. Lab Description Histograms are graphical representations of the distribution of data. A normalized histogram, thus, should provide an estimate of the probability distribution of the outcomes of an experiment. Generating the histogram for discrete data can be as easy as running an experiment several times and counting the number of occurrences of each outcome. In this lab you will generate random sequences responding to several families of random variables, and plot their histograms to compare them to the actual PMFs. I encourage you to read Matlabâ€™s help page on discrete distributions, which you can find in the following location: https://www.mathworks.com/help/stats/discrete-distributions.html A. Consider the discrete Uniform(l,k) random variable. Do the following: 1. Generate the PMF of the uniform(l,k) distribution for, say, l = -12, k = 4 (use the book as reference if these parameters donâ€™t mean anything to you). 2. Obtain the expected value and the variance (i.e. theoretical values) for the corresponding PMF. 3. Generate an N-point vector, say x, of random numbers that have a uniform distribution. Choose a reasonable size for N, and explain your choice. 4. Calculate the sample mean and the sample variance of the vector you generated in step 3. Note that these should approximate the values you found in step 2. 5. In the same figure, plot the following three things (in that order): a. The first 100 values of the random vector you generated. b. The PMF of the distribution. i. The title of this subplot should state the type of distribution and the parameters used. ii. The title should also show the mean and variance you obtained in step 2. iii. The mean should be indicated with a vertical, red line, of width 3. c. The histogram you generated form the random vector. i. The title of this subplot should show the sample mean and sample variance you calculated in step 4. The scales of the horizontal and vertical axes of the second and third subplots should be identical. An example of what I am looking for is shown in the next page. 6. Repeat steps 1-5 for other two other values of l and k. B. Repeat part A for: a. Geometric(p) random variable b. Binomial(n, p) random variable c. Pascal(k, p) random variable d. Poisson(ï¡) random variable Note: for each random variable you should test at least three different parameters (of your choice). ENGR 383 LAB #2 Page 2 of 5 ENGR 383 LAB #2 Page 3 of 5 To generate a title for the whole figure (not shown in the figure in the previous page, you may use the function suplabel.m. This function is not part of any Matlab release, and is attached in Appendix A. To create strings that have variables and text, you can use the num2str() function. An example is shown below: tt = [‘Uniform(‘,num2str(k), ‘,’ num2str(l), ‘) RV, m=’, … num2str(m), ‘, v=’, num2str(v)]; Note that three dots at the end of a line are used to extend a command into the next line. You can embed greek letters in Matlab titles 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 ï³ X ï€² ï€® Deliverables: You should turn in, via email, at least the following 4 items in a single, cohesive PDF document: 1. Explanation of the code you used to generate the random data. 2. All plots requested, with the corresponding very well documented Matlab code you used to obtain them. Of course I only need one sample Matlab code for each of the distributions. For example, if you did ranges [-12, 4], [4,10], and [2,12] for the uniform distribution, I only need to see Matlab code for one of the three. 3. Analysis/discussion of your code/results. Note that I do expect at least a brief explanation of what is a discrete random variable, what is a PMF, how/why the histogram relates to it, etc. Additionally, turn in via email to the instructor ([email protected], not Canvas message): 1. All Matlab code, with instructions on how to run it. The subject should be: â€œEENG 383 â€“ Lab number â€“ Your first and last name.â€ 2. The single PDF file should be named as follows â€œEENG383_Lab2_Rodriguez-Marek.pdf,â€, but replacing my last name with yours. I will take points off if you donâ€™t have it exactly like that (because if you donâ€™t do it, then I have to do it for you! ïŠ). NOTE: I expect your lab report in PDF format, and your code (i.e. a â€œ.mâ€ file with instructions to use it). Finally, you need to demonstrate your working code (at least a couple of plots for each RV) to the instructor to get credit for the lab. Signature page must be turned in with your report. _______________________________ Instructorâ€™s Signature ENGR 383 LAB #2 Page 4 of 5 Appendix A function [ax,h]=suplabel(text,whichLabel,supAxes) % PLaces text as a title, xlabel, or ylabel on a group of subplots. % Returns a handle to the label and a handle to the axis. % [ax,h]=suplabel(text,whichLabel,supAxes) % returns handles to both the axis and the label. % ax=suplabel(text,whichLabel,supAxes) % returns a handle to the axis only. % suplabel(text) with one input argument assumes whichLabel=’x’ % % whichLabel is any of ‘x’, ‘y’, ‘yy’, or ‘t’, specifying whether the % text is to be the xlable, ylabel, right side y-label, % or title respectively. % % supAxes is an optional argument specifying the Position of the % “super” axes surrounding the subplots. % supAxes defaults to [.08 .08 .84 .84] % specify supAxes if labels get chopped or overlay subplots % % EXAMPLE: % subplot(2,2,1);ylabel(‘ylabel1’);title(‘title1’) % subplot(2,2,2);ylabel(‘ylabel2’);title(‘title2’) % subplot(2,2,3);ylabel(‘ylabel3’);xlabel(‘xlabel3’) % subplot(2,2,4);ylabel(‘ylabel4’);xlabel(‘xlabel4’) % [ax1,h1]=suplabel(‘super X label’); % [ax2,h2]=suplabel(‘super Y label’,’y’); % [ax3,h2]=suplabel(‘super Y label (right)’,’yy’); % [ax4,h3]=suplabel(‘super Title’ ,’t’); % set(h3,’FontSize’,30) % % SEE ALSO: text, title, xlabel, ylabel, zlabel, subplot, % suptitle (Matlab Central) % Author: Ben Barrowes <[email protected]> %modified 3/16/2010 by IJW to make axis behavior re “zoom” on exit same as %at beginning. Requires adding tag to the invisible axes currax=findobj(gcf,’type’,’axes’,’-not’,’tag’,’suplabel’); if nargin < 3 supAxes=[.08 .08 .84 .84]; ah=findall(gcf,’type’,’axes’); if ~isempty(ah) supAxes=[inf,inf,0,0]; leftMin=inf; bottomMin=inf; leftMax=0; bottomMax=0; axBuf=.04; set(ah,’units’,’normalized’) ah=findall(gcf,’type’,’axes’); for ii=1:length(ah) ENGR 383 LAB #2 Page 5 of 5 if strcmp(get(ah(ii),’Visible’),’on’) thisPos=get(ah(ii),’Position’); leftMin=min(leftMin,thisPos(1)); bottomMin=min(bottomMin,thisPos(2)); leftMax=max(leftMax,thisPos(1)+thisPos(3)); bottomMax=max(bottomMax,thisPos(2)+thisPos(4)); end end supAxes=[leftMin-axBuf,bottomMin- axBuf,leftMax- leftMin+axBuf*2,bottomMax-bottomMin+axBuf*2]; end end if nargin < 2, whichLabel = ‘x’; end if nargin < 1, help(mfilename); return; end if ~isstr(text) | ~isstr(whichLabel) error(‘text and whichLabel must be strings’) end whichLabel=lower(whichLabel); ax=axes(‘Units’,’Normal’,’Position’,supAxes,’Visible’,’off’,’tag’,’supl abel’); if strcmp(‘t’,whichLabel) set(get(ax,’Title’),’Visible’,’on’) title(text); elseif strcmp(‘x’,whichLabel) set(get(ax,’XLabel’),’Visible’,’on’) xlabel(text); elseif strcmp(‘y’,whichLabel) set(get(ax,’YLabel’),’Visible’,’on’) ylabel(text); elseif strcmp(‘yy’,whichLabel) set(get(ax,’YLabel’),’Visible’,’on’) ylabel(text); set(ax,’YAxisLocation’,’right’) end for k=1:length(currax), axes(currax(k));end % restore all other axes if (nargout < 2) return end if strcmp(‘t’,whichLabel) h=get(ax,’Title’); set(h,’VerticalAlignment’,’middle’) elseif strcmp(‘x’,whichLabel) h=get(ax,’XLabel’); elseif strcm

p(‘y’,whichLabel)

### Disclaimer

### Quick Links

### Quick Links

### Stay Connected

p(‘y’,whichLabel)

© 2019 AssignmentFreelancers. All Rights Reserved.