I am trying to plot the following simple vector field
$$\sqrt{4-x^2-y^2-z^2}*(y,-x,0)$$
but when I plug this field into the functions VectorPlot
and VectorPlot3D
, the output graph is completely blank. The MWE im using is
ClearAll[expr]
expr[x_, y_, z_] :=
N@Piecewise[{{Sqrt[4 - (x^2 + y^2 + z^2)] {y, -x, 0},
4 > (x^2 + y^2 + z^2)}}, {0, 0, 0}]
VectorPlot[expr[x, y, 0], {x, -4, 4}, {y, -4, 4}]
VectorPlot3D[
Evaluate@expr[x, y, z], {x, -5, 5}, {y, -5, 5}, {z, -2, 2},
VectorPoints -> Fine]
with output:
which is no good :(.
I tried defining my vector field using the ConditionalExpression
function:
ClearAll[expr]
field = Sqrt[4 - (x^2 + y^2 + z^2)] {y, -x, 0}
expr[a_, b_, c_] :=
ConditionalExpression[field, Im[field] == {0, 0, 0}] /. {x -> a,
y -> b, z -> c}
expr[4, 4, 4]
VectorPlot3D[expr[x, y, z], {x, -5, 5}, {y, -5, 5}, {z, -2, 2},
VectorPoints -> Fine]
Now, this actually produces something, but its largely nonsense (even though it contains what Im looking for):
Undefined
I entered expr[4,4,4]
to verify it returns undefined, as it should. However, VectorPlot3D
is still plotting something. I don't even know what it could be plotting in the area where it should be empty.
Perhaps Mathematica is doing something strange and somehow evaluating the imaginary part and then plotting it? I really don't know.
I appreciate any help!