1
$\begingroup$

I need to print out the value of x, y, and z when h==0, g==0. Help please?

h = x^2 + y^2 + z^2 - 2; 
g = x^3 + y^2 - z^2;

ContourPlot3D[{h == 0, g == 0}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
  MeshFunctions -> {Function[{x, y, z, f}, h - g]},
  MeshStyle -> {{Thick, Blue}}, Mesh -> {{0}}, 
  ContourStyle ->  Directive[Orange, Opacity[0.5], Specularity[White, 30]]]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ The blue Pringle-shaped curve is when h==0 and g==0. Otherwise you could use Solve[{h == 0, g == 0}, {x, y, z}]. ?? $\endgroup$
    – Chris K
    Commented Nov 8, 2019 at 19:26
  • $\begingroup$ @ChrisK. I knew the blue curve is when h==0 and g==0, but in other word what arex,y values at z=0 point in the z-axis? $\endgroup$
    – user68340
    Commented Nov 8, 2019 at 20:16
  • $\begingroup$ The question in the comment is not the same as the question in the OP. Could you please edit the question in the OP? $\endgroup$
    – anderstood
    Commented Nov 9, 2019 at 8:55

1 Answer 1

3
$\begingroup$

Like Chris says in a comment, Solve can be used to find the values where h == 0 && g == 0, at least for two variables since we have two equations. You take as an example z = 0. For that case we have the following:

Solve[h == 0 && g == 0 /. z -> 0, {x, y}, Reals]

{{x -> -1, y -> -1}, {x -> -1, y -> 1}}

Here's a demonstration of finding the values for different z:

sols[zval_] := Append[zval] /@ Values@Solve[h == 0 && g == 0 /. z -> zval, {x, y}, Reals]

cp = ContourPlot3D[
   {h == 0, g == 0},
   {x, -2, 2}, {y, -2, 2}, {z, -2, 2}
   ];

pts = Flatten[Table[Quiet@sols[z], {z, -2, 2, 0.1}], 1];
Show[
 cp,
 Graphics3D[{
   Green, ,
   Sphere[pts, 0.2]
   }]
 ]

Mathematica graphics

$\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.