Assignment03Sol

# Assignment03Sol - Columbia University IEOR 4404 Simulation...

This preview shows pages 1–4. Sign up to view the full content.

Columbia University IEOR 4404: Simulation Spring 2009 Solution to Assignment 3 1. Exercise 3 Solution: function SimulateDiscrete(p) % SimulateDiscrete(p) generates a discrete random variable with % probability mass function given by the vector p p=[0.3,0.2,0.35,0.15]; U = rand(); i = 0; total = 0; while( U > total ) i = i + 1; total = total + p(i); end i 2. Exercise 4 Solution: The following MATLAB code prints 95% approximate conﬁdence intervals for the expectation and variance of the total number of hits:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
hits = []; for n=1:10000 list = 1:100; for k=100:-1:1 % generate a random integer between 1 and k i = floor(k*rand()) + 1; % swap values of list(i) and list(k) temp = list(i); list(i) = list(k); list(k) = temp; end % count number of hits hits = [ hits sum( list == 1:100 ) ]; end m = mean( hits ); v = mean( ( hits - mean( hits ) ).^2 ); sigmam = std( hits ); sigmav = std( ( hits - mean( hits ) ).^2 ); CIm = [ m - 1.96 * sigmam/n^.5, m + 1.96 * sigmam/n^.5 ] CIv = [ v - 1.96 * sigmav/n^.5, m + 1.96 * sigmav/n^.5 ] Running the code gives us the following output: CIm = 0.9898 1.0292 CIv = 0.9791 1.0436 We now compute the expectation and variance of the number of hits analytically. Let N denote the number of hits and let n = 100. Then N can be written as N = n X i =1 N i , where N i = ( 1 , card i is the i th card to be turned over 0 , otherwise . (1) Notice that for each i = 1 ,...,n we have P [ N i = 1] = 1 n . This is because the i th card to be turned
over is equally likely to be any of the cards 1 ,...,n . Therefore, for each i = 1 ,...n , E [ N i ] = 1 · 1 n + 0 · ± 1 - 1 n = 1 n , (2) E [ N 2 i ] = 1 2 · 1 n + 0 · ± 1 - 1 n = 1 n . (3) Combining (2) and (3) gives us for each

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.
• Spring '10
• C
• Probability theory, Discrete probability distribution, pj, Probability mass function, approximate confidence intervals

{[ snackBarMessage ]}

### Page1 / 7

Assignment03Sol - Columbia University IEOR 4404 Simulation...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online