FYI, reported to WRI [CASE:4288967]
By mistake, I put x range starting from negative to make StreamPlot
for expression with Log[x]
in it.
But should this cause the kernel to die? I am Ok with an empty plot. When using ParametricPlot
it gives back empty plot, and kernel stays up.
Is this behavior expected or is this a bug?
Is it possible to catch the error instead of kernel crash?
For other reasons, I want to keep same range, since this is running inside script over hundreds of different cases, and do not want to change the x-range for each case. But can live with empty plot and an error I can catch instead.
ClearAll[x, y];
fTerm = (y (1 + 3 x y^3 Log[x]))/(3 x);
StreamPlot[{1, fTerm}, {x, -2, 2}, {y, -2, 2}]
Kernel dies. But
ClearAll[x, y];
fTerm = (y (1 + 3 x y^3 Log[x]))/(3 x);
ParametricPlot[fTerm, {x, -2, 2}, {y, -2, 2}]
Empty plot. Kernel remains Up.
This is on V12, windows 10.
update I found another example of where kernel crash. This is due to 1/0 (I think). The problem I get no error message printed or anything. Just one loud beep and that is it. This makes it very hard to run the script, since I have to restart the kernel it each time and manually skip the case that caused the crash.
ClearAll[x, y];
fTerm = -((1 - 3*x^6*y^3)/(3*x^7*y^2)) - (2^(1/3)*(-1 + 6*x^6*y^3))/(3*x^7*y^2*(-2 + 18*x^6*y^3 - 27*x^12*y^6 + 3*Sqrt[3]*Sqrt[-4*x^18*y^9 + 27*x^24*y^12])^(1/3)) + (-2 + 18*x^6*y^3 - 27*x^12*y^6 + 3*Sqrt[3]*Sqrt[-4*x^18*y^9 + 27*x^24*y^12])^(1/3)/(3*2^(1/3)*x^7*y^2);
StreamPlot[{1, fTerm}, {x, -2, 2}, {y, -2, 2}]
I could not catch the error. Adding Catch
around it has no effect. Kernel just crashed.
Answer
The tricks used here also solve this problem. The first seems more robust and does not need StreamPoints
to be specified:
StreamPlot[Boole[fTerm ∈ Reals] {1, fTerm}, {x, -2, 2}, {y, -2, 2}]
StreamPlot[{1, ConditionalExpression[#, # ∈ Reals] &@fTerm},
{x, -2, 2}, {y, -2, 2},
StreamPoints -> {{
{{-1.8, 0.4}, Automatic}, {{-0.6, 1.8}, Automatic},
{{ 1.8, 0.4}, Automatic}, {{ 0.6, 1.8}, Automatic}, Automatic}}]
[Second plot (the original answer) omitted as it is pretty similar. See edit history if curious.]
Comments
Post a Comment