0
$\begingroup$

So I have this system of equations that I've solved by hand, but want to graph with multiple initial conditions. But I don't want to have mutiple spamming lines of code like this.

graph1a = ContourPlot[{y^3 == x^3}, {x, -10, 10}, {y, -10, 10}];
graph2a = ContourPlot[{y^3 == x^3 + 2}, {x, -10, 10}, {y, -10, 10}];
graph3a = ContourPlot[{y^3 == x^3 - 2}, {x, -10, 10}, {y, -10, 10}];
graph4a = ContourPlot[{y^3 == x^3 + 15}, {x, -10, 10}, {y, -10, 10}];
graph5a = ContourPlot[{y^3 == x^3 - 15}, {x, -10, 10}, {y, -10, 10}]; 
graph6a = ContourPlot[{y^3 == x^3 + 75}, {x, -10, 10}, {y, -10, 10}];
graph7a = ContourPlot[{y^3 == x^3 - 75}, {x, -10, 10}, {y, -10, 10}];
Show[graph1a, graph2a, graph3a, graph4a, graph5a, graph6a, graph7a]

I'm pretty sure there's a way to nicely put this into fewer lines. The Equation solution is

y^3 = x^3 + K

with $K$ being the initial condition.

$\endgroup$
  • $\begingroup$ that would be enough: ContourPlot[{y^3 == x^3 + {0, 2, -2, 15, -15, 75, -75}}, {x, -10, 10}, {y, -10, 10}] $\endgroup$ – garej Mar 16 '16 at 7:36
5
$\begingroup$

What you want to plot are simply some contour lines of a single function, $y^3-x^3$, so there is no need to to Show many graphics overlapped, all the tools are provided by ContourPlot itself:

ContourPlot[y^3 - x^3, {x, -10, 10}, {y, -10, 10},
 Contours -> {0, 2, -2, 15, -15, 75, -75},
 ContourShading -> None,
 ContourLabels -> True,
 ContourStyle -> Gray
 ]

Mathematica graphics

If you prefer some colors, you can replace the last option with something like ContourStyle -> ColorData[3, "ColorList"]:

Mathematica graphics

$\endgroup$
4
$\begingroup$
Show@
  Table[
    ContourPlot[{y^3 == x^3 + const}, {x, -10, 10}, {y, -10, 10}],
    {const, {0, 2, -2, 15, -15, 75, -75}}
  ]

Mathematica graphics

$\endgroup$
2
$\begingroup$

Alternatively,

ContourPlot[
 Evaluate[Table[y^3 == x^3 + k, {k, {0, 2, -2, 15, -15, 75, -75}}]], {x, -10, 
  10}, {y, -10, 10}]

enter image description here

Or if you want to augment existing Tooltip

ContourPlot[
 Evaluate[Table[y^3 == x^3 + k, {k, {0, 2, -2, 15, -15, 75, -75}}]], {x, -10, 
  10}, {y, -10, 10}, PlotLegends -> "Expressions"]

enter image description here

$\endgroup$
  • $\begingroup$ Why is there Evaluate function in the argument for ContourPlot? $\endgroup$ – Smart Humanism Mar 16 '16 at 18:11
  • $\begingroup$ @SmartHumanism - remove the Evaluate and compare the results. Then look at the Attributes for ContourPlot. $\endgroup$ – Bob Hanlon Mar 16 '16 at 18:16

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.