function IEOR161HW8

# function IEOR161HW8 - function IEOR161HW8 clear all close...

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

function IEOR161HW8() clear all close all clc %% Simulation part (C) %initialize for the Markov Chain n1=0; n2=0; l=1; m1=2; m2=3; N=20000; %initialize for the geometric limitiing distribution p1=1-l/m1; p2=1-l/m2; %form tracking vars t=[5,10,50,100,200]; x1 = zeros(length(t),N); x2 = zeros(length(t),N); geo1 = zeros(1,N); geo2 =zeros(1,N); for i = 1:length(t); for j = 1:N; n1=0; n2=0; wait1=0; wait2=0; r1 = rand; while r1>p1; wait1=wait1+1; r1=rand; end r2 = rand; while r2>p2; wait2=wait2+1; r2=rand; end for k = 1:t(i); if n1==0 && n2==0; n1=n1+1; elseif n1>=1 && n2==0; p=rand; n1=n1+(p<(l/(l+m1)))-(p>(l/(l+m1))); n2=n2+(p>(l/(l+m1))); elseif n1==0 && n2>=1; p=rand; n1=n1+(p<(l/(l+m2))); n2=n2-(p>(l/(l+m2))); elseif n1>=1 && n2>=1; p=rand; n1=n1+(p<(l/(l+m1+m2)))-(p<(1-m2/(l+m1+m2))&& p>(l/(l+m1+m2))); n2=n2 - (p>(1-m2/(l+m1+m2))) + (p<(1-m2/(l+m1+m2))&& p>(l/(l+m1+m2))); end end geo1(j)=wait1; geo2(j)=wait2; x1(i,j)= n1;

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

View Full Document
x2(i,j)= n2; end figure(t(i)); hist(x1(i,:),40); figure(t(i)+1); hist(x2(i,:),40); end figure(501); hist(geo1,40); figure(502); hist(geo2,40); %% Part (d) Plot X1 and X2 for a single sample path of length 200 (l=1,l=2) t= 1:200; x1 = zeros(1,length(t)); x2 = zeros(1,length(t)); for l = 1:2; n1=0; n2=0; for i = 1:length(t); if
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern