# Solid volume calculation

In order to calculate the volume of the solid defined by

$$\frac{51}{100} (\cos x \cos y+\cos x \cos z+\cos y \cos z)+\cos x+\cos y+\cos z+1\le0$$

where $x,y,z\in[0,2\pi]$

I used the following code (in MATLAB)

f = @(x, y, z) double(1 + cos(x) + cos(y) + cos(z) + 0.51*(cos(x).*cos(y)  + cos(x).*cos(z) + cos(y).*cos(z))<=0)
q = 8*integral3(f, 0, pi, 0, pi, 0, pi)


but gives warning message and NaN

Warning: Reached the maximum number of function evaluations (10000). The result fails the global error test.

How to obtain the desired result in as high as possible precision?

Update:

It seems Gauss-Kronrod Rule solves this problem correctly; a further variable substitution, $u_i=\cos x_i$ with Jacobian determinant involved may cause computation efficiency.

• While I don't know any clever quadrature methods for your type of problem, you could always stick this into a routine using Monte Carlo integration to compute the volume fairly trivially. – spektr May 24 '17 at 23:28
• thank you. The only concern is Monte carlo method has poor accuracy. – LCFactorization May 25 '17 at 0:16
• Finding the volume of a semi-algebraic set (which is very similar to what you have, except with polynomial inequalities) is known to be a hard problem in general, so yours is harder. It's possible that there wouldn't be anything much better than MC. Also, could you please include the full output, not just "gives error message". In particular, what is the exact error message? – Kirill May 25 '17 at 0:27
• @LCFactorization Naïve MC might have a slow convergence of $O(n^{-1/2})$, where $n$ is the nunmber of samples, but you might be able to find some more adaptive MC approaches that could make your computation more accurate in a feasible time. The Wikipedia page mentions a few: en.wikipedia.org/wiki/Monte_Carlo_integration – spektr May 25 '17 at 0:49
• Could you triangulate (tetrahedralize?) your domain? Using high-order elements to follow the curved boundary would the use of a great number of quadrature tools commonly used in finite element methods. They also have the nice property that the result will converge to the correct result as you refine the mesh. This could allow you to get a close approximation to the volume in a very short amount of time, provided that you have a capable mesh generation program at your disposal. I might suggest the "Distmesh 3d" package as a starting point for mesh generation in matlab. – Tyler Olsen May 25 '17 at 2:27

Another way is to generate surface mash only and apply Divergence theorem (Gauss's theorem - Ostrogradsky's theorem). $$V = \frac{1}{3}\int_S x\cdot n \textrm{d}S$$