Task#1: Generate The Binomial Distribution With Following
Task#1: Generate The Binomial Distribution With Following
clear all;clc;
% Get the values for the domain, x.
x = 0:12;
% Get the values of the probability mass function
n1=12;
p1=0.3;
pdf1 = binopdf(x,n1,p1);
n2=12;
p2=0.7;
pdf2 = binopdf(x,n2,p2);
%calculate mean and variance
mean1=p1*n1
variance1=n1*p1*(1-p1)
mean2=p2*n2
variance2=n1*p2*(1-p2)
% Do the plots.
subplot(1,2,1),bar(x,pdf1,1,'w')
title(' n = 12, p = 0.3')
xlabel('X'),ylabel('f(X)')
axis square
subplot(1,2,2),bar(x,pdf2,1,'w')
title(' n = 12, p = 0.7')
xlabel('X'),ylabel('f(X)')
axis square
0.2 0.2
0.15 0.15
f(X )
f(X )
0.1 0.1
0.05 0.05
0 0
0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12
X X
n = 6, p = 0.3 n = 6, p = 0.7
0.35 0.35
0.3 0.3
0.25 0.25
0.2 0.2
f(X)
f(X)
0.15 0.15
0.1 0.1
0.05 0.05
0 0
0 1 2 3 4 5 6 0 1 2 3 4 5 6
X X
Comments:
We have compared the same these earlier graph with the current graphs what we have in 1 st task.
Difference is just in number of trials while same thing we can observe that same variance were
calculated for earlier graph reason for what I have already explained.
Code:
x = 0:18;
pdf1= poisspdf(x,7);
pdf2 = poisspdf(x,10);
subplot(121),plot(x,pdf1,'+')
xlabel('X');ylabel('f(X)');
title('lamda=7');
subplot(122),plot(x,pdf2,'*')
xlabel('X');ylabel('f(X)');
title('lamda=10');
Graph:
lamda=7 lamda=10
0.16 0.14
0.14
0.12
0.12
0.1
0.1
0.08
f(X)
0.08
f(X)
0.06
0.06
0.04
0.04
0.02
0.02
0 0
0 5 10 15 20 0 5 10 15 20
X X
Comments:
In the above graph, the two different Poisson distribution with mean 7 and 10 are drawn and we can
see clear that both have highest value at their corresponding means. Since we know that Poisson
distribution is often used to model the inter arrival time between packets so if above graph are also
TASK#4:
Codes:
x = 0:18;
cdf1= poisscdf(x,7);
cdf2 = poisscdf(x,10);
subplot(121),plot(x,cdf1,'k+')
xlabel('X');ylabel('F(X)');
title('lamda=7');
subplot(122),plot(x,cdf2,'k*')
xlabel('X');ylabel('F(X)');
title('lamda=10');
GRAPH:
lamda=7 lamda=10
1 1
0.9 0.9
0.8 0.8
0.7 0.7
0.6 0.6
F(X)
F(X)
0.5 0.5
0.4 0.4
0.3 0.3
0.2 0.2
0.1 0.1
0 0
0 5 10 15 20 0 5 10 15 20
X
X
Comments:
These are cumulative distributions of above Poisson distributions , we can see that its maximum value is
1.
Graph:
n=18,p=0.3 lamda=5.4
0.25 0.18
X: 5
Y: 0.1728
0.16
X: 5
Y: 0.2017
0.2
0.14
0.12
0.15
0.1
f(X)
f(X)
0.08
0.1
0.06
0.04
0.05
0.02
0 0
0 5 10 15 20 0 5 10 15 20
X
X
Comments:
In above graphs,left one is binomial graph with value of n= 18 and n=0.3 and distribution
which is shown on right hand side is poisson distribution lamda=18*0.3=5.4
We can see that both have maximum value at same value of n but still there is a difference
between them .Since we know that when n tends to infinity and p tends to zero then binomial