7
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ "should this cause the kernel to die?"? No, the kernel should die only if instructed to do so, any other crash is a bug. I can reproduce the crash bug in Mathematica 11.3 and 12 on Windows 7 64 . I have highlighted the part of your question that is not off-topic. How to catch the error before it causes a crash seems and interesting question to me. $\endgroup$ – rhermans Aug 9 at 9:57
  • 2
    $\begingroup$ Same behavior in v9.0.1 and v8.0.4. $\endgroup$ – xzczd Aug 9 at 10:52
  • 2
    $\begingroup$ I get no crash with {x, -0.89, 2} but a crash with -0.895. Starting at -0.893 caused the FE to hang. Killing the kernel freed up the FE. (Mac, V12.0) $\endgroup$ – Michael E2 Aug 9 at 12:32
  • $\begingroup$ Have you reported this to Wolfram Support? Do they acknowledge the bug? Can we reproduce this bug on MacOS or Linux? $\endgroup$ – rhermans Aug 11 at 9:59
  • $\begingroup$ Perhaps this is better?: StreamPlot[ Boole[Chop@fTerm \[Element] Reals] {1, Re@fTerm}, {x, -2, 2}, {y, -2, 2}] -- it seems the imaginary parts cancel but Boole[0.0234375 + 0. I \[Element] Reals] does not evaluate to a number, for instance. There also seem to be some numerics issues near the y-axis, but adding WorkingPrecision causes a Throw[]. $\endgroup$ – Michael E2 Aug 13 at 13:44
3
$\begingroup$

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

enter image description here

[Second plot (the original answer) omitted as it is pretty similar. See edit history if curious.]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.