3
$\begingroup$

I want to plot a line defined IMPLICITLY by the intersection of an equality and an inequality, i.e. a line that you can't easily simplify (and therefore take advantage of its form). Consider for instance the simple example

R=x > 0 && y == -((5 x)/3)

but assume you don't know which equalities and inequalities it involves (although you know it's a line and not a 2D region).

How can I plot the set R? I can't use RegionPlot as it only consider regions defined by inequalities, but at the same time ContourPlot

ContourPlot[R, {x, -2, 2}, {y, -2, 2}]

does not work.

I know there is the function ImplicitRegion, but

ContourPlot[ImplicitRegion[R, {x, y}], {x, -2, 2}, {y, -2, 2}]

does not work either.

I repeat, do not take advantage of the expressions in R - if you could a solution is to use ContourPlot with RegionFunction.

PS this question is related to Integration over a (non-parametric) curve defined by indicator function

$\endgroup$
7
  • $\begingroup$ Is RegionPlot useful ? $\endgroup$ Commented Oct 28, 2014 at 12:18
  • $\begingroup$ No, RegionPlot allows only to plot sets defined only by inequalities. $\endgroup$
    – Nicola
    Commented Oct 28, 2014 at 12:20
  • $\begingroup$ RegionPlot+ImplicitRegion works for me. i.sstatic.net/e4C9m.png $\endgroup$
    – user484
    Commented Oct 28, 2014 at 12:25
  • 2
    $\begingroup$ @rhermans I disagree with the close votes. Just because there is a simple answer does not mean it is a simple mistake. I mean my first thought was why doesn't ContourPlot work here. Before the region functionality of V10, RegionPlot would have failed miserably on such a problem. To satisfy the OP's constraint is difficult with ContourPlot. $\endgroup$
    – Michael E2
    Commented Feb 17, 2016 at 14:14
  • 1
    $\begingroup$ @rhermans The region is, in fact, a contour. But the way Mathematica works makes RegionPlot the best approach. It seems to me that if one looks at an object as a contour, one would naturally consider ContourPlot. If other plotters work with regions, why not ContourPlot? (It's not a ground-breaking question to be sure, but I think it passes muster.) Thanks, in any case. $\endgroup$
    – Michael E2
    Commented Feb 17, 2016 at 22:01

3 Answers 3

3
$\begingroup$

Answer

RegionPlot[ImplicitRegion[R, {x, y}]]

Mathematica graphics

Documentation

ImplicitRegion

Mathematica graphics

RegionPlot

Mathematica graphics

$\endgroup$
3
$\begingroup$

This can easily be done with ContourPlot: you have an equality and an inequality. Put the equality as the argument to ContourPlot and the inequality as the value of the option RegionFunction

ContourPlot[y == -((5 x)/3), {x, -2, 2}, {y, -2, 2}, 
 RegionFunction -> (#1 > 0 &)]

enter image description here

$\endgroup$
3
$\begingroup$

Rahul's comment is the way to do it with ImplicitRegion directly, since RegionPlot is the plotter to use with regions. If a solution in terms of ContourPlot is desired, then a numeric function (or an equivalent equation) describing the region will be needed.

Here is one way to go from ImplicitRegion to ContourPlot.

reg = ImplicitRegion[x > 0 && y == -((5 x)/3), {x, y}];
ysol = Solve[RegionMember[reg, {x, y}], y];
ContourPlot[y == (y /. ysol), {x, -2, 2}, {y, -2, 2}]

Mathematica graphics

There are two obvious limitations: (1) The limitations of Solve, which are more than sufficient for the present task. (2) The the variable to be solved for, y or x, needs to be chosen appropriately in the case of a horizontal or vertical line.

What's going on is that Solve returns a ConditionalExpression that is undefined when x <= 0:

ysol = Solve[RegionMember[reg, {x, y}], y]
(*  {{y -> ConditionalExpression[-((5 x)/3), x > 0]}}  *)
$\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.