1
$\begingroup$

The plot function does not want to plot the equation system as is:

eq = y == 5 + 2 x - Sqrt[-115 + 30 x + 6 x^2] || 
  y == 5 + 2 x + Sqrt[-115 + 30 x + 6 x^2]
Plot[eq, {x, 0, 10}]

Out[...]=<... empty plot ...>

I can resolve that by rearrange the components:

eq = y == 5 + 2 x - Sqrt[-115 + 30 x + 6 x^2] || 
  y == 5 + 2 x + Sqrt[-115 + 30 x + 6 x^2]
Subscript[y, 1][x] = eq[[1]][[2]]
Subscript[y, 2][x] = eq[[2]][[2]]
Plot[Evaluate[{Subscript[y, 1][x], Subscript[y, 2][x]}], {x, 0, 10}]

I don't want to rearrange the equation system, because it is the output from another function which depends on the input and can change unpredictably.

How to resolve that w/o splitting up the equation system on components?

$\endgroup$
3
$\begingroup$

In some cases you can directly "plot" a logical expression as an implicit region plot:

RegionPlot[ImplicitRegion[eq, {{x, 0, 10}, {y, 0, 40}}], 
 PlotPoints -> 100]

enter image description here

note this plot erroneously plots a line for x<~2.5 , but still may be useful to you.

| improve this answer | |
$\endgroup$
  • $\begingroup$ What MM version are you running? I'm running 10.4.1 on a Mac, and it doesn't produce a plot for $x \lesssim 2.5$. $\endgroup$ – Michael Seifert Apr 23 '18 at 21:31
  • $\begingroup$ @MichaelSeifert I see this in 10.1\Windows and 11.1.1\Linux. $\endgroup$ – george2079 Apr 23 '18 at 21:33
  • $\begingroup$ Seems 11.2 version falls into infinite loop to plot that. $\endgroup$ – Andry Apr 23 '18 at 21:38
  • $\begingroup$ as you see the region functions are a bit tempermental. $\endgroup$ – george2079 Apr 23 '18 at 21:45
3
$\begingroup$

Let's try a little pattern matching

eq = y == 5 + 2 x - Sqrt[-115 + 30 x + 6 x^2] || 
  y == 5 + 2 x + Sqrt[-115 + 30 x + 6 x^2];
neweq=List@@eq /.Equal[y,v_]->v;
Plot[neweq,{x,0,10}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ This is another one splitup. What about more complicated equation with intervals like x > 0, y >= 0? Do I need to predict all over the place rules for that? $\endgroup$ – Andry Apr 23 '18 at 21:02
  • 3
    $\begingroup$ As nicely as I can possibly put it, it is really common for a person to post a question, another person reads that, writes the answer to that and the first person responds "yah but, what if I wanted the answer to something different?" It is a difficult balancing act to find a way to express a problem that isn't too broad, vague and general and thus potentially gets no answer at all versus how to express a problem that is too narrow and limited and doesn't answer what the person really wanted. I don't know how to resolve that, not at least until MMA includes the "Do What I Mean" button. $\endgroup$ – Bill Apr 23 '18 at 21:08
  • $\begingroup$ Does it means I have to manually analyze the output of each equation solution and write my own pattern-parser for it? $\endgroup$ – Andry Apr 23 '18 at 21:17
  • 1
    $\begingroup$ You can learn about things like ToRules that might help you. You can explore the ever growing list of new different kinds of plotting functions that might help you. But since Plot wants to plot a simple expression or a list of simple expressions then it seems really unlikely that you will be able to make Plot work for you if you give it what may be an arbitrary collection of boolean conditions and expressions and equations and get what you seem to be hoping for. So roughly I think the answer to your latest question is: yes. $\endgroup$ – Bill Apr 23 '18 at 21:23
2
$\begingroup$
eq = y == 5 + 2 x - Sqrt[-115 + 30 x + 6 x^2] || 
   y == 5 + 2 x + Sqrt[-115 + 30 x + 6 x^2];

Plot[Evaluate[y /. {eq // ToRules}], {x, -15, 10},
 PlotLegends -> Placed["Expressions", {.25, .75}]]

enter image description here

Also,

ContourPlot[Evaluate[List @@ eq], {x, -15, 10}, {y, -60, 60}, 
 PlotPoints -> 100, PlotLegends -> Placed["Expressions", {.35, .75}]]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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