2301520 Fundamental of AMCS
Simulation

Simulation

pdist= PoissonDistribution[20];

plot1=ListPlot[Table[PDF[pdist,x], {x,0,50}], Joined-> True]

data1=RandomInteger[pdist,1000]

(*<<"Histograms`"; *)

plot2 = Histogram[data1, HistogramScale -> 1] (* Pre-Version 8*)

plot2 = Histogram[data1, {1}, "PDF"] (* Version 8 *)

Show[plot2, plot1]

pdist2= PoissonDistribution[15];

simdat2=RandomInteger[pdist2,30]

edist2= ExponentialDistribution[1/3];

interarrivaltimes=RandomReal[edist2,30]

edist3= ExponentialDistribution[1/2];

servicetimes=RandomReal[edist3,30]

ArrivalTime[1]=0;WaitingTime[1]=0;

DepartureTime[i_]:=ArrivalTime[i]+WaitingTime[i]+servicetimes[[i]];

ArrivalTime[i_]:=ArrivalTime[i-1]+interarrivaltimes[[i-1]];

WaitingTime[i_]:= If[DepartureTime[i-1]<ArrivalTime[i],0, DepartureTime[i-1]-ArrivalTime[i]];

DepartureTime[2]

departuretimes=Table[DepartureTime[i],{i,30}]

WaitingTime[2]

waitingtimes=Table[WaitingTime[i],{i,30}]

Mean[%]

arrivaltimes=Table[0,{i,30}];

For[i=2,i≤ 30,i++,arrivaltimes[[i]]=arrivaltimes[[i-1]]+interarrivaltimes[[i-1]]];

arrivaltimes

departuretimes=Table[0,{i,30}]; waitingtimes=Table[0,{i,30}];

For[i=2,i≤ 30,i++,(
departuretimes[[i-1]]=arrivaltimes[[i-1]]+waitingtimes[[i-1]]+servicetimes[[i-1]];
waitingtimes[[i]]=If[departuretimes[[i-1]]<arrivaltimes[[i]], 0, departuretimes[[i-1]]- arrivaltimes[[i]]];
)];

waitingtimes

Mean[%]

departuretimes

colors={"Blue", "White"}

labels=Characters["ABCDE"]

simdat=Table[{colors[[RandomInteger[{1,2}]]],labels[[RandomInteger[{1,5}]]]},{100}]

Count[simdat,{_,"B"}]

Count[simdat, {"White","A"}]

Select[simdat,MatchQ[#,{"Blue",_}]&]

If[MatchQ[#,{"White","A"}],1,0]&/@simdat