Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have strange problem with Wolfram Mathematica's function RegionPlot

RegionPlot[x - y == 0, {x, 0, 100}, {y, 0, 100}]

the result is:

enter image description here

But when I try

RegionPlot[x - y == 1, {x, 0, 100}, {y, 0, 100}]

enter image description here

Do you know what I am doing wrong? Thanks!

share|improve this question
4  
Documentation states that "RegionPlot will only visualize two-dimensional regions: ". So, the question is, why did the first plot show a line? – bbgodfrey Feb 28 at 15:53
    
I'm doing exercise in which I need to use function RegionPlot to draw a line, but I guess there must be an error in exercise. – user38129 Feb 28 at 16:01
    
There is not an error in your exercise! – rewi Feb 28 at 16:17
up vote 6 down vote accepted

Starting with v10.0 you can use InfiniteLine

RegionPlot[
 InfiniteLine[{x, x - 1} /. {{x -> 0}, {x -> 1}}], 
 PlotRange -> {0, 100}]

enter image description here

share|improve this answer

What do you want

ContourPlot[x - y == 1, {x, 0, 100}, {y, 0, 100}]

enter image description here

or should it be

RegionPlot[x - y < 1, {x, 0, 100}, {y, 0, 100}]

enter image description here

Addendum for exercise. You have to define a region!

reg = ImplicitRegion[x - y == 1, {x, y}];
RegionPlot@reg

enter image description here

reg = ImplicitRegion[x - y == 1 && 0 < x < 100 && 0 < y < 100, {x, y}];
RegionPlot@reg

enter image description here

RegionPlot will only visualize two-dimensional regions. See the documentation "Possible Issues".

share|improve this answer
    
I'm doing exercise in which I need to use function RegionPlot to draw a line. – user38129 Feb 28 at 15:57
1  
@rewi Why did the first example work? This seems to be a one-dimensional region which violates the Possible Issues in the documentation. – Jack LaVigne Feb 28 at 16:20
    
@Jack LaVigne Unfortunately, I also know not all :) – rewi Feb 28 at 16:24
2  
@JackLaVigne The example in possible issues seems to need modification since the introduction of ImplicitRegions – Coolwater Feb 28 at 19:39

Correction:

RegionPlot[x - y == 1, {x, 0, 100}, {y, -1, 99}]

Why does it work? Consider the following example. RegionPlot understands True statement (put any a).

With[{a = 50}, 
 RegionPlot[x - y == a, {x, 0, 100}, {y, 0 - a, 100 - a}]]

enter image description here

share|improve this answer
1  
+1 I think you have nailed it. Excellent explanation. – Jack LaVigne Feb 28 at 22:05

Due to the sampling pattern used by RegionPlot, it is lucky that it finds the line in your first example. Consider the output of

noisyFunction[x_, y_] := Module[{},
    Sow[{x, y}];
    x - y
];
ListPlot[
  Take[
    Reap[
      RegionPlot[noisyFunction[x, y] == 0, {x, 0, 100}, {y, 0, 100}]
    ][[2, 1]],
  {4, -1}]
]

The clustering of samples around the line is easily seen. But RegionPlot is not lucky for your second example.

ListPlot[
  Take[
    Reap[
      RegionPlot[noisyFunction[x, y] == 1, {x, 0, 100}, {y, 0, 100}]
    ][[2, 1]],
  {4, -1}]
]

One should use EvaluationMonitor if one is going to be serious about inspecting the evaluation set of a function fed to a plot or numerical search.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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