function my_pi=HW1P2(N)
L=2; %length of a side on a cube centered at the origin
squarevolume=L^3;

%Monte-Carlo loop:
sum=0;
for ii=1:N
 r=L*(rand(3,1)-0.5); %pick a random point (x,y,z) inside the cube
 if norm(r)<L/2 %if it is inside a circumscribed sphere with radius L/2
  sum=sum+1; %then add it to the sum
 end
end
   

spherevolume=sum/N*squarevolume; %calculate ratio

my_pi=spherevolume*3/4*(2/L)^3; %solve V=4/3*pi*R^3 for pi! 