hw6sol - IEOR 4404 Simulation Prof. Mariana Olvera-Cravioto...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
IEOR 4404 Assignment #6 Solutions Simulation 24th October 2006 Prof. Mariana Olvera-Cravioto Page 1 of ?? Assignment #6 Solutions 1. The following code asks the user to input the probability mass vector and then generates a value of a random variable having this mass function. prob = input(’\n Enter the respective probabilities: ’) n=length(prob); i=1; u = rand; sumProb = prob(1); while (i < n)&&(u>= sumProb) i = i+1; sumProb = sumProb + prob(i); end i 2. The following code simulates the action of drawing a card from the shuffled deck of cards and not replacing it into the deck. Indeed, this is equivalent to drawing a card at random from the ordered deck of cards. The key is to make sure that you don’t pick the same card twice which is guaranteed by rearranging the elements in the C vector each time a card is withdrawn. S=10000; % Sample size X=zeros(1,S); % Sample vector e=ones(1,S); % Unit vector C=zeros(1,100); % 100 cards with number 1,2,. ..,100 for s=1:S for i=1:100 C(i)=i; end n=100; Y=0; for j=1:100
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 IEOR 4404, Assignment #6 Solutions U=rand; N=floor(n*U)+1; if j==N Y=Y+1;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/17/2010 for the course IEOR 4404 taught by Professor C during the Spring '10 term at Columbia.

Page1 / 5

hw6sol - IEOR 4404 Simulation Prof. Mariana Olvera-Cravioto...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online