# Integrate function over a 2D implicit surface

I have the following problem. Let's say we have a 2D region, let me be very explicit:

R = ImplicitRegion[
Cos[x] + Cos[y] + Cos[z] ==
1.5, {{x, -π, π}, {y, -π, π}, {z, -π, π}}];


I'd like to integrate some function over this surface (looks like potato), for example it's area is given by integral over the surface of function equal to 1:

NIntegrate[1, {x, y, z} ∈ R]


Unfortunately, the result is the input, i.e. Mathematica doesn't know how to do the integration. Never mind, we can always discretize region:

dR = DiscretizeRegion[R, MaxCellMeasure -> 100]


Now, it works!

NIntegrate[1, {x, y, z} ∈ dR]


gives

46.2047


Some odd function:

NIntegrate[x, {x, y, z} ∈ dR]


gives:

0.0000340503


Should be zero from (anti)symmetry, but nevermind, it's the matter of discretization step.

But now, when I try (the result should also be close to zero):

NIntegrate[Sin[x], {x, y, z} ∈ dR]


The output is rather lengthy and intriguing error "tdlen: Objects of unequal length in \ {NIntegrateSimplexQuadratureDumpU\$14954[1], ..." and "Could not complete external evaluation at instruction 186; proceeding \ with uncompiled evaluation." - what does it mean? How different is Sin[x] from x? The result after listing those errors is -0.000115624 (sounds likely), but it takes longer (significantly). How can I integrate ANY function over ANY 2D implicit region (the one I chose is something that can't be done analytically to demonstrate nature of this error)? What's nature of these errors? Did someone else run into the same or similar problem as me? Thanks.

P.S.: I tried with f[x_,y_,z_]:= (Sin[x]^2+Sin[y]^2+Sin[z]^2)^(-1/2) and for this function the result is not even a number, it's lot of errors and the input.

I have Mathematica student version 10.0.2.0 running on Win 10.

• NIntegrate[Sin[x], {x, y, z} ∈ R] works for me. Commented May 9, 2016 at 16:21
• Wow, how? For me it doesn't. Which version of M are you using? Commented May 9, 2016 at 16:24
• I am using 10.4.1, on Xubuntu Trusty. You might want to include your version number and OS in your question. Commented May 9, 2016 at 16:26
• As a workaround, have you tried reformulating your integral to use Boole[] instead? Commented May 9, 2016 at 16:32
• i opened a post on the same question and i obtained a satisfying answer. Commented Nov 29, 2016 at 17:19

It turns out that NIntegrate has been improved these years. The following is the output in v13.3:

Still, there's a mysterious warning, but the issues mentioned in the question no longer exist.

• Funny, cause Cloud 13.3 prints positive results. Commented Jun 27, 2023 at 9:45