% this is a function to compute the harmonic measure of one side
% of a rectable from its center. We assume the box is of the 
% form [-a,a] times [-1,1] and the grid size in 1/m, where a and m
% are inputs.  A random walk is run N times and we count the number 
% of times it first hits the boundary on the right hand side.

function out=hm_box(a,m,N)
   tic;
   delta=1/m;
   ep=.000001;
   total=0;      
   for n=1:N
       flag=0;
       x=0;
       y=0;
       points=[x,y];
       while flag==0;
          step=randi(4);
          switch step
              case 1
                  x=x+delta;
              case 2
                  x=x-delta;
              case 3 
                 close all
                 y=y+delta;
              case 4
                  y=y-delta;
          end % switch
          points=[points;x,y];
          if  (abs(x)>a-ep)||(abs(y)>=1-ep)
              if x>a-ep
                  total=total+1;
              end 
              save(n,:)=[x,y];
              flag=1;
          end   
      end % while
   end % for n
   prob=total/N
   toc
   figure;
   axis equal;
   hold on
   x=[-a,a,a,-a,-a];
   y=[-1,-1,1,1,-1];
   plot(x,y,'LineWidth',2)
   plot(points(:,1),points(:,2),'b');
   scatter(save(:,1),save(:,2),'r','filled')
return

