5
$\begingroup$

I have to plot, in the plane, the following equation

$$ (x_1+x_2-2)^6=64(2x_2-3x_1+1),\quad x_1\leq 0 $$ $$ (x_1+x_2+2)^6=64(-2x_2+3x_1+1),\quad x_1\geq 0.$$

Maybe there is a more appropriate function to plot this but I managed something with ContourPlot:

Show[
 {
  ContourPlot[{(x1 + x2 - 2)^6 == 64 (2 x2 - 3 x1 + 1)}, {x1, -8, 
    8}, {x2, -8, 8}, GridLines -> Automatic, 
   ContourStyle -> {Black, Dashed}],
  ContourPlot[{(x1 + x2 + 2)^6 == 64 (-2 x2 + 3 x1 + 1)}, {x1, -8, 
    8}, {x2, -8, 8}, GridLines -> Automatic, 
   ContourStyle -> {Red, Dashed}]
  }
 ]

Which gives enter image description here

However, for the black-dashed curve, I only need the lower portion (for which $x_1\leq 0$) and for the red-dashed curve, I only need the upper portion (for which $x_1\geq 0$).

I tried using the RegionFunction option but I could only eliminate a portion of what needed to be taken off:

enter image description here

How can I manage this?

$\endgroup$
0

4 Answers 4

4
$\begingroup$

Another way, solving for an explicit formula for the desired function:

Plot[
 x2 /. {First@
     Solve[(x1 + x2 - 2)^6 == 64 (2 x2 - 3 x1 + 1) && x1 <= 0, x2, 
      Reals],
    Last@Solve[(x1 + x2 + 2)^6 == 64 (-2 x2 + 3 x1 + 1) && x1 >= 0, 
      x2, Reals]} // Evaluate,
 {x1, -8, 8},
 PlotStyle -> {Directive[Black, Dashed], Directive[Red, Dashed]},
 PlotRange -> 8, Frame -> True, GridLines -> Automatic, 
 AspectRatio -> 1
 ]
$\endgroup$
6
$\begingroup$

I think your issue might be that $x_1 \leq 0$ and $x_1 \geq 0$ do not properly characterize the parts of the regions you want. It seems that for the bottom one, you want $x_1 \geq -x_2$, and for the top you want $x_1 \leq -x_2$. Then RegionFunction works:

Show[{ContourPlot[{(x1 + x2 - 2)^6 == 64 (2 x2 - 3 x1 + 1)}, {x1, -8, 
    8}, {x2, -8, 8}, GridLines -> Automatic, 
   ContourStyle -> {Black, Dashed}, RegionFunction -> (#1 <= -#2 &)], 
  ContourPlot[{(x1 + x2 + 2)^6 == 64 (-2 x2 + 3 x1 + 1)}, {x1, -8, 
    8}, {x2, -8, 8}, GridLines -> Automatic, 
   ContourStyle -> {Red, Dashed}, RegionFunction -> (#1 >= -#2 &)]}]

enter image description here

$\endgroup$
5
$\begingroup$

I don't know how to translate the contour to a parametric curve directly. So here we try to differential the equation then we get a differential equation and solve it by NDSolve.

$$\frac{dx2}{dx1}=-\frac{\partial{f(x1,x2)}}{\partial x1}/\frac{\partial{f(x1,x2)}}{\partial x2}$$

f[x1_, x2_] := (x1 + x2 - 2)^6 - 64 (2 x2 - 3 x1 + 1);
solf = NDSolve[{D[yf[t], t] D[f[x1, x2], x2] == -D[f[x1, x2], 
        x1] /. {x2 -> yf[t], x1 -> t}, yf[0] == 0}, yf, {t, -10, 0}];
g[x1_, x2_] := (x1 + x2 + 2)^6 - 64 (-2 x2 + 3 x1 + 1);
solg = NDSolve[{D[yg[t], t] D[g[x1, x2], x2] == -D[g[x1, x2], 
        x1] /. {x2 -> yg[t], x1 -> t}, yg[0] == 0}, yg, {t, 0, 10}];
Show[Plot[yf[t] /. solf, {t, -6, 0}, GridLines -> Automatic, 
  PlotStyle -> {Black, Dashed}], 
 Plot[yg[t] /. solg, {t, 0, 6}, PlotStyle -> {Red, Dashed}], 
 PlotRange -> All]

enter image description here

Edit

We can get the parametric curve by differential the equation and set the curve with unit speed velocity.

$$df=\frac{\partial{f}}{\partial x_1}dx_1+\frac{\partial{f}}{\partial x_2}dx_2$$ $$ x_{1}'(t)^2+x_{2}'(t)^2=1 $$

f[x1_, x2_] := (x1 + x2 - 2)^6 - 64 (2 x2 - 3 x1 + 1);
df = Dt[f[x1, x2]] /. {x1 -> x1[t], x2 -> x2[t]} /. Dt[t] -> 1;
solf = NDSolve[{df == 0, x1'[t] + x2'[t] == 1, x1[0] == 0, 
    x2[0] == 0}, {x1, x2}, {t, -6, 6}];
g[x1_, x2_] := (x1 + x2 + 2)^6 - 64 (-2 x2 + 3 x1 + 1);
dg = Dt[g[x1, x2]] /. {x1 -> x1[t], x2 -> x2[t]} /. Dt[t] -> 1;
solg = NDSolve[{dg == 0, x1'[t] + x2'[t] == 1, x1[0] == 0, 
    x2[0] == 0}, {x1, x2}, {t, -6, 6}];
Show[ParametricPlot[{x1[t], x2[t]} /. solf, {t, -1, 2}, 
  PlotStyle -> {Dashed}, Mesh -> {{0}}, 
  MeshShading -> {Black, Green}], 
 ParametricPlot[{x1[t], x2[t]} /. solg, {t, -2, 1}, 
  PlotStyle -> {Dashed}, Mesh -> {{0}}, MeshShading -> {Cyan, Red}], 
 PlotRange -> All, GridLines -> Automatic]

enter image description here

$\endgroup$
4
$\begingroup$

You can use a single ContourPlot with region function Sign[#2] (# + #2) <= 0 & to restrict the plot to the region below the main diagonal for positive y and above the main diagonal for negative y values:

ContourPlot[{(x1 + x2 - 2)^6 == 64 (2 x2 - 3 x1 + 1), 
   (x1 + x2 + 2)^6 ==  64 (-2 x2 + 3 x1 + 1)}, 
 {x1, -8, 8}, {x2, -8, 8}, 
 GridLines -> Automatic, 
 ContourStyle -> Thread[{Dashed, {Black, Red}}], 
 RegionFunction -> (Sign[#2] (# + #2) <= 0 &)]

enter image description here

You can also use

ContourPlot[{ConditionalExpression[(x1 + x2 - 2)^6 - 64 (2 x2 - 3 x1 + 1), 
     Sign[x2] (x1 + x2) <= 0], 
  ConditionalExpression[(x1 + x2 + 2)^6 - 64 (-2 x2 + 3 x1 + 1), 
     Sign[x2] (x1 + x2) <= 0]},
 {x1, -8, 8}, {x2, -8, 8},
 GridLines -> Automatic, 
 ContourStyle -> Thread[{Dashed, {Black, Red}}]]
same picture
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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