I used the following code to find the volume of the sphere $x^2+y^2+z^2 \leq 1$ in the first octant:
McVolume[Num_] :=
Module[{hit, miss, index, x, y, z}, hit = 0; miss = 0;
For[index = 1, index <= Num, index = index + 1,
x = Random[Real, {0, 1}];
y = Random[Real, {0, 1}];
z = Random[Real, {0, 1}];
If[z <= Sqrt[1 - x^2 - y^2], hit = hit + 1, miss = miss + 1];];
Return[(hit/Num) 1];]
McVolume[100]
It turns out to be 11/25
. Even thought the answer is correct but using this code i am getting an error:
LessEqual::nord: Invalid comparison with 0. +0.48202 I attempted. >>
I don't understand, why is this error popping up?
Any help would be appreciated.