Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to plot some flow lines for a certain vector field, but Mathematica doesn't seem to plot the entire flow line, only a small piece of it. How can I fix this?

VectorPlot[{Re[Sqrt[x + I y]], Im[Sqrt[x + I y]]}, 
{x, -1, 1}, 
{y, -1, 1}, 
VectorPoints -> Fine,  
StreamPoints -> Coarse, 
StreamStyle -> Red, 
StreamScale -> None]

enter image description here


I feel dumb for not realizing the discontinuity, but I'll mention that what I really want are flow lines of slope fields, not vector fields. I didn't see how to do this in Mathematica "directly," and hence used VectorPlot. How can I plot the lines of a slope field?

share|improve this question
It plots from -1 to 1 in each direction. What do you want it to do? – bill s Mar 27 '13 at 14:39
If you mean the discontinuity along the negative x-axis, it's because the vector field is discontinuous and changes direction. – Michael E2 Mar 27 '13 at 15:13
Chris, please register an account now so you can edit and manage your posts. – Szabolcs Mar 27 '13 at 15:29
Could you explain what a "slope field" is? Is it the same as a covector field (a one-form)? Or a section of the circle bundle associated with the tangent bundle? Or a section of that bundle with opposite directions identified at each point? – whuber Mar 27 '13 at 18:54
@whuber: The last option you mentioned, so there's no notion of forwards/backwards direction, just of tangency. – user62206 Mar 28 '13 at 17:38
up vote 4 down vote accepted

You could specify seed-points for streamlines directly using StreamPoints: only those stremlines will be plotted which pass through these points. Here I set up two point sets: one at $y = 1$ and another at $y = -1$. These share identical $x$ coordinates so they meet at the discontinuity at $y = 0$. One can control the streamline lenghts by the third argument to StremPoints (second argument controls the minimal distance between streamlines).

points = Join[{#, -1.} & /@ Range[-1, 1, .2], {#, 1.} & /@ Range[-1, 1, .2]];
VectorPlot[{Re[Sqrt[x + I y]], Im[Sqrt[x + I y]]}, {x, -1, 1}, {y, -1,
   1}, VectorPoints -> Fine, StreamPoints -> {points, Automatic, 2}, 
 StreamStyle -> Red, StreamScale -> None]

Mathematica graphics

Here is a small Manipulate interface to get a grip on how the streampoints are positioned and how length and distance can be controlled. Here a circular layout is used for the streamline-points to be able to capture some missing lines (thanks whuber!).

 points = Table[{Cos@t, Sin@t}*r, {t, 0., 2. \[Pi], d}];
 VectorPlot[{Re[Sqrt[x + I y]], Im[Sqrt[x + I y]]}, {x, -1, 
   1}, {y, -1, 1}, VectorPoints -> Fine, 
  StreamPoints -> {points, Automatic, l}, StreamStyle -> Red, 
  StreamScale -> None, 
  Epilog -> {Green, PointSize@Large, Point@points}],
 {{d, \[Pi]/20., "point spacing"}, 0, 1, \[Pi]/40, 
  Appearance -> "Labeled"},
 {{l, 2, "stream length"}, 0, 2, Appearance -> "Labeled"},
 {{r, 1, "radius"}, 0, 1, Appearance -> "Labeled"}

Mathematica graphics

share|improve this answer
+1 How would you cope with the streamlines for positive $x$--the ones that ought to converge at the origin but instead are terminated within a distance of about $0.1$ of it? – whuber Mar 27 '13 at 18:49
Thanks! This is exactly what I needed. – user62206 Mar 28 '13 at 18:58

For a slope field $dy/dx = f(y,x)$, I suppose you have to make do with something like a vector field of the form {1, f[x,y]} or Normalize@{1, f[x,y]}. We might as well normalize the vector, since magnitude doesn't matter in a slope field. Ordinarily, the value of the slope field at a point indicates the tangent line to an integral curve without regard to a direction of motion. I don't think Mathematica can represent that (or at least not conveniently). You have to use a vector.

In your case, it seems better to treat $x$ as a function of $y$ and for $dx/dy = g(x,y)$, use Normalize@{g[x,y], 1}, where g[x,y] is the quotient of the x and y components of your vector field:

 Evaluate@Normalize@{Re[Sqrt[x + I y]]/Im[Sqrt[x + I y]], 1},
 {x, -1, 1}, {y, -1, 1},
 VectorPoints -> Fine, StreamPoints -> Coarse, 
 StreamStyle -> Red, StreamScale -> None, 
 VectorStyle -> Arrowheads[0]]

Vector field plot

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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