function exponential03fig1
% Fig. B. 4 Book Illustration for Exponential RNG Simulation 
% with mean one (3/2007):
clc % clear variables, but must come before globals, 
%     else clears globals too.
clf % clear figures
fprintf('\nfunction exponential03fig1 OutPut:')
kfig = 0; mu = 1.0;
scrsize = get(0,'ScreenSize');
ss = [3.0,2.8,2.6,2.4,2.2,2.0];
for m = 3:2:5
    kfig = kfig+1; figure(kfig);
    N=10^m;
    x=-mu*log(rand(N,1));
    xmean=mean(x);
    xstd=std(x);
    remean=(xmean/mu-1)*100;
    restd=(xstd/mu-1)*100;
    fprintf('\nExponential Random Deviate (MATLAB randn) Test:');
    fprintf('\n fig=%i; m=%2i; N=%i; xmean=%f; xstd=%f;'...
        ,kfig,m,N,xmean,xstd);
    fprintf('\n fig=%i; relerrmean=%f; relerrstd=%f;'...
        ,kfig,remean,restd);
    nbins = 50; % min(fix(sqrt(10^m)),101); 
    xmin = 0; xmax = max(x);
    xbin1 = xmin; xbin2 = xmax; dxbin = (xbin2-xbin1)/nbins;%
    fprintf('\n#bins(x)=%4i; xbin in [%6f,%6f]; dxbin=%10f;'...
        ,nbins,xbin1,xbin2,dxbin)
    xbin = xbin1+dxbin/2:dxbin:xbin2-dxbin/2;
    nx = hist(x,xbin); % using centered defined bins, 
    %                    rather than edge bins
    bar(xbin,nx)
    axis tight
    title('Histogram for x = -ln(rand(N,1))'...
        ,'Fontsize',44,'FontWeight','Bold');
    ks = [0.6,0.6];  nxmax = max(nx);
    xtext = xmax*ks(1); ytext=fix(ks(2)*nxmax); 
    textn=['N = ' int2str(N)];
    text(xtext,ytext,textn...
        ,'Fontsize',40,'FontWeight','Bold');
    ylabel('Exponential Bin Frequency'...
        ,'Fontsize',44,'FontWeight','Bold');
    xlabel('x, Exponential random-Deviate'...
        ,'Fontsize',44,'FontWeight','Bold');
    patchobj = findobj(gca,'Type','patch');
    set(patchobj,'FaceColor','w','EdgeColor','k','linewidth',2);
    set(gca,'Fontsize',36,'FontWeight','Bold','linewidth',3);
    set(gcf,'Color','White','Position'...
        ,[scrsize(3)/ss(kfig) 70 scrsize(3)*0.60 scrsize(4)*0.80]);
end
% End exponential03fig1