function normal03fig1 % Fig. B.2 Book Illustration for Normal RNG Simulation (3/2007): clc % clear variables, but must come before globals, % else clears globals too. clf % clear figures fprintf('\nfunction normal03fig1 OutPut:') kfig = 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=randn(N,1); xmean=mean(x); xstd=std(x); remean=xmean*100; restd=(xstd-1)*100; fprintf('\nNormal 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 = min(x); 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); % Need Center Oriented hist. bar(xbin,nx) axis tight title('Histogram for x = randn(N,1)'... ,'Fontsize',44,'FontWeight','Bold'); ks = [0.4,0.7]; nxmax = max(nx); xtext = xmax*(ks(1)-(kfig-1)*0.1); ytext=fix(ks(2)*nxmax); textn=['N = ' int2str(N)]; text(xtext,ytext,textn... ,'Fontsize',40,'FontWeight','Bold'); ylabel('Normal Bin Frequency'... ,'Fontsize',44,'FontWeight','Bold'); xlabel('x, Normal randn-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 normal03fig1