1
$\begingroup$

I have the following code:

M := {{3, 0, 0}, {0, 2, 0}, {0, 0, 1}}
f[x_, y_, z_] := Cross[{x, y, z}, M*{x, y, z}]
ContourPlot3D[f[x, y, z] == {0, 0, 0}, {x, y, z} \[Element] Ball[{0, 0, 0}, 1]]

Which almost produces exactly what I want.enter image description here

The only issue is I am uninterested in the region inside the sphere, I only want the curves on the surface of the sphere created by this intersection. When I try the seemingly innocent replacement of Ball[{0, 0, 0}, 1] with Sphere[{0, 0, 0}, 1] Mathematica starts complaining about the dimension of this region. How can I achieve the desired result? I am using version 13.1

$\endgroup$
5
  • 1
    $\begingroup$ Do you mean something like the sphere in this image from this post? — I think you want a contour plot of the sphere and then color the surface according to f. However, Solve[f[x, y, z] == {0, 0, 0} && x^2 + y^2 + z^2 == 1] yields only a finite number of points, assuming f is supposed to be f[x_, y_, z_] := Cross[{x, y, z}, M . {x, y, z}] with . for matrix product instead of elementwise multiplication of *. To markup points, use Epilog with a small Sphere[] for each point. $\endgroup$
    – Michael E2
    Commented Aug 31, 2022 at 20:35
  • $\begingroup$ Yes, this is what I had in mind. I see, so my code is mistaken if it's producing a continuum of solutions? $\endgroup$ Commented Aug 31, 2022 at 20:43
  • 1
    $\begingroup$ I suppose it depends on what f[x, y, z] == {0, 0, 0} means to you. I interpreted it as a system of simultaneous equations. Your contour plot didn't finish quick enough, so I skipped thinking about. ContourPlot3D[] seems to treat the system as three separate equations; and on that basis, the plot is correct. But which interpretation did you want? $\endgroup$
    – Michael E2
    Commented Aug 31, 2022 at 20:53
  • $\begingroup$ Ah I see, OK so this was not what I wanted then. I suppose if I want to plot level sets of the problem in your other post I can try using ContourPlot3D to plot various different level sets of h[x_, y_, z_] := 0.5*({x, y, z} . (M . {x, y, z})) $\endgroup$ Commented Aug 31, 2022 at 20:57
  • $\begingroup$ This returns me to my original question ContourPlot3D[ h[x, y, z] == 0.7, {x, y, z} \[Element] Ball[{0, 0, 0}, 1]] works but Sphere does not. How can I overcome this? And is there a way to overlay several different level sets of $h$? $\endgroup$ Commented Aug 31, 2022 at 21:00

1 Answer 1

1
$\begingroup$

Maybe the two approachs.

Clear[M, f];
M = {{3, 0, 0}, {0, 2, 0}, {0, 0, 1}};
f[x_, y_, z_] = Cross[{x, y, z}, M . {x, y, z}];
ContourPlot3D[
 f[x, y, z] == {0, 0, 0}, {x, y, z} ∈ Ball[{0, 0, 0}, 1], 
 Mesh -> None, ContourStyle -> None, BoundaryStyle -> {Thick, Blue}]

enter image description here

Clear[M, f];
M = {{3, 0, 0}, {0, 2, 0}, {0, 0, 1}};
f[x_, y_, z_] = Cross[{x, y, z}, M . {x, y, z}];
ContourPlot3D[
 x^2 + y^2 + z^2 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
 MeshFunctions -> Evaluate[Function[{x, y, z}, #] & /@ f[x, y, z]], 
 Mesh -> {{0}}, MeshStyle -> Directive[Thick, Blue], 
 ContourStyle -> Opacity[.1], PlotPoints -> 80, MaxRecursion -> 4]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks. This is exactly what I want visually in terms of the appearance of the curves and sphere, but it seems I'm getting quite a different looking output when I run this code. Do you know why this may be? $\endgroup$ Commented Aug 31, 2022 at 22:37
  • $\begingroup$ @TheoDiamantakis Restart the Mathematica and test the code again maybe helpfull. Or use ClearAll etc. to Clare the variables. $\endgroup$
    – cvgmt
    Commented Aug 31, 2022 at 22:41
  • $\begingroup$ ClearAll was unsuccessful but restarting Mathematica did it. Thank you. It remains to be seen if this is really what I want (a level set of the 0 vector in R^3) or Mathematica is just solving each quadratic equation separately or correctly interpreting them as a nonlinear system, though the plot does look vaguely correct to me. You've answered the main part of my question for the visuals and using a sphere instead of ball so I'll accept the answer. Thanks $\endgroup$ Commented Aug 31, 2022 at 22:48

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.