4
$\begingroup$

I am attempting to make a parametric stream plot of a dynamical system that is seeded along a line of points. For some reason, Mathematica inconsistently seeds at these points and will actually sometimes seed the wrong points (as shown below).

Is this a Mathematica issue, or is there a problem with my code?

enter image description here

I've visualized the seeding points as well in the StreamPlot to show the points appear to be defined correctly. Toggling the parameter makes the arrows coming from the other points appear and disappear inconsistently. The problem is also not unique to a specific dynamical system.

My code:

xpoints = ConstantArray[-2, 11];
ypoints = Range[-2, 2, 0.4];
points = Transpose[{xpoints, ypoints}]
Manipulate[
  StreamPlot[{y, -a x^3}, {x, -3, 3}, {y, -3, 3}, 
    StreamPoints -> points, Epilog -> Point[points]], 
  {a, 0, 1}]
$\endgroup$
2
  • 2
    $\begingroup$ It sometimes removes stream lines if they get too close to one another. It does this automatically, which can make it very hard to use it to produce exactly what you want. Having to a pretty good job at illustrating a phase portrait is fairly easy, though. You can use NDSolve directly to create the stream lines, though. $\endgroup$
    – Michael E2
    Commented Mar 1, 2019 at 2:44
  • $\begingroup$ Manipulate[ StreamPlot[{y, -a*x^3}, {x, -3, 3}, {y, -3, 3}, StreamPoints -> {points, 0.001}, Epilog -> Point[points]], {a, 0, 1}] eventually leads to a kernel crash, after clicking the dialog buttons to abort and to disable dynamic updating. $\endgroup$
    – Michael E2
    Commented Mar 1, 2019 at 11:49

1 Answer 1

3
$\begingroup$

I don't think there's any problem with your code, not do I think you found a bug. What I think is happening is that StreamPlot is making some automatic choices because you didn't give a complete specification for StreamPoints and you are unhappy with those choices,

First, let's look a slightly modified version of you code that shows what value of a appears to go wrong.

xpoints = ConstantArray[-2, 11];
ypoints = Range[-2, 2, .4];
points = Transpose[{xpoints, ypoints}];

Manipulate[
  StreamPlot[{y, -a x^3}, {x, -3, 3}, {y, -3, 3}, 
    StreamPoints -> points,
    Epilog -> {Red, AbsolutePointSize[5], Point[points]}],
  {a, 0, 1, .02, Appearance -> "Labeled"}]

demo1

The plot you show in your question shows up at a = 0.28. Now, let's look at the same plot with a full specification for StreamPoints.

Manipulate[
  StreamPlot[{y, -a x^3}, {x, -3, 3}, {y, -3, 3}, 
    StreamPoints -> {points, Automatic, Scaled[b]},
    Epilog -> {Red, AbsolutePointSize[5], Point[points]}],
  {{a, .28}, 0, 1, .02, Appearance -> "Labeled"},
  {{b, 2}, 0, 5, .1, Appearance -> "Labeled"}]

demo2

The problem has been corrected.

$\endgroup$
2
  • 1
    $\begingroup$ Still a bit disappointing that the length has to be adjusted manually and the stream lines go around more than once so that the arrows overlap. $\endgroup$
    – Michael E2
    Commented Mar 1, 2019 at 11:43
  • $\begingroup$ @MichaelE2. I agree, but it's the best I have been able to do given the choices that WRI has made in their implementation the StreamPoints option. My guess is that the implementors weren't thinking about the use case this question illustrates. $\endgroup$
    – m_goldberg
    Commented Mar 1, 2019 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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