3
$\begingroup$

I've been trying to numerically calculate an integral in a tetrahedron of a discretized domain. In some cases when I specify a method I've been getting the error message

NIntegrate::femonly

NIntegrate[x^2, {x, y, z} \[Element] 
Tetrahedron[{{1.25, 1.875, 0.}, {0., 1.875, 1.25}, {0., 1.25, 
 0.}, {1.125, 1.125, 1.125}}], Method -> "MultidimensionalRule"]

What does this mean? Also, I have noticed a very slow performance for NIntegrate in this case compared to specifying the limits of integration directly. Is this expected?

$\endgroup$
  • $\begingroup$ Are you sure you copied the message tag correctly? I can't find the corresponding message text. Also, could you provide a bit of your code? $\endgroup$ – Sjoerd C. de Vries Oct 28 '14 at 18:25
  • $\begingroup$ @SjoerdC.deVries I added code which produces the error in Mathematica 10.0.0. $\endgroup$ – Jim Oct 28 '14 at 20:30
  • 2
    $\begingroup$ @kirma The function is just an example. In my code I have to use NIntegrate and the integral takes a long time to compute. This is why I have tried different methods and I'm wondering why this message comes up. $\endgroup$ – Jim Oct 28 '14 at 20:51
  • 1
    $\begingroup$ Given that the message text is missing this looks like a case for Wolfram support (support@wolfram.com). $\endgroup$ – Sjoerd C. de Vries Oct 28 '14 at 21:05
  • 3
    $\begingroup$ My guess, FWIW, is that Method -> "FiniteElement" is the only method allowed on a tetrahedron. But you should let Wolfram know. At least they could provide text for the message in the next update. $\endgroup$ – Michael E2 Oct 28 '14 at 21:51
4
$\begingroup$

Perhaps this will help in your general use-cases. Part of the problem comes down to how the tetrahedron region is described. Apparently(?), when the coordinates are approximate reals, the finite element method is invoked. Specifying another method appears to cause the message and the integral not being evaluated. However, if exact coordinates are given, then the "MultidimensionalRule" may be used.

If we convert the coordinate to exact numbers, with

Tetrahedron[
  Rationalize[
   {{1.25, 1.875, 0.}, {0., 1.875, 1.25}, {0., 1.25, 0.}, {1.125, 1.125, 1.125}},
   0]]

then NIntegrate will work, and work fairly quickly:

NIntegrate[x^2,
 {x, y, z} ∈ Tetrahedron[
   Rationalize[
     {{1.25, 1.875, 0.}, {0., 1.875, 1.25}, {0., 1.25, 0.}, {1.125, 1.125, 1.125}},
      0]], 
 Method -> "MultidimensionalRule"]

(* 0.137838 *)

It is quite common for the use of approximate real numbers in the descriptions of inequalities (e.g., regions) to fail where the use of exact numbers succeeds. Round-off error causes numbers whose difference should be zero to end up being slightly off. The loss of precision can be significant.

Consider the following:

Reduce[RegionMember[
    Tetrahedron[
      {{1.25, 1.875, 0.}, {0., 1.875, 1.25}, {0., 1.25, 0.}, {1.125, 1.125, 1.125}}],
    {x, y, z}],
  {x, y, z}];
Through[{Min, Max}[Cases[%, x_?NumericQ :> Abs[x], Infinity]]]

Reduce::ratnz: Reduce was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. >>

(* {1.56582*10^-90, 7.98302*10^89} *)

Exact coordinates:

Reduce[RegionMember[
    Tetrahedron[
      Rationalize[
        {{1.25, 1.875, 0.}, {0., 1.875, 1.25}, {0., 1.25, 0.}, {1.125, 1.125, 1.125}},
        0]],
    {x, y, z}],
  {x, y, z}];
Through[{Min, Max}[Cases[%, x_?NumericQ :> Abs[x], Infinity]]]
(* {0, 48} *)

That is a tremendous difference in the coefficients. Obviously, it is not why the error message is generated. But perhaps it is a hint at why only the finite element method is implemented for certain regions. (By the way, the use of Reduce like this is pretty much how one goes about setting up a multiple integral. It effectively does a CylindricalDecomposition.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.