clear all
close all


disp('Demonstrating that (n-1)s^2/sigma^2 has chi^2 distribution')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
% end of preabmle--------------------------------------
n = 8;
M=100000;
    x = 5 * randn([n, M]);
    ch2 = (n-1) * var(x)/25;
%histn(ch2,0,0.4,30);
histo(ch2, 40,1, 1)
hold on
plot( (0:0.1:30), chi2pdf((0:0.1:30), n-1),'r-','linewidth',lw)
%print -depsc 'C:\Brani\Courses\bmestatu\BMESBOOK\Estimation\dists2.eps'