1
$\begingroup$

I try this code to plot streamline

data = Table[{{x, y}, {-y, x}}, {x, -2, 2, 1/200}, {y, -2, 2, 1/200}];
ListStreamPlot[data, StreamStyle -> "Line", StreamPoints -> 4]

It returns enter image description here

Question: In the picture, the lines are not closed in the red circles.

So, how to get closed curves use parameters of ListStreamPlot? Thank you!

$\endgroup$
  • $\begingroup$ Might be hard to get to be done automatically, given that numerics usually won't give exactly closed curves, esp. with discrete data. -- I mean, with the discrete data, one has to assume how the vector field is to be estimated/interpolated. How do you know the resulting vector field has closed curves? Any perturbation of {-y, x} tends to destroy the closed curves. $\endgroup$ – Michael E2 May 31 '17 at 12:24
  • $\begingroup$ @MichaelE2, I know that the data I want to plot has closed streamline from its physical meaning, so I want to get closed curves within MMA. In my question, I just present an example. How to get closed curves with some additional process? Thank you! $\endgroup$ – tanghe2014 May 31 '17 at 13:16
  • $\begingroup$ A hack: ListStreamPlot[data, StreamStyle -> "Line", StreamPoints -> 4] /. Line[{a_, b__}] :> Line[{a, b, a}] but it doesn't look good for the reason Michael gives. $\endgroup$ – MikeLimaOscar May 31 '17 at 13:31
  • $\begingroup$ Can you estimate a potential function or some invariant for the field? You could use it to draw level curves, which would approximate the closed orbits. $\endgroup$ – Michael E2 May 31 '17 at 16:17
  • $\begingroup$ @MichaelE2, I cannot get potential function. I only have velocity vectors. $\endgroup$ – tanghe2014 Jun 2 '17 at 2:59
2
$\begingroup$

Here's what I had in mind for estimating a potential function:

grad = MapAt[{-#[[2]], #[[1]]} &, data, {All, All, 2}];
pot = Accumulate@grad[[All, All, 2, 1]] + Accumulate /@ grad[[All, All, 2, 2]];

ListContourPlot[pot, DataRange -> {{-2., 2.}, {-2., 2.}}]

Mathematica graphics

The potential function could be multiplied by Δx Δy, but there's no real need to do it for the plot.

|improve this answer|||||
$\endgroup$
1
$\begingroup$
ListStreamPlot[data, StreamStyle -> "Line", StreamPoints -> 4] /. 
 Line -> (BSplineCurve[#, SplineClosed -> True] &)

Mathematica graphics

|improve this answer|||||
$\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.