# Plotting vector valued level set over a sphere (instead of a ball)

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.

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

• 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. Commented Aug 31, 2022 at 20:35
• Yes, this is what I had in mind. I see, so my code is mistaken if it's producing a continuum of solutions? Commented Aug 31, 2022 at 20:43
• 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? Commented Aug 31, 2022 at 20:53
• 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})) Commented Aug 31, 2022 at 20:57
• 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$? Commented Aug 31, 2022 at 21:00

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}]


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]


• 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? Commented Aug 31, 2022 at 22:37
• @TheoDiamantakis Restart the Mathematica and test the code again maybe helpfull. Or use ClearAll etc. to Clare the variables. Commented Aug 31, 2022 at 22:41
• 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 Commented Aug 31, 2022 at 22:48