# Find and plot the cumulative distribution and probability density functions of a random variable

AIM: To find and plot the cumulative distribution and probability density functions of a given  random variable.

OBJECTIVE: To find the cumulative distribution and probability density functions of a given random variable.

EQUIPMENT:

PC with windows (95/98/XP/NT/2007).

MATLAB Software

Plot the CDF of discrete  random variable:

PROGRAM:

``````px1=[0.1 0.2 0.1 0.5 0.1]
x1=[3 5 6 8 9]
x=1:max(x1)
P1=zeros(1,length(x))
for j=1:length(x)
for k=1:length(x1)
if x(j)==x1(k)
P1(j)=px1(k)
end
end
end
k=0
for i=1:length(x)
Fx(i)=k+P1(i)
k=Fx(i)
end
disp(Fx)
subplot(2,1,1)
stem(x,P1)
axis([0 10 0 1])
subplot(2,1,2)
stairs(x,Fx)
axis([0 10 0 1.5])``````

OUTPUT:

px1 =

0.1000    0.2000    0.1000    0.5000    0.1000         0

x1 =

3     5     6     8     9    12

Fx

Columns 1 through 12

0         0         0    0.1000    0.1000    0.3000    0.4000    0.4000    0.9000    1.0000    1.0000    1.0000

Column 13

1.0000

Plot the PDF of discrete random variable:

PROGRAM:

``````x=[3 5 6 8 10]
Fx=[0.3 0.4 0.9 1 1]
f1=zeros(1,min(x));
x1=[0:min(x)-1 x]
Fx1=[f1 Fx]
for i=2:length(x1);
Px(1)=Fx1(1);
Px(i)=Fx1(i)-Fx1(i-1);
end
disp('px')
disp(Px)
subplot(2,1,1)
stairs(x1,Fx1)
xlabel('x1')
ylabel('Fx1')
title('CDF of x')
axis([0 10 0 1.1])
subplot(2,1,2)
stem(x1,Px)
xlabel('x1')
ylabel('Px')
title('pdf of x')
axis([0 10 0 1])``````

OUTPUT:

x =

3     5     6     8    10

Fx =

0.3000    0.4000    0.9000    1.0000    1.0000

x1 =

0     1     2     3     5     6     8    10

Fx1 =

0         0         0    0.3000    0.4000    0.9000    1.0000    1.0000

px

0         0         0    0.3000    0.1000    0.5000    0.1000         0

RESULT: Thus cumulative distribution and probability density functions of a given  random variable are plotted

OUTCOME: The Student must be able to understand how to find the cumulative distribution to  probability density functions of a given random variable using MATLAB

• Updated
Mar 03, 2020
• Views
534
You May Like