I am really baffled by this. Call to StreamPlot
does not return empty plot, nor an error message, nor a beep. It just return unevaluated.
I do not think I've seen something like this before. What would the cause for this?
Is this expected behavior?
Normally, when a plot can not be generated, either an error is returned or empty plot.
ClearAll[x, y, f];
f = (x*y - Sqrt[-1 + x^2 + y^2])/(-1 + x^2);
StreamPlot[{1, f}, {x, -2, 2}, {y, -2, 2}]
btw, it will plot OK when changing the -1
to 1
in the above, under the square root:
So it seems due to value of the function becomes complex over some region. But normally when this happens, an empty plot is returned, right?
V 12 on windows 10.
Answer
I think it should give an error message, perhaps. I agree with the OP's guess that problem stems from the complex values of the vector field. It may be that it's because the field is real around the boundaries and then becomes complex. Here is a workaround:
StreamPlot[
Evaluate[ConditionalExpression[#, # ∈ Reals] & /@ {1, f}],
{x, -2, 2}, {y, -2, 2}]
Update: Here is another that seems to be more robust. It zeros out the complex-valued parts, and zero vectors are not drawn nor lead to stream lines:
StreamPlot[Boole[f ∈ Reals] {1, f}, {x, -2, 2}, {y, -2, 2}]
Comments
Post a Comment