% spherical_cap_col.m
% estimate volume of  spherical cap on unit
% sphere in n-space using random points
   tic 
   % set number of random trials to do
   trials=1000000;
   % choose size of caps
   r=.5;
   % chose what dimensions to test
   dimen=10:10:100;
   for j=dimen
      count =0;
      for k=1:trials
	  % choose random normal vector in n-space
	  x=randn(dimen,1);
	  % normalize so it has length one (lies on unit sphere)
	  x=x/norm(x);
	  % increase count if x lies in a cap
          if abs(x(1))>r
              count = count+1;
	  end % if 
      end % for k
      % save fraction of sphere that lies in caps
      vol(dimen)=count/trials;
   end % for dimen
   toc 

   % plot the estimated fraction against dimension
   figure; grid on; hold on;
   title('Plot of volume of spherical caps');
   plot([10:10:100],vol([10:10:100]));
   xlabel('dimension');
   ylabel('volume');

   return

   % plot log of estimated fraction against dimension
   figure; grid on; hold on;
   title('Log-Plot of volume of spherical caps');
   plot([10:10:100],log(vol([10:10:100])));
   xlabel('dimension');
   ylabel('volume');
   toc

