Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ntuition about r time on numerical experiments. This proble will take advantage of MATLAB's pseudorandom2 number generation and plotting functions. In particular, we will be

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

ntuition about r time on numerical experiments. This proble will take advantage of MATLAB's pseudorandom2 number generation and plotting functions. In particular, we will be generating and plotting many (independent) realizations of a random variable. (a) The code below generates numtrials realizations of a Binomial(n, p) random variable and plots them in sequence. Play around to get sense for the impact of changing n and p Generate and turn in a plot for 100 realizations of a Binomial(10, 1/2) random variable. Parameters n 10; p = 0.5; numtrials 100 ; %Generate Binomial RVs X - random ('Binomial' ,n, p,numtrials,1); %Plot stem(X) axis([1 numtrials 0 n]) xlabel('Trial Number') ylabel ('X') (b) To get a sense for how frequently cach possible value occurs, it is uscful to look at the histogram, normalized by the number of trials. The code framework below3 generates a bar plot of the number of occurrences of cach value from 0 to n, normalized by the number of trials. Your job is to fill in the lines of code needed to count the number of occurrences of the values i in the sequence X and also calculate the PMF of a Binomial(n, p) random variable for X-i. Then, for n 10 and p 1/2, generate and turn in plots for 100, 1000, and 10000 trials to get a sense for how the histogram converges to the true PMF. (If you don't want to print out your entire code as part of your homework, you can just write the relevant lines of code that you wrote directly on the graph print out %(Normalized) Histogram counts - zeros (1,n+1); for i -0:n counts (1+1) = %%Your code for number of occurrences of value i in X end normalizedcounts - countsumtrials; %Probability Mass Function pmfvalues zeros (1,n+1); for i -0:n pmfvalues (1+1) -%%Your code for PMF of ith value end %Plot colormap ([0.5 0.7 0.9]) %Lighten default plot color hold off bar (O:n,normalizedcounts) hold on stem(O:n,pmfvalues, 'b', 'linewidth',2) xlabel('x') ylabel('Probability') legend ('Normalized Histogram' , 'PMF) (c) Recall that the mean of a Discrete Uniform(k, 2) random variable is E[X . However, if we did not know this, one way to estimate the mean would be to just average the trials Specifically, for realizations X, X2, . . . , Xm, the sample mean is -m 'ni Xi SMATLAB provides functions for histogram generation (histogram) and PMF calculation (pmf), but it is useful to build these up from scratch to understand how they work. The code framework below generates numtrials realizations of a Discrete Uniform(k, L) random variable, calculates the sample mean up to the mth realization for m from 1 to numtrials, and plots the resulting sequence of sample means. Your job is to fill in the code needed to calculate the sample mean. Parameters numtrials - 1000 IX = +5; kY = -50; LY = +50 %Generate Discrete Uniform random variables. %(MATLAB only generates Discrete Uniform random variables from 1:n for some %parameter n so we need to adjust it a bit.) X -random ('Discrete Uniform' ,1X - kX + 1,numtrials,1) + kX - 1; Y = random ('Discrete Uniform ,,LY -kY + 1,numtrials, 1) + kY- 1; %Calculate sample mean for an increasing number of trials. samplemeanX -zeros(1,numtrials); samplemeanY zeros (1,num trials); for m 1:numtrials for m samplemeanX (m) sampleme any(m) %%Your %%Your code code for for calculating calculating 1/m 1/m (X-1 (Y-1 X-m) Y-m) = * + + = * + + end %Plot plot(1:numtrials,samplemeanX) xlabel ('Number of Trials') ylabel('Sample Mean') Then, for numtrials- 1000, kx in plots of the sample mean. Comment on the role of the variance in determining the convergence of the sample mean to the true mean. (If you don't want to print out your entire code as part of your homework, you can just write the relevant lines of code that you wrote directly on the graph print out.) 5, 1x = 5, ky, 50, ly - 50 generate and turn (d) We can use the same approach to estimate probabilities, when calculating them analytically is either too tedious (or impossible). This approach is often used for plotting the performance of simulated systems. For instance, for realizations X1, X2,... , Xm, the probability estimate of P[X > b is simply the number of times Xi > b, divided by m The code framework below generates numtrials realizations of a Poisson(a) random vari able, estimates the probability PIX > using up to the mth realization for m from 1 to numtrials, and plots the resulting sequence of probability estimates as well as the exact probability. Your job is to fill in the code needed to generate the cstimate the probability as well as calculate the exact probability Parameters numtrials 1000 alpha = 4; %Generate Poisson (alpha) random variables. X = random (poisson ,,alpha , numtrials, 1); %Estimate P(X > b] probestimate-zeros(1,numtrials); for m - 1:numtrials probestimate (m) = %% Your code for calculating (1/m) * (number of times X-1 > b) %Calculate P(X > b] exactly exactprob-%% Your code for calculating P(X > b] exactly %Plot hold off, plot(1:numtrials,probestimate,) hold on, plot(1:numtrials,exactprob*ones (1,numtrials), 'r--') xlabel('Number of Trials') ylabel('Probability') legend('Probability Estimate', 'Exact Probability') Then, for numtrials 1000, a-4, and b- 3, generate and turn in plots of the probability estimate. (If you don't want to print out your entire code as part of your homework, you can just write the relevant lines of code that you wrote directly on the graph print out.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

Understanding Groups

Answered: 1 week ago