% LMTable060201_4th.m
% from the normal pdf
% From Larsen & Marx  (2006) Introduction to Mathematical Statistics,
% Fourth Edition. page 432
% Dept. Environmental, Earth & Ocean Sciences
% Written by Eugene.Gallagher@umb.edu written & revised 3/4/11
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% Use Matlab to find the 95% critical value (1-tailed)? it is about 25.178
y1 = fsolve(@(x) 0.95-normcdf((x-25)./(2.4./sqrt(30))),25,optimset('Display','off'))
% Generate n random samples of size 30 with mean 25 and sigma=2.4
MU=25;SIGMA=2.4;
fprintf('mu =%5.3f and sigma = %5.3f\n',MU,SIGMA);
n=75;                    % Larsen & Marx used 75
samsize=30;              % Larsen & Marx used 30
Ybar = mean(normrnd(MU,SIGMA,samsize,n));
fprintf('\nTable 6.2.1\n\n')
for i=1:n
    if Ybar(i)>=y1
        fprintf('%6.3f \tyes\n',Ybar(i))
    else
        fprintf('%6.3f \tno\n',Ybar(i))
    end
end
fprintf('There were %1.0f of %2.0f samples that exceeded %6.3f.\n',sum(Ybar>=y1),n,y1)