-
Notifications
You must be signed in to change notification settings - Fork 0
/
Poisson_Distribution.m
52 lines (38 loc) · 951 Bytes
/
Poisson_Distribution.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
%Function for obtaining Poisson Distr from exponential
lambda=5; N=1000
for i=1:N
n=1;
P=1;
U=rand;
P=U*P;
while P>exp(-lambda)
n=n+1;
U=rand;
P=U*P;
end
x(i)=n-1;
end
hist(x)
xlabel('Value'); ylabel('Count');title('PMF for the number of packet arrivals to a buffer')
figure
bar(hist(x) ./ sum(hist(x)) ) %normalize the plot
xlabel('Value'); ylabel('Count');title('Normalized PMF for the number of packet arrivals to a buffer')
mean =0;
for i =1 : N
mean = x(i)+ mean;
end
meanvalue = mean/N
var = 0;
for i = 1: N
var = (x(i) - meanvalue)^2 + var;
end
varvalue = var/N
%To double check, use the poissrnd function
xmean = 5
x = poissrnd(xmean,N,1);
figure, clf, hold on
rvaxis = [0:30];
xf = hist(x,rvaxis) / N;
stem(rvaxis, xf,'b')
xlabel('Value'); ylabel('Count');
title('PMF for the number of packet arrivals to a buffer using poissrnd')