%help stats %random number generator seed=931316785; rand('seed',seed); randn('seed', seed); % normal probability density function % mean=0, standard deviation=1 x = [-3:0.1:3]; f = normpdf(x,0,1); plot(x,f) title('normal pdf') pause; %cumulative probability density function % for normal pdf with mean=0, standard deviation=1 x = [-3:0.1:3]; p = normcdf(x,0,1); plot(x,p) title('normal cumulative df') pause; %inverse cumulative distribution function x = [-3:0.1:3]; xnew = norminv(normcdf(x,0,1),0,1); %how does xnew compare with x? p = [0.1:0.1:0.9]; pnew = normcdf(norminv(p,0,1),0,1); %how does pnew compare with p? %note that the relationship between a cdf and %its inverse function is more complicated for % discrete distributions %binomial pdf for n=10 and p=1/2 (e.g., how many heads % for flipping 10 a coin ten times) x = 0:10; y = binopdf(x,10,0.5); plot(x,y,'+') title('binomial distribution') pause; %chi-square distribution %4 degrees of freedom x = 0:0.2:70; y = chi2pdf(x,4); plot(x,y) hold on; %chi-square distribution %20 degrees of freedom x = 0:0.2:70; y = chi2pdf(x,20); plot(x,y) title('two chi-2 distributions') pause; hold off %discrete uniform distribution x = 0:10; y = unidcdf(x,10); stairs(x,y) set(gca,'Xlim',[0 11]) pause; set(gca,'Xlim','default') title('discrete uniform distribution') %exponential pdf x = 0:0.1:10; y = exppdf(x,2); plot(x,y) title('exponential pdf') pause; %F distribution x = 0:0.01:10; y = fpdf(x,5,3); plot(x,y) title('F distribution') pause; %Poisson distribution x = 0:15; y = poisspdf(x,5); plot(x,y,'+') title('Poisson pdf') pause; %student's t-distribution %versus normal distribution x = -5:0.1:5; y = tpdf(x,5); z = normpdf(x,0,1); plot(x,y,'-',x,z,'-.') title('Students t- and normal distributions')