Why doesn't RegionPlot plot the region?

Was my 7th grade teacher messing with us when she claimed the set of points that satisfy x^2+y^2=1 was a circle of radius 1? RegionPlot[] thinks so. When it comes to a point (0,0), ContourPlot and RegionPlot each have doubts about that.

More generally, what’s the best way to plot a geometric object defined by an equation or by a system of equations in x,y or x,y,z? The parametric plots work reliably for me, but is there a reliable plotting function that displays the points that satisfy Cartesian equations. Am I doing something wrong with ContourPlot and RegionPlot.

I am not sure if I understand the question.
ContourPlot is designed to plot one-dimensional objects on the cartesian plane.
You are asking RegionPlot to do the same thing–but it has to search for a set of area zero in the plane, and so has to do quite a bit of hunting and recursion to find the one dimensional region. If you are willing to accept a limit then:

Manipulate[
 RegionPlot[1 - e < x^2 + y^2 < 1 + e, {x, -1.2, 1.2}, {y, -1.2, 1.2},
   MaxRecursion -> 5, PlotPoints -> 60], {e, 0, .1}]

From the documentation.

RegionPlot initially evaluates pred at a grid of equally spaced sample
points specified by PlotPoints. Then it uses an adaptive algorithm to
subdivide at most MaxRecursion times, attempting to find the
boundaries of all regions in which pred is True.

and

You should realize that since it uses only a finite number of sample
points, it is possible for RegionPlot to miss regions in which pred is
True. To check your results, you should try increasing the settings
for PlotPoints and MaxRecursion.

It works for x == y and the given ranges because the sample points include that line. If the range is changed to an irrational then RegionPlot is empty

RegionPlot[x == y, {x, -Sqrt[2], Sqrt[2]}, {y, -3/2, 3/2}]

Thanks, Rohit Namjoshi and W. Craig Carter.

I appreciate your explaining why Mathematica didn’t render the defined sets as I entered them. That leaves the second part of my question.

I’ll try to focus it better: What is the most convenient way to visualize the solution to a set of real-valued equations in four or fewer variables? Take a simple example that doesn’t need a graphic to visualize.

I’m not sure about the best way, but these are methods I would employ:

Epilog:

solutions = Solve[{x^2 + y^2 == 1, x == y}, {x, y}];
ParametricPlot[ {{Cos[t], Sin[t]}, {t, t}}, {t, -Pi, Pi}, 
Epilog -> {Red, PointSize[0.05], Point[{x, y} /. solutions]}]

Show:

plot = ParametricPlot[ {{Cos[t], Sin[t]}, {t, t}}, {t, -Pi, Pi}]
points = Graphics[{Red, PointSize[0.05], Point[{x, y} /. solutions]}]
Show[plot, points]

Thanks, W. Craig Carter.

That code nicely produces the desired result. But it skirts the motive behind my question.

I hope (maybe in vain) for an easy way to visualize a set or a geometric object defined by a system of equations. It’s to help me with a book I’m reading on algebraic geometry.

I picked examples x^2 + y^2 = 1 and x = y to avoid extraneous issues. They might have been bad choices since they are so simple they don’t need visualization. Sets defined by more complicated systems of equations – the ones that need visualization – are often difficult to parameterize.

I hope someone has ideas on a general and practical way to visualize sets defined by systems of equations. Or if someone can explain why that’s impossible in Mathematica, I can at least abandon this effort.

Hi Jay,

Can you give an example of

Sets defined by more complicated systems of equations – the ones that
need visualization – are often difficult to parameterize.

Yes, Rohit Namjoshi. Here are some examples. I hope they are good examples. I was in a hurry to respond. So I haven’t thought too much about them. It would be helpful to see how you would visualize any one of these. Please keep in mind they are just examples. My question is about the easiest way to streamline visualization of real sets like these. I’m just an undergraduate math student. So systems like these are difficult for me to visualize. Thanks in advance for any help you can give.

Here is my workflow for your last example. It is not the best workflow, but how I approached it.
Visualize the first two equations:

planes = 
 ContourPlot3D[{x + y + z == 1, x - 2 y - z == 3}, {x, -2, 2}, {y, -2,
    2}, {z, -2, 2}]

Look for a location where I might visualize the third equation:

FindInstance[(y - x^2)^2 + (z - x^3)^2 == 0, {x, y, z}, 6] // N

See if I can find conditions that there are real solutions to the last equation:

Reduce[(y - x^2)^2 + (z - x^3)^2 == 0, {x, y, z}, Reals]

Continue to see if there might be any real solutions other than 0:

Reduce[-x^4 + 2 x^2 y - y^2 > 0, {x, y}, Reals]

I conclude there is no intersection between the three surfaces.

For your second example:

eq1 = x y - z^2 - x;
eq2 = x y z - 2;
ineq3 = x^2 + y^2  + z^2 <= 5;

Sanity check to see if there are any intersections:

FindInstance[{eq1 == 0, eq2 == 0, ineq3}, {x, y, z}, Reals, 6] // N

Reduce[{eq1 == 0, eq2 == 0, ineq3}, {x, y, z}, Reals] // N

It looks like there is a narrow band around x=-1 that may have solutions in it.

Plot the first two surfaces in the region of interest:

surfaces = 
 ContourPlot3D[{eq1 == 0, eq2 == 0}, {x, -1.5, -1}, {y, -10, 
   10}, {z, -10, 10}]

plot the inequality region:

region = 
 RegionPlot3D[ineq3, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, 
  PlotStyle -> {Opacity[0.5], Orange}] (*I added Opacity on a second pass, not on the first work flow*)

VIsualize the intersection:

Show[surfaces, region]

Look for the curve. Copying and pasting as this is a one-time-only:

pp = ParametricPlot3D[{x, Root[-4 - x^3 #1^2 + x^3 #1^3 &, 1], 
   2/(x Root[-4 - x^3 #1^2 + x^3 #1^3 &, 1])}, {x, -1.15, -1.06}, 
  PlotStyle -> {Red, Thickness[0.02]}]

Visualize:

Show[surfaces, region, pp]

I made an error in my first example:
There are real solutions:

FindInstance[(y - x^2)^2 + (z - x^3)^2 == 0, {x, y, z}, Reals, 6] // N

Solve[(y - x^2)^2 + (z - x^3)^2 == 0, z]

Reduce[-x^4 + 2 x^2 y - y^2 >= 0, {x, y}, Reals]

Subspace of real solutions:

((y - x^2)^2 + (z - x^3)^2) /. y -> x^2

Therefore z → x^3

pp = ParametricPlot3D[{x, x^2, x^3}, {x, -10, 10}]

Show[
 ContourPlot3D[{x + y + z == 1, x - 2 y - z == 3}, {x, -2, 2}, {y, -2,
    2}, {z, -2, 2}],
 pp
 ]

Resolve[Exists[{x, y, z}, {(y - x^2)^2 + (z - x^3)^2 == 0, 
   x + y + z == 1, x - 2 y - z == 3} ], {x, y, z}, Reals]

Thanks, W. Craig Carter. This is the best idea I’ve seen. I’ll come back to this thread when I’ve had a chance to apply it more broadly. It will take me some time to see how well it generalizes for me. I’m still Mathematica challenged and mathematics challenged.

You can try the combination Region[ImplicitRegion[]]:

Region[ImplicitRegion[{x^2 + y^2 == 1, x == y}, {x, y}],
 Frame -> True]
Region[ImplicitRegion[{x + y + z == 1, x - 2 y - z == 3},
  {{x, -2, 2}, {y, -2, 2}, {z, -2, 2}}], Boxed -> True]

Thank you Gianluca Gorni. Your approach made fast work of all but one of the examples I posted. See notebook at the end. I’m always amazed at the level of help I can get from this community. I’m sorry I couldn’t give you more than one thumbs up. Your answer deserves more.

Region[] and ImplicitRegion[] are amazing. You don’t even need to tell them how many dimensions to return. I spent many hours pouring through the Visualization & Graphics section of the documentation. I should have been looking in the Geometry section. I posted an earlier question just asking what function(s) were most direct, but the moderators pulled that question because it didn’t have any specific code questions.

I’m not sure what the conditionals are telling me in some of the results. I’ll keep working on that.
As for the system of equations that failed to render, Reduce[] gives an answer, but I’ll have to figure out how to put it in a form ImplicitRegion[] can handle, if that’s possible.

I am new to Mathematica. What is the standard way to alter presentation of Region[]? Options seem to be different from the plotting presentation options. For example, how would you make the region shown below (two points and a line segment) stand out, say, by making them red and bolder/thicker? Also, should I care that Subscript[[ScriptCapitalR], 1] doesn’t turn black when defined?

You could use Style

Show[
 	Region[Style[ImplicitRegion[Subscript[\[ScriptCapitalR], 1], {x, y}], Red, PointSize@Large]],
 	Region[Style[ImplicitRegion[Subscript[\[ScriptCapitalR], 2], {x, y}], Red, Thick]],
 	PlotRange -> rng1, Axes -> True
 ]

Thanks, Hans Milton. That works. It’s simple and tells me how to do lots of over things. I love this community.

Hi Jay,

You may be interested in this article from the Mathematica Journal. The article is based on this book by the same author. There is a link to download the notebooks used in the book.

Thanks, Rohit Namjoshi. I’ve downloaded it. It will take a while to read, but your recommendation is enough for me.

The generalized introductory documentation for Mathematica is great but never detailed enough to do anything useful. Finding the specialized literature that focuses on the details needed for a special application is hard. So it’s great that you shared this.

Jay,

your basic question was perfectly answered by Hans Milton: Style in combination with Region - this is great (+1)!

Here I just have a remark:

When I started to try understanding Mathematica, (well, I am still trying!) I found this discussion on SE extremely useful. There you also will find some background regarding your question:

Also, should I care that Subscript[\[ScriptCapitalR], 1] doesn’t turn black when defined?

The reason is that \[ScriptCapitalR] is not defined by this - and stays blue. What is done here instead is adding some additional definitions to Subscript.

So, Subscript[\[ScriptCapitalR], 1] is not a symbol, OwnValues[Subscript[\[ScriptCapitalR], 1]] does not work! The general advice is, not to use Subscript at all, except maybe at the very end of a calculation for displaying reasons.

Thanks, Henrik Schachner. Looks like that link flags some likely pitfalls.