0% found this document useful (0 votes)
13 views9 pages

Probability Project 1 Final

This document contains code to generate and plot the probability mass function (PMF) and cumulative distribution function (CDF) of the binomial distribution for different parameter values. The code samples illustrate how changing the probability of success (p) or the number of samples (n) impacts the shape and spread of the binomial distribution. A third code sample defines and plots the uniform distribution, which has a constant PDF over its specified range.

Uploaded by

yousefhossamx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

Probability Project 1 Final

This document contains code to generate and plot the probability mass function (PMF) and cumulative distribution function (CDF) of the binomial distribution for different parameter values. The code samples illustrate how changing the probability of success (p) or the number of samples (n) impacts the shape and spread of the binomial distribution. A third code sample defines and plots the uniform distribution, which has a constant PDF over its specified range.

Uploaded by

yousefhossamx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MTH 1133

Probability
Project (1): Special Functions

Sec. B.N.

Youssef Khalid Saeed 8 9

Youssef Adel Abdel Moneim 8 13

Youssef Magdy Ebrahim 8 17


Solution:
Code in Matlab:

%Binomial distribution parameters


p = 0.1; % probability of success (i.e., containing the pollutant)
n = 18; % number of samples

% Range of X (the number of samples containing the pollutant)


X = 0:n;

% Calculate the PMF and CDF


pmf = binopdf(X, n, p);
cdf = binocdf(X, n, p);

% Plotting PMF and CDF


figure;
subplot(2,1,1);
bar(X, pmf, 1);
title('Binomial PMF');
xlabel('X');
ylabel('P(X)');
subplot(2,1,2);
stairs(X, cdf);
title('Binomial CDF');
xlabel('X');
ylabel('P(X <= x)');

Solution:
Code in Matlab:

%Binomial distribution parameters


p = 0.9; % probability of success
n = 18; % number of samples

% Range of X (the number of samples that contain the pollutant)


X = 0:n;

% Calculate the PMF and CDF


pmf = binopdf(X, n, p);
cdf = binocdf(X, n, p);

% Plotting PMF and CDF


figure;
subplot(2,1,1);
bar(X, pmf, 1);
title('Binomial PMF');
xlabel('X');
ylabel('P(X)');
subplot(2,1,2);
stairs(X, cdf);
title('Binomial CDF');
xlabel('X');
ylabel('P(X <= x)');
The main difference between this code and the previous code (which had a 10% chance
of containing the pollutant) is the value of `p`. With a 90% chance of containing the
pollutant in each sample, the probability of success is much higher, and as a result, the
PMF and CDF have shifted to the right. For example, with a 10% chance of containing
the pollutant, the most likely outcome is that 1 or 2 samples out of 18 will contain the
pollutant, with a very low probability of all 18 samples containing the pollutant. On the
other hand, with a 90% chance of containing the pollutant, the most likely outcome is
that 16-18 samples will contain the pollutant, with a very low probability of none of the
samples containing the pollutant.

Solution:
Code in Matlab:

%Binomial distribution parameters


p = 0.1; % probability of success (i.e., containing the pollutant)
n = 50; % number of samples

%Range of X (the number of samples that contain the pollutant)


X = 0:n;

% Calculate the PMF and CDF


pmf = binopdf(X, n, p);
cdf = binocdf(X, n, p);

% Plot the PMF and CDF


figure;
subplot(2,1,1);
bar(X, pmf, 1);
title('Binomial PMF');
xlabel('X');
ylabel('P(X)');
subplot(2,1,2);
stairs(X, cdf);
title('Binomial CDF');
xlabel('X');
ylabel('P(X <= x)');
The main difference between this code and the previous code (which had 18 samples) is
the value of `n`, which is now set to 50. This means that we're analyzing a larger number of
samples, which could have a significant impact on the distribution.

With a 10% chance of containing the pollutant in each sample, the most likely outcome is
that 4-6 samples out of 50 will contain the pollutant, with a very low probability of all 50
samples containing the pollutant. On the other hand, with a 90% chance of containing the
pollutant, the most likely outcome is that 45-50 samples will contain the pollutant, with a
very low probability of none of the samples containing the pollutant.

In general, as the number of samples increases, the distribution becomes more spread out
and symmetrical, with a higher likelihood of values closer to the mean. Therefore, it's
important to consider the sample size when analyzing the binomial distribution.

Solution:
Code in Matlab:

% Define the uniform distribution parameters


a = 4.9; % lower bound of the range
b = 5.1; % upper bound of the range
f = 5; % constant PDF value

% Define the range of values for X


X = linspace(a, b, 1000);

% Calculate the PDF (probability density function) and CDF (cumulative distribution
function)
PDF = f * ones(size(X));
CDF = (X - a) / (b - a);

% Plot the PDF and CDF


figure;
subplot(2,1,1); % PDF plot
plot(X, PDF);
xlabel('X');
ylabel('f(X)');
title('Uniform PDF');subplot(2,1,2); % CDF plot
plot(X, CDF);
xlabel('X');
ylabel('F(X)');
title('Uniform CDF');
The Uniform Distribution is a continuous probability distribution that has a constant
probability density function (PDF) over a specified range. The PDF for a uniform
distribution is a horizontal line over the range of values for which the distribution is
defined.

You might also like