4
$\begingroup$

I have two semicircles that are identical except that the second is shifted one unit to the right.

R1 := ImplicitRegion[0 <= y <= Sqrt[1 - x^2], {x, y}]
R2 := ImplicitRegion[0 <= y <= Sqrt[1 - (x - 1)^2], {x, y}]

When I plot them I get

Expected behavior of RegionPlot Unexpected behavior of RegionPlot

What's up with the second plot? It should look the same as the first, right? Is this somehow a result of imaginary values of Sqrt?

$\endgroup$
2
  • $\begingroup$ I've reproduced this and passed it along to the developers. $\endgroup$
    – rcollyer
    Oct 29, 2015 at 2:46
  • $\begingroup$ @rcollyer Awesome, thanks! Some more (related) unexpected behavior is described in my comments on the answers. $\endgroup$ Oct 29, 2015 at 3:35

2 Answers 2

4
$\begingroup$

Somehow Mathematica allows your variables to be Imaginary. Restrict them to Reals, and all works fine:

R1 := Assuming[{x, y} \[Element] Reals, 
   ImplicitRegion[0 <= y <= Sqrt[1 - x^2], {x, y}]];
R2 := Assuming[{x, y} \[Element] Reals, 
   ImplicitRegion[0 <= y <= Re@Sqrt[1 - (x - 1)^2], {x, y}]];

Hmmm.... it is curious that one must specify the full range of $x$ in RegionPlot[R2], but if you recast the equations this way:

R3 := Assuming[{x, y} \[Element] Reals, 
   ImplicitRegion[(x - 1)^2 +  y^2 <= 1 && y > 0, {x, y}]];

all works fine.

$\endgroup$
3
  • $\begingroup$ This looks great. (I used RegionPlot[ImplicitRegion[{x, y} \[Element] Reals && 0 <= y <= Sqrt[1 - (x - 1)^2], {x, y}]], which gives the same result as your R2.) However, I only get a quarter-circle unless I also specify 0 ≤ x ≤ 2. Is there any way to have Mathematica figure out the window automatically? $\endgroup$ Oct 29, 2015 at 0:09
  • $\begingroup$ Hm. Very odd... I notice that I can drop the Real checking entirely with your amendment: RegionPlot[ImplicitRegion[(x - 1)^2 + y^2 <= 1 && y >= 0, {x, y}]]. I think your solution is the most foolproof. If there's documentation on the possible inaccuracies of RegionPlot I'd love to see it, but the current docs don't even mention the RegionPlot[region] syntax yet. $\endgroup$ Oct 29, 2015 at 0:57
  • $\begingroup$ @raxod502 - The form RegionPlot[region] is indirectly documented by the documentation for ImplicitRegion. $\endgroup$
    – Bob Hanlon
    Oct 29, 2015 at 1:32
6
$\begingroup$

Since you shifted the oval you must shift the domain of x for the second region

R1 := ImplicitRegion[-1 <= x <= 1 && 0 <= y <= Sqrt[1 - x^2], {x, y}]

R2 := ImplicitRegion[0 <= x <= 2 && 0 <= y <= Sqrt[1 - (x - 1)^2], {x, y}]

GraphicsRow[RegionPlot /@ {R1, R2}]

enter image description here

$\endgroup$
2
  • $\begingroup$ I don't understand why I have to specify the domain at all (for instance, I didn't have to in R1). For an ImplicitRegion, shouldn't Mathematica be able to figure it out automatically? $\endgroup$ Oct 28, 2015 at 21:17
  • 1
    $\begingroup$ @raxod502 - I agree that Mathematica should be able to figure it out; however, when you experience a problem then add information that you know: FunctionDomain[Sqrt[1 - x^2], x] is -1 <= x <= 1 and FunctionDomain[Sqrt[1 - (x - 1)^2], x] is 0 <= x <= 2. $\endgroup$
    – Bob Hanlon
    Oct 28, 2015 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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