8
$\begingroup$

It seems like a natural thing to do, however I can't seem to find anything on the docs nor here on SE.

What I'd like to plot is the locus of solutions to a system of (polynomial) equations, e.g. $$\begin{cases}x=yz\\ y^2=xz\end{cases}$$.

I tried with with the command

ContourPlot3D[{x == y*z, y^2 == x*z}, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}]

However I get the two plots of each equation, which is not what I want: plot

Basically, I'd like to see just the intersection.

What is the easiest way to do that?

$\endgroup$
  • $\begingroup$ I made a thousand edits because the editor didn't let me publish the question, it kept complaining around missing code fences except there already were code fences. $\endgroup$ – mattecapu May 17 at 16:25
8
$\begingroup$

You can "plot" one equation as a contour and draw the mesh lines of the other equation onto it by using the option MeshFunctions.

curve = ContourPlot3D[
  y^2 == x z
  {x, -10, 10}, {y, -10, 10}, {z, -10, 10},
 MeshFunctions -> Function[{x, y, z}, x - y z],
 Mesh -> {{0}},
 ContourStyle -> None,
 BoundaryStyle -> None,
 MeshStyle -> Thick,
 PlotPoints -> 100
 ]

enter image description here

Here is also a compined plot that looks a bit more fancy:

surf = ContourPlot3D[{y^2 == x z, x == y z}, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, ContourStyle -> Opacity[0.4]];
Show[
  surf, 
  curve /. Line[x__] :> {Lighter@Black, Specularity[White, 30], 
     Tube[x, 0.2]}, 
  Lighting -> "Neutral"
  ]

enter image description here

$\endgroup$
  • $\begingroup$ ugly yet effective... thanks! to the future me: Mesh-> {{0}} selects the level set $=0$ for the specified mesh function, the rest of the options is to remove stuff we don't want to see $\endgroup$ – mattecapu May 17 at 16:36
  • 1
    $\begingroup$ Exactly. You got it. $\endgroup$ – Henrik Schumacher May 17 at 16:37
11
$\begingroup$

Define an implicit region with your equations by And-combining them:

ir = ImplicitRegion[x == y*z && y^2 == x*z, {x, y, z}];

Make a 3D plot by discretizing the implicit region:

DiscretizeRegion[ir, 3*{{-1, 1}, {-1, 1}, {-1, 1}}, 
  MaxCellMeasure -> 10^-4, Boxed -> True, Axes -> True]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Wow, I am surprised that DiscretizeRegion works so well on this! It used to produce quite shabby results for lower-dimensional regions... $\endgroup$ – Henrik Schumacher May 17 at 20:17
  • 2
    $\begingroup$ @HenrikSchumacher you still need a massive dose of MaxCellMeasure to make it pretty. $\endgroup$ – Roman May 17 at 20:24

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