% LMFig070201_3rd.m
% Similar to LMFig040301.m
% Page 405 in Larsen & Marx.
% Galton's Height data
% E. Gallagher, Eugene.Gallagher@umb.edu
% Revised: 2/5/04
Midpoints=[54.5:77.5]';
Frequency=[5 3 7 6 10 15 50 526 1237 1947 3019 ...
        3475 4054 3631 3133 2075 1485 680 343 118 42 9 6 2]';
SF=sum(Frequency)
Density=Frequency/SF;
AvgHt=1/SF*sum(Midpoints.*Frequency)
VarHt=1/SF^2 * ((SF*sum(Frequency.*Midpoints.^2)) - (sum(Midpoints.*Frequency))^2)
VH=var(Frequency.*Midpoints)
bar(Midpoints,Density);
axis([54 77 0 .165]);
xlabel('Height in inches')
ylabel('Probability density')
title('Figure 7.2.1')
figure(gcf)
ax1=gca;% save the handle of the first graph
% Superimpose the normal probability pdf:
% The normal probability equation is provided on p. 264 & 402 in L&M
muj=AvgHt;
sigmaj=sqrt(VarHt); % sigmaj is the standard deviation
y=54:.2:77;
fyj=1/(sqrt(2*pi)*sigmaj)*exp(-1/2*((y-muj)/sigmaj).^2); 
% Plot using ax1 handle, saved above,to save this graph
% on top of the previous graph.
h1=line(y,fyj,'Color','r','Parent',ax1,'Linewidth',3);
set(h1,'linestyle','--','color','r','linewidth',3)
xlabel('Height (in inches)'),ylabel('Probability Density')
title('Figure 7.2.1')
figure(gcf);pause