% LMEx040304sol.m
% Larsen & Marx (3rd edition), p. 275.
% Effect of rounding on the expected value and variance of rounded 
% estimates
% Based on the central limit theorem, what is the probability that
% 100 transactions, rounded to the nearest dollar would exceed $5.00?

% What is the variance of a uniformly distributed random number
% over the interval -.125 to .125
% From definition of Variance, top p. 219:
% Var(Y)=E[(Y-mu)^2]= integral from -.5 to 0.5 (y-mu)^2 f_y(y) dy.
% mu=0,f_y(y)=1;
format rat
syms y mu
int('4*y^2',-.125,.125)  % Use the symbolic math toolbox to find the variance
                   % of a uniformly distributed variable on the interval
                   % -.5 to 0.5
VarY=eval(int('4*y^2',-.125,.125))
VarY
% Variance of a uniform randomly distributed number
% on the unit interval is 1/12
% Note how the variance remains 1/12 with a shift in mean:
% Var(Y)=E(Y^2)-mu^2;
mu=.125;
int('y^2*4',0,.25)
EYsq=eval(int('y^2*4',0,.25))
VARY=EYsq-mu^2
format
% using Theorem 3.13.12, in Larsen & Marx (2001, p. 223)
% Calculate the variance of all 100 transactions (multiply the variances)
Varall=100*VARY;
% calculate the standard deviation;
sigmaall=sqrt(Varall);
% Calculate the Z statistic
Z=zeros(2,1);
Z(1)=(-2-0)/sigmaall;
Z(2)=(2-0)/sigmaall
% Use the statbox normp.m, the cumulative normal probability function to
% find the probability of being more than $5 dollars off after $100 transactions:
P=1-(normp(Z(2))-normp(Z(1)))
% normp.m calls the Matlab erf.m function
