5
$\begingroup$

QUESTION

How come this works:

NIntegrate[1, {x, y} ∈ 
  ImplicitRegion[{x == y^3, x <= 1, x >= 0}, {x, y}]]

But this fails:

NIntegrate[1, {x, y} ∈ 
  ImplicitRegion[{Sin[Pi x] == y, x <= 1, x >= 0}, {x, y}]]

where we have

ContourPlot[x == y^3, {x, 0, 1}, {y, 0, 1}]

Mathematica graphics

and

ContourPlot[Sin[Pi x] == y, {x, 0, 1}, {y, 0, 1}]

Mathematica graphics

A related question is this one

$\endgroup$
  • 1
    $\begingroup$ Thinking that Sin[Pi x] == y might be failing because its inverse is multivalued, I tried Exp[x] == y, but it also fails. Yet, Abs[x - .5] == Sqrt[y] works fine, giving the same answer as (x - .5)^2 == y, as it should. $\endgroup$ – bbgodfrey Feb 4 '15 at 18:24
  • $\begingroup$ @bbgodfrey good point, but on the other hand it is not on the interval I am considering. $\endgroup$ – chris Feb 4 '15 at 18:26
  • $\begingroup$ Could it be because it can't figure out the dimension of the region? RegionDimension[ ImplicitRegion[Sin[\[Pi] x] == y && x <= 1 && x >= 0, {x, y}]] fails. The same thing works for the first region you tried. NIntegrate would need to know what this is really a 1D integral, not a 2D one, to give a reasonable (non-zero) result. $\endgroup$ – Szabolcs Feb 4 '15 at 18:47
  • $\begingroup$ @bbgodfrey I doubt it. If we invert the relationship using Reduce that problem goes away yet Mathematica still can't figure out that it's a 1D region. $\endgroup$ – Szabolcs Feb 4 '15 at 18:56
  • $\begingroup$ I do wonder if this is a bug. I would have thought that even discretization would require figuring out the dimension first. It does produce a 1D-type discretized region after all. Perhaps it's something worth reporting. $\endgroup$ – Szabolcs Feb 4 '15 at 18:58
5
$\begingroup$
reg = ImplicitRegion[{Sin[Pi x] == y, x <= 1, x >= 0}, {x, y}]

This is a 1D region embedded in 2D space. NIntegrate needs to know this to produce a reasonable result. My guess is that it uses RegionDimension, which fails here:

In[41]:= RegionDimension[reg]

During evaluation of In[41]:= RegionDimension::nmet: Unable to compute the dimension of region ImplicitRegion[Sin[π x]==y&&x<=1&&x>=0,{x,y}]. >>

Out[41]= RegionDimension[
 ImplicitRegion[Sin[π x] == y && x <= 1 && x >= 0, {x, y}]]

RegionMeasure would be equivalent to your NIntegrate example in this specific case and it also fails.

Mathematica can determine the dimension of the other region just fine:

RegionDimension@
 ImplicitRegion[{x == y^3, x <= 1, x >= 0}, {x, y}]
(* 1 *)

We could however discretize the region first:

In[42]:= dreg = DiscretizeRegion[reg]

In[43]:= RegionDimension[dreg]
Out[43]= 1

In[44]:= RegionMeasure[dreg]
Out[44]= 2.30414

In[45]:= NIntegrate[1, {x, y} ∈ dreg]
Out[45]= 2.30414

This works, but the problem is that at the discretization step we lose precision that NIntegrate can never re-gain afterwards.

DiscretizeRegion has several options which can control how and how accurately the discretization is done. I'm not sure which one is the best choice in this case, but MaxCellMeasure would be one.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks. I did not realize you could discretize also 1D regions. That should do the trick for my problem. $\endgroup$ – chris Feb 5 '15 at 8:05
  • $\begingroup$ @chris Just keep in mind that the accuracy of the discretization can have a significant effect on the result of the integral. $\endgroup$ – Szabolcs Feb 5 '15 at 16:27

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.