function [v,sd] = ball(n,N) M=20; a=[]; for k=1:M % M independent runs x=2*rand(n,N)-1; % random vectors in W_n nq = sum(x.^2 , 1); % list of the 2-norms (squared) of the vectors K = sum(nq<1); % number of vectors with norm <=1 a = [a,K/N]; % percentage of points in B_n end a_m = mean(a); % mean value of a a_sd = std(a); % standard deviation of a v = a_m * 2^n; % mean value of v sd = a_sd * 2^n; % standard deviation of a