Exercise Set 1, Question 5

Matlab code:

g=0;
N=100000;
for i=1:N;
    x=-2*rand(1,10)-1;
    if (sum(x.^2)<1)
        g=g+1;
    end
end
 
volume = 2^10*g/N
error = 2^10*sqrt((g/N-(g/N)^2)/N)

You can also use the mean and std commands to get the volume and error - can you see how and explain?

Results of 4 runs

volume    error
2.4576    0.1584
2.6726    0.1652
2.6419    0.1643
2.5600    0.1617

Results of 4 further runs with N=1,000,000

volume    error
2.5334   0.0509
2.6532   0.0521
2.5149   0.0507
2.5221   0.0508

To reduce the error to 0.01 (3 s.f. accuracy) we are going to have to take N=25,000,000. I did just one run like this, it gave

volume    error
2.5550    0.0099
(Arguably for 3 s.f. accuracy here we should reduce the error to 0.005.)

The exact answer, according to Wikipedia, is (pi^5)/5!, which is 2.5502. All the above results are consistent with this, most being within one standard deviation from the exact result, with one that is close to 2 standard deviations away.


Back to course home page
Back to my main teaching page
Back to my home page