7
$\begingroup$

I am doing a StreamPlot and something seems wrong with the output.

  StreamPlot[{0, -(y - x)^3}, {x, -3, 3}, {y, -3, 3}]

The plot is attached and I highlighted the issue in red

enter image description here

Shouldn't the direction arrows be the other way around?

It is also odd that it appears to be crossing the critical points $y = x$.

Is this a bug?

I should also mention that I am using Windows 10 with MMA V 12.1.0.0.

$\endgroup$
  • 1
    $\begingroup$ with ` StreamPoints -> Fine` or ` StreamPoints -> Coarse` the issue does not arise. $\endgroup$ – kglr May 6 at 12:43
  • 1
    $\begingroup$ @MichaelE2 I am not surprised that the line crosses x==y, but I am surprised about the reversal of the arrows. That must be a bug, no ... ? $\endgroup$ – Szabolcs May 6 at 12:45
  • 1
    $\begingroup$ @Szabolcs That's what I realized right after I posted my comment. However, it could be numerical error if the first step across x == y went past the plot range...seems really unlikely, though. Streamplot uses a special NDSolve method. I don't know anything about it, but I expect it's designed to be quick. $\endgroup$ – Michael E2 May 6 at 12:59
  • 1
    $\begingroup$ I'm not giving you an reason for why StreamPlot is behaving like that. But If you are looking for the Similar plots then try this VectorPlot[{0, -(y - x)^3}, {x, -3, 3}, {y, -3, 3}, VectorScale -> {Automatic, Automatic, #}, PlotLabel -> HoldForm[#]] & /@ {None} $\endgroup$ – Gummala Navneeth May 6 at 13:36
5
$\begingroup$

A nice check of what StreamPlot does is the option Mesh->All:

StreamPlot[{0, -(y - x)^3}, {x, -3, 3}, {y, -3, 3}, Mesh -> All]

Graphics of StreamPlot with Mesh->All

With this overview, it is evident that the stream field is not so nice in this rectangle overall. It is free to select a better mesh by hand or a different region in which the stream is represented or deal closer to the problem.

The origin of the problem is not only the indifference along the diagonal. The stream is an overall ill condition since the first component is constant and zero.

The error in representation vanishes with the styling of the StreamPlot. Change the theme to Minimal and voila. It is much better in both with and without Mesh->All. In all other themes, the problems remain. This shows up another pass by of the problem, set PlotTheme -> "Minimal".

StreamPlot[{0, -(y - x)^3}, {x, -3, 3}, {y, -3, 3}, 
 PlotTheme -> "Minimal"]

Graphics PlotTheme->"Minimal"

This input with Mesh->All shows the difference:

StreamPlot[{0, -(y - x)^3}, {x, -3, 3}, {y, -3, 3}, 
 PlotTheme -> "Minimal", Mesh -> All]

Graphics output Mesh->all PlotTheme->"Minimal"

The mesh is much more coarse and avoids already internally the problem.

The line of indifference is now dealt much safer. The cells are greater and the problem of a possible reversal of the stream directions in the representation is avoided.

There are of course formulas available in the literature that deal with the problem. Since it is in practice very seldom that this occurs it is easier and cheaper to try Mathematica options. The method used by Mathematica is not known to me at present on how to generate the mesh. It is robust but needs gradient to get accurate. If that is not present the method fails and different things occur from reversal, nothing to singularities - everything is possible.

Since the example is a polynomial just brave phenomenons will occur. I leave this to personal curiosity. It is not an error of the method used by Mathematica. It should be discussed the fashion I do here exemplary.

One hint is to try the option VectorPoints on the example for more to wonder about. In the Details and Options section for StreamPlot are even more hidden wonders of stream plotting mathematics.

In the book of Abell and Braselton interpretation for this kind of question if the first component would be 1 not zero and how to make your own stream plot function plot in Mathematica. Historically stream plots were derived for special applications and with the invention of CAS this kind of use appeared.

| improve this answer | |
$\endgroup$
  • $\begingroup$ StreamPlot[{0, -(y - x)^3}, {x, -3, 3}, {y, -3, 3}, StreamPoints -> Fine, Mesh -> All] $\endgroup$ – Moo May 7 at 11:20

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.