Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improve corner rendering in RegionPlot in Mathematica

I am using RegionPlot to display a system of linear inequalities in two variables to help me find parameter values for which they can all be satisfied, or if there don't exist any, to get a feel for them to understand why. But when I graph them, RegionPlot very literally cuts corners. How can I get a more accurate graph of regions bounded by linear inequalities?

Here is a minimal example (actual code much hairier):

RegionPlot[{y > 0 && x > 0 && x - y > 0, 
  y < .1 && x < .1 && x - y < .1}, {x, -10, 10}, {y, -10, 10}]

Output plot here.

In this example, Mathematica cuts off the bottom-left quarter of the first-quadrant region, which makes it appear as if the two regions don't intersect. But they do.

Things I've considered but rejected:

  1. Using FindInstance to find the intersection of the regions. So far, FindInstance has failed to find any intersection, but I'm not sure if that is due to specific choices of parameter values. More importantly, if there is no intersection, I want to get a sense of which conditions are likely to be contradictory by playing with the parameters (via Manipulate).

  2. Changing the scale of the graph. In my actual code, there are several such intersecting regions, and I'd like to see them all on one plot. So I'd really like to improve corner rendering given a plot scale.

like image 868
Seth Avatar asked Feb 24 '26 00:02

Seth


1 Answers

The problem is that RegionPlot samples some initial points and then refine the areas with changes to improve the plot without affecting the performance by sampling unchanged areas. In this case, it is missing the central detail, I think.

Try increasing the MaxRecursion option or the initial number of points with PlotPoints, for example, these two examples will give good results but the performance will suffer. Which one is better will depend on the real case, I think.

RegionPlot[{y > 0 && x > 0 && x - y > 0, 
  y < .1 && x < .1 && x - y < .1}, {x, -10, 10}, {y, -10, 10}, 
 PlotPoints -> 100]

RegionPlot[{y > 0 && x > 0 && x - y > 0, 
  y < .1 && x < .1 && x - y < .1}, {x, -10, 10}, {y, -10, 10}, 
 MaxRecursion-> 6]
like image 92
siritinga Avatar answered Feb 27 '26 01:02

siritinga