Vector fields in Mathematica
D. McClendon

To define a vector field on (ℝ^2), use the usual type of syntax with underscores:

f[x_,y_] = {x+y,x-2y}

A table of values for this vector field can be obtained as follows (for example, the first output shows that f(-2,-2) = (-4,2)):

Table[{x,y,f[x,y]}, {x,-2,2},{y,-2,2}] // TableForm

Pictures of vector fields

To produce a picture of a vector field, use the VectorPlot command.  This command plots the vector field f(x,y) = (x+y, x-2y) where the  “{x, -3, 3}” and “{y, -3, 3}” tell Mathematica to produce a picture that runs from x = -3 to x = 3 and y = -3 to y = 3, i.e. it specifies the range of the picture.

f[x_,y_] = {x+y,x-2y};
VectorPlot[f[x,y], {x,-3,3},{y,-3,3}]

You can add some bells and whistles to the VectorPlot command as shown below:
 - The “VectorPoints -> 30” tells Mathematica how many vectors to draw.  If you change 30 to a larger number, you get more densely drawn arrows.   This produces a more accurate picture of the vector field, but the program will take longer to run.  On the other hand, if you change 30 to a smaller (positive) number, less arrows will be drawn, resulting in a less dense picture.
  - The “Axes -> True” tells Mathematica to draw the x- and y- axes on the picture.
  - The “VectorScale -> {Automatic, Automatic, None}” tells Mathematica to make sure all the vectors are scaled so that you can see them (without this command many of the vectors drawn would be too small to see) and so that they are all the same length.
  - The “VectorStyle -> Orange” tells Mathematica to make the vectors orange.  An interesting thing to do is to replace this command with “VectorColorFunction -> Hue” to get a ‘tie-dye’ looking picture.

f[x_,y_] = {x+y,x-2y};
VectorPlot[f[x,y],{x,-3,3},{y,-3,3}, 
VectorPoints -> 30, 
Axes -> True, 
VectorScale->{Automatic,Automatic,None}, 
VectorStyle -> Orange]

Graphing flow lines

To sketch flow lines on top of a vector field, add the commands indicated below.  The “StreamPoints -> 35” command tells Mathematica to sketch 35 flow lines, through randomly chosen points.    The “StreamScale-> Full” command ensures that the flow lines are connected when they should be (so that you get a much better picture).  The last bit tells Mathematica what color to make the stream lines and to make them thick.

f[x_,y_] = {x+y,x-2y};
VectorPlot[f[x,y],{x,-3,3},{y,-3,3},
 VectorPoints -> 30, Axes -> True,
 VectorScale->{Automatic,Automatic,None}, 
VectorStyle -> Orange, 
StreamPoints ->35, 
StreamScale -> Full, 
StreamStyle -> {Black, Thick}]

Graphing flow lines through particular points

Suppose you wanted to draw one flow line that went through one specified point.  In this case, you modify the above command by changing the StreamPoints directive from 35 to “{{a,b}}” where you want to draw the stream line through the point (a, b).  For example, in the above picture, if you wanted the stream line passing through the point (-1, 2), your command would be :

f[x_,y_] = {x+y,x-2y};
VectorPlot[f[x,y],{x,-3,3},{y,-3,3},
 VectorPoints -> 30, Axes -> True,
 VectorScale->{Automatic,Automatic,None}, 
VectorStyle -> Orange, 
StreamPoints ->{{-1,2}}, 
StreamScale -> Full, 
StreamStyle -> {Thick, Blue}]