1
$\begingroup$

I'm having an issue where it seems like the region Mathematica shows depends on what the domain is (i.e. not just different parts of the same domain).

The code that gives me 2 intersecting lines $y = x$ and $y = 1 - x$ in the square $[0, 1] \times [0, 1]$:

Clear[polys, result];
polys = {
   (x^2 - x) - (y^2 - y), 
   (2 m*x - x - m + 1/2)^2 + (2 m*y - y - m + 1/2)^2 - 
    4 (m^2 - m) (x^2 - x)};
result = Resolve[Exists[{m}, polys == 0], Reals];
RegionPlot[result, {x, 0, 1}, {y, 0, 1}]

But, if I just change the y domain to end at $1/2$ instead of $1$, I get a completely empty plane, not just a zoomed in version of the original picture:

Clear[polys, result];
polys = {
   (x^2 - x) - (y^2 - y), 
   (2 m*x - x - m + 1/2)^2 + (2 m*y - y - m + 1/2)^2 - 
    4 (m^2 - m) (x^2 - x)};
result = Resolve[Exists[{m}, polys == 0], Reals];
RegionPlot[result, {x, 0, 1}, {y, 0, 1/2}]

If I change the $x$ and $y$ bounds in other situations I also get various different pictures. I know in this situation that the correct picture is in fact the two lines intersecting, but I won't know the answer in more complicated situations.

How do I "fix" this issue where Mathematica gives me different regions depending on what the $x$ and $y$ bounds are?

$\endgroup$
1
  • $\begingroup$ I'm suprised that your first RegionPlot shows something. Usually RegionPlot only shows 2D-regions I think. $\endgroup$ Commented Aug 16, 2021 at 7:05

2 Answers 2

3
$\begingroup$

Usually RegionPlot cann't show 1D-regions!

cond = Simplify[result, {  1 >= x >= 0, 1 >= y >= 0}] /. Or -> List
(* {x == y, x + y == 1}*)

ContourPlotshows these lines in both domains

Row[{ContourPlot[ Evaluate[cond] , {x, 0, 1}, {y, 0, 1}],ContourPlot[ Evaluate[cond] , {x, 0, 1}, {y, 0, 1/2}]}]

enter image description here

$\endgroup$
1
$\begingroup$

RegionPlot sometimes tries to discrete the object automatically,this is why it can draw both 1-D and 2-D region. But it seems that it doesn't always take effect,so we need to discrete the object manually or use Region etc.

polys = {(x^2 - x) - (y^2 - 
      y), (2 m*x - x - m + 1/2)^2 + (2 m*y - y - m + 1/2)^2 - 
    4 (m^2 - m) (x^2 - x)};
result = Resolve[Exists[{m}, polys == 0], Reals];
{Region[ImplicitRegion[result, {{x, 0, 1}, {y, 0, 1}}]],
  Region[ImplicitRegion[
    result, {{x, 0, 1}, {y, 0, 1/2}}]]} // GraphicsRow

enter image description here

Original

One way is using ImplicitRegion and DiscretizeRegion before RegionPlot.

Clear[polys, result, reg1, reg2];
polys = {(x^2 - x) - (y^2 - 
      y), (2 m*x - x - m + 1/2)^2 + (2 m*y - y - m + 1/2)^2 - 
    4 (m^2 - m) (x^2 - x)};
result = Resolve[Exists[{m}, polys == 0], Reals];
reg1 = ImplicitRegion[result, {{x, 0, 1}, {y, 0, 1}}];
reg2 = ImplicitRegion[result, {{x, 0, 1}, {y, 0, 1/2}}];
{RegionPlot[DiscretizeRegion[reg1]], 
  RegionPlot[DiscretizeRegion[reg2]]} // GraphicsRow

enter image description here

$\endgroup$

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.