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.
Sin[Pi x] == y
might be failing because its inverse is multivalued, I triedExp[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$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$Reduce
that problem goes away yet Mathematica still can't figure out that it's a 1D region. $\endgroup$