www.gusucode.com > stats 源码程序 matlab案例代码 > stats/PDFAndCDFForStudentstDistributionExample.m

    %% PDF and CDF for Student's-t Distribution
%

% Copyright 2015 The MathWorks, Inc.


%% Compute and plot pdf
x = [0:.1:10];
y1 = tpdf(x,5);   % For nu = 5
y2 = tpdf(x,25);  % For nu = 25
y3 = tpdf(x,50);  % For nu = 50

figure;
plot(x,y1,'Color','black','LineStyle','-')
hold on
plot(x,y2,'Color','red','LineStyle','-.')
plot(x,y3,'Color','blue','LineStyle','--')
legend({'nu = 5','nu = 25','nu = 50'})
hold off

%% Compute and plot cdf
x = [0:.1:10];
y1 = tcdf(x,5);   % For nu = 5
y2 = tcdf(x,25);  % For nu = 25
y3 = tcdf(x,50);  % For nu = 50

figure;
plot(x,y1,'Color','black','LineStyle','-')
hold on
plot(x,y2,'Color','red','LineStyle','-.')
plot(x,y3,'Color','blue','LineStyle','--')
legend({'nu = 5','nu = 25','nu = 50'})
hold off

%% Compute icdf
p = .95;
nu = 50;
x = tinv(p,nu)

%% Generate random number
nu = 10;
r = trnd(nu)

%% Compute mean and variance
nu = 10;
[m,v] = tstat(nu)