This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/code/tdistribution.m

33 lines
601 B
Matlab

n = 100000
x=randn(n, 1);
nsamples = 3;
nmeans = 10000;
means = zeros( nmeans, 1 );
sdevs = zeros( nmeans, 1 );
students = zeros( nmeans, 1 );
for i=1:nmeans
sample = x(randi(n, nsamples, 1));
means(i) = mean(sample);
sdevs(i) = std(sample);
students(i) = mean(sample)/std(sample)*sqrt(nsamples);
end
sdev = 1.0
msdev = std(means)
% scatter( means, sdevs )
hold on;
dxg=0.01;
xmax = 10.0
xmin = -xmax
xg = [xmin:dxg:xmax];
pg = exp(-0.5*(xg/sdev).^2)/sqrt(2.0*pi)/sdev;
hold on
plot(xg, pg, 'r', 'linewidth', 4)
bins = xmin:0.1:xmax;
hist(means, bins, 1.0/(bins(2)-bins(1)) );
hold off;