0% found this document useful (0 votes)
54 views6 pages

Task#1: Generate The Binomial Distribution With Following

The document contains code to generate and plot binomial and Poisson distributions with different parameters. For the binomial distribution, it generates two distributions with n=12, p=0.3 and n=12, p=0.7, and finds they have the same variance. For the Poisson, it generates distributions with λ=7 and λ=10 and calculates the CDF for both. It then compares a binomial and Poisson distribution with similar parameters and notes the binomial does not perfectly match the Poisson.

Uploaded by

Muhammad Naveed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views6 pages

Task#1: Generate The Binomial Distribution With Following

The document contains code to generate and plot binomial and Poisson distributions with different parameters. For the binomial distribution, it generates two distributions with n=12, p=0.3 and n=12, p=0.7, and finds they have the same variance. For the Poisson, it generates distributions with λ=7 and λ=10 and calculates the CDF for both. It then compares a binomial and Poisson distribution with similar parameters and notes the binomial does not perfectly match the Poisson.

Uploaded by

Muhammad Naveed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Task#1:

Generate the binomial distribution with following :


 n=2,p=0.3
 n=12,p=0.7

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

n = 12, p = 0.3 n = 12, p = 0.7


0.25 0.25

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

mean1 =3.6000,variance1=2.5200,mean2 =8.4000,variance2 =2.520

MUHAMMAD NAVEED SHAIKH (08TL19) Page 1


comments:
in this graph we have number of trials is equal to 12 and first one it
probability of success is 0.3 while in second one probability of success is
0.7.
we can see that mean of both distribution is different and but variance is
same because since probability of success of both binomial probabilities are
related to each other if we observe that in what is the probability of
failure for 1st distribution ,is probability of success of for second one
thus one represents success probability and other represents probability of
failure so both have same variance.
Task#2:Earlier graph to compare:

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

mean1 = 1.8000, variance1 = 1.2600, mean2 = 4.2000, variance2 =1.2600

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.

MUHAMMAD NAVEED SHAIKH (08TL19) Page 2


Task 3:
Generate poission distribution with the following parameter:Lamda=7, lamda=10;

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

MUHAMMAD NAVEED SHAIKH (08TL19) Page 3


showing same inter arrival time then we can see that time between two packets is mostly 7 and 10
seconds respectively.

TASK#4:

Also calculate cdf for above Poisson Distribution.

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.

MUHAMMAD NAVEED SHAIKH (08TL19) Page 4


Task#5:
Comparision between binomial and poisson distribution using plot command;
x = 0:18;
n=18;p=0.3;
lamda=n*p
pdf1= binopdf(x,n,p);
pdf2 = poisspdf(x,lamda);
subplot(121),plot(x,pdf1,'k+')
xlabel('X');ylabel('f(X)');
title('n=18,p=0.3');
subplot(122),plot(x,pdf2,'k*')
xlabel('X');ylabel('f(X)');
title('lamda=5.4');

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

MUHAMMAD NAVEED SHAIKH (08TL19) Page 5


becomes poisson distribution if we further increase the value of n and decrease the value of p
then we can have better approximations.

MUHAMMAD NAVEED SHAIKH (08TL19) Page 6

You might also like