%
%  math495/stat490 -- 16 oct 03 -- djm
%
%  w07cdfA.m:  uniform rv eCDF

clear

%  initialize settings
rand('state',7654321)
Nrvs = 500;  Nex = 1;
ecdf = (1:Nrvs)/Nrvs;  sorted = zeros(Nrvs,Nex);

%  plot empirical cdf
figure(2);  clf

for j=1:Nex
    %  uniform random variables
    rvs = rand(Nrvs,1);
    sorted = sort(rvs);

    plot(sorted,ecdf,'r.');  hold on
end

title(['\bf empirical CDF for (N = ' num2str(Nrvs) ' rvs)'])
ylabel('\bf eCDF (F_k = k/N)')
xlabel(['\bf sorted x_k''s (' num2str(Nex) ' simulations)'])
axis([0 1 0 1])

ind   = (1:Nrvs);
tmean = ind/(Nrvs+1);
plot(tmean,ecdf,'b')

%tvar  = ind.*(Nrvs-ind+1)/(Nrvs+1)^2/(Nrvs+2);
%plot(tmean+2*sqrt(tvar),ecdf,'b--')
%plot(tmean-2*sqrt(tvar),ecdf,'b--')
