5

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

chris
  • 22,860
  • 5
  • 60
  • 149
  • 1
    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. – bbgodfrey Feb 04 '15 at 18:24
  • @bbgodfrey good point, but on the other hand it is not on the interval I am considering. – chris Feb 04 '15 at 18:26
  • 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. – Szabolcs Feb 04 '15 at 18:47
  • @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. – Szabolcs Feb 04 '15 at 18:56
  • 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. – Szabolcs Feb 04 '15 at 18:58

1 Answers1

5
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.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • Thanks. I did not realize you could discretize also 1D regions. That should do the trick for my problem. – chris Feb 05 '15 at 08:05
  • @chris Just keep in mind that the accuracy of the discretization can have a significant effect on the result of the integral. – Szabolcs Feb 05 '15 at 16:27