% LMFig060202_4th.m
% Larsen & Marx (2001, p. 367).
% Normal probability pdf:
% The normal probability equation is provided on p. 264.
% This is for mean 0, and unit standard
% deviation. The more general equation (Legendre & Legendre, 1998 p. 147) is:
% f(y_j)=1/(sqrt(2*pi)*sigma_j)*exp(-1/2*((y_j-mu_j)/sigma_j)^2)
y1=25.25;
p=1-normcdf((y1-25)/(2.4/sqrt(30)));
muj=25;
sigmaj=2.4/sqrt(30); % sigmaj is the standard error of the mean
maxy=26.6;
y=23.4:.01:maxy;
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.
plot(y,fyj,'linestyle','--','color','r','linewidth',3)
ylabel('Density','FontSize',20)
xlabel('Gas Mileage','FontSize',22)
axis([23.4 26.6 0 1.05])
set(gca,'Ytick',[0.5 1],'FontSize',18)
set(gca,'Xtick',[23.5:.5:24.5 25.25 26 26.5],'FontSize',18)
ax1=gca;% save the handle of the graph
title('Figure 6.2.2','FontSize',22)
hold on
fyj1=1/(sqrt(2*pi)*sigmaj)*exp(-1/2*((y1-muj)/sigmaj).^2);
plot([y1 y1]',[0 fyj1]','-k','linewidth',1) 
% Fill in the upper tail with fill
y2=y1:.1:maxy;
fyj2=1/(sqrt(2*pi)*sigmaj)*exp(-1/2*((y2-muj)/sigmaj).^2);
fyjmax=1/(sqrt(2*pi)*sigmaj)*exp(-1/2*((maxy-muj)/sigmaj).^2);
fill([y1 y2 maxy maxy],[0 fyj2 fyjmax 0],[.8 .8 1])
t=sprintf('Area=%6.4f\n',p);
text(y1+.25,fyj1,t,'Color','b','FontSize',20);
figure(gcf)
hold off