2. Take you to get started with the probability density function of the common distribution of matlab mathematical statistics (matlab program)

1. Brief description

      Calculation of probability distribution laws and density function values


Matlab directly provides a general function to calculate the value of the probability density function. They are pdf and namepdf functions, which are used as follows:
Y=pdf('name', K, A, B) or: namepdf (K, A, B)
above The function means to return the probability value or density value at X=K and the parameters are A, B, and C. For different distributions, the number of parameters is different; name is the name of the distribution function, which needs to be changed according to the corresponding distribution when used. The function names are summarized in the following table:

Value of name Function Description
'beta' or 'Beta' Beta distribution
'bino' or 'Binomial' Binomial distribution
'chi2' or 'Chisquare' Chi-square distribution
'exp' or 'Exponential' Exponential distribution
'f' or 'F ' F distribution
'gam' or 'Gamma' GAMMA distribution
'geo' or 'Geometric' geometric distribution
'hyge' or 'Hypergeometric' hypergeometric distribution
'logn' or 'Lognormal' lognormal distribution
'nbin' or 'Negative Binomial' ' Negative binomial distribution
'ncf' or 'Noncentral F' Noncentral F distribution
'nct' or 'Noncentral t' Noncentral t distribution
'ncx2' or 'Noncentral Chi-square' Noncentral chi-square distribution
'norm' or' Normal' Normal distribution
'poiss' or 'Poisson' Poisson distribution
'rayl' or 'Rayleigh' Rayleigh distribution
't' or 'T' T distribution
'unif' or 'Uniform' Continuous uniform distribution
'unid' or 'Discrete' Uniform' discrete uniform distribution
'weib' or 'Weibull' Weibull distribution
 

2. Code and running results

%% Density function of binomial distribution
clear all;
x=1:20;
y=binopdf(x,200,0.06); 
figure;
plot(x,y,'r*');
title('Binomial distribution (n =200, p=0.06)');


%% Poisson distribution density function
clear all;
x=1:20;
y=poisspdf(x,20); %Poisson distribution
figure;
plot(x,y,'r+');
title('Poisson distribution' );

 


%% geometric distribution
clear all;
x=1:10;
y=geopdf(x,0.4); % geometric distribution
figure;
plot(x,y,'rx');
title('geometric distribution');

 


%% Uniform distribution (discrete)
clear all;
n=10;
x=1:n;
y=unidpdf(x,n); % Uniform distribution (discrete)
figure;
plot(x,y,'ro');
title( 'Uniform distribution (discrete)');

 


%% Uniform distribution (continuous)
clear all;
x=-2:0.1:15;
y=unifpdf(x,0,6); % Uniform distribution (continuous) between 0 and 6
figure;
plot(x,y,' r:');
title('Uniform distribution (continuous)');

 


%% Exponential distribution
clear all;
x=0:0.1:10;
y=exppdf(x,2); % Exponential distribution
figure;
plot(x,y,'r:');
title('Exponential distribution');

 


%% normal distribution
clear all;
x=-5:0.1:5;
y1=normpdf(x,0,1); % standard normal distribution
y2=normpdf(x,3,3); % non-standard normal distribution
figure;
plot(x,y1,x,y2,':');
legend('standard normal distribution','non-standard normal distribution');
x1=-5:0.1:5;
y3=normpdf(x1, 3,1); %SIGMA=1
y4=normpdf(x1,3,2); %SIGMA=2
y5=normpdf(x1,3,3); %SIGMA=3

 


figure
plot(x1,y3,'r-',x1,y4,'b:',x1,y5,'k--');
legend('SIGMA=1','SIGMA=2','SIGMA=3');
y6=normpdf(x1,0,2); %MU=0
y7=normpdf(x1,2,2); %MU=2
y8=normpdf(x1,4,2); %MU=4

 

 


figure
plot(x1,y6,'r-',x1,y7,'b:',x1,y8,'k--');
legend('MU=0','MU=2','MU=4');

 

%% The probability density function of the three major sampling distributions
%% Chi-square distribution
clear all;
x=0:0.1:15;
y1=chi2pdf(x,2); %Chi-square distribution n=2
y2=chi2pdf(x,3) ; % chi-square distribution n=3
figure;
hold on;
plot(x,y1);
plot(x,y2,':');
legend('n=2','n=3');
title('card square distribution');


%% t distribution
clear all;
x=-5:0.1:5;
y1=tpdf(x,2); %t distribution (n=2)
y2=tpdf(x,10); %t distribution (n=10)  
figure;
plot(x,y1,'r:',x,y2,'b-');
legend('n=2','n=10');
title('t distribution');

 

 


%% F distribution
clear all;
x=0.1:0.1:5;
y=fpdf(x,2,5); %F distribution
figure;
plot(x,y,'r:');
title('F distribution (m =2,n=5)');

 

 

Guess you like

Origin blog.csdn.net/m0_57943157/article/details/131649445