5

I'm looking to visualize slope fields of differential equations for my differential equations course. Every example I see draws them as vectors, adding unnecessary "arrows" that, to me, are visually distracting. Is there a way to plot these slope fields without the "arrows" that get in the way?

silvascientist
  • 389
  • 1
  • 13

2 Answers2

13

You can use the options VectorScale and VectorStyle of VectorPlot. To create the slope field for the first order equation $y'=f(x,y)$, I usually do something like so.

f = Exp[-x] - y;
VectorPlot[{1, f}, {x, -2, 2}, {y, -2, 2},
  VectorScale -> {0.03, Automatic, None},
  VectorStyle -> {Gray, Arrowheads[0]}]

enter image description here

Mark McClure
  • 32,469
  • 3
  • 103
  • 161
9

Yes, you can simply replace each occurrence of Arrow with Line like this:

VectorPlot[{y, -x}, {x, -3, 3}, {y, -3, 3}] /. Arrow -> Line

lines

To understand how this works, please read the documentation for ReplaceAll and also take a look at FullForm[VectorPlot[...]]. The point is to see that the plot is just a bunch of graphics directives and therefore we can modify it. Replacing Arrow with Line works because the argument is the same to both Arrow and Line.

You can also achieve it like this:

VectorPlot[{y, -x}, {x, -3, 3}, {y, -3, 3}, VectorStyle -> "Segment"]

Look at the documentation for VectorStyle and especially the part under "Details" to see the full set of options. As a beginner, this is the way to go, and I should probably have used it as well. But as you get more experienced sometimes you don't want to dig in the documentation so you do something quick and dirty like what I did above. It's often useful to be able to, so I'll let the other solution remain in my answer.

My example above was poor, it appears, since it's not a proper slope field. For that part of the question check out Mark McClure's answer.

C. E.
  • 70,533
  • 6
  • 140
  • 264