MAT LAB program to find & plot pdf and cdf for the case of 3 dice roll and compare it with gaussian curve

%MAT LAB program to find & plot pdf and cdf for the case of 3 dice roll and compare it with Gaussian curve
clc;
clear all();
n=10000;
s1= ceil(6*rand(1,n));
s2= ceil(6*rand(1,n));
s3= ceil(6*rand(1,n));
%find pdf 
s=s1+s2+s3;    % s=sum of every possibility
z=3:1:18;          % z=total possible possibility
subplot(2,2,1);
hist(s,z);
[x y]=hist(s,z);
y1=x/n;
subplot(2,2,2);
bar(z,y1);
hold on;
%find cdf 
y2=cumsum(y1);
subplot(2,2,3);
bar(z,y2)
%find Gaussian curve for same 



m=mean(s);
d=var(s);
a=1/((sqrt(2*3.14*d)));
g=a*exp(-((z-m).*(z-m))/(2*d))
subplot(2,2,2);
plot(z,g,'r')
------------------------------------------------------------------------------------------------------------
after writing this code save it and press the run button you will see the 3 graphs  in 1 figure as shown below :


Comments

Popular posts from this blog

MATLAB program to find Frequency Modulation