clc seed = 7; disp(['setting seed ',num2str(seed)]) rng(seed) nn=1000 dim=2 lambda=2.5 points = zeros(nn,dim); tic for i=1:nn % random column vector p = ranExp(dim,lambda); % transpose to get a row vector p = p'; % set the ith row of "points" to be equal to p points(i,:) = p; end toc points(1:5,:) hold off % this is how to plot points whose x and y components are the % first two columns of a matrix plot( points(:,1),points(:,2), 'ko' ) print -dpdf 'points.pdf' -bestfit % uncommment the rest to test the importance sampling % how many points to use ? n=100000; % what dimension ? (eg try 20 or 30) dim = 20; % how many repeats for each value of lambda ? mm=20; % values of lambda to try, for importance sampling lambdaVals = [ 0,1,3,5,8 ] disp(['dimension ',num2str(dim),', n is ',num2str(n)]) exV = exactVol(dim); disp(['exact is ',num2str( exV ), ... ' fraction of cube ',num2str(exV/2^dim)]) tic % this is how we loop over list elements in matlab for lambda = lambdaVals % do the calculation m times and check mean/variance estMean = 0; estMean2 = 0; for i=1:mm [estV,estScaled] = sphereVolMCImpExp(dim,n,lambda); estV; estMean = estMean + estV; estMean2 = estMean2 + estV*estV; end estMean = estMean / mm; estMean2 = estMean2 / mm; stdDev = sqrt( estMean2 - estMean*estMean ); disp(['lambda is ',num2str(lambda),' mean ',num2str(estMean), ... ' std dev ',num2str(stdDev)]) end toc