Mathematica has built-in commands for plotting 2-and 3-dimensional vector fields. To use them, first call up the Graphics package PlotField or Plotfield3D. The following routine illustrates that process. Execute it to produce a plot of the two-dimensional vector field F with formula F(x, y) = P(x, y) i + Q(x, y) j for P(x, y) = - y/2 and Q(x, y) = x/2. (As usual, you execute the routine by placing your cursor after the last line and pressing Enter or Shift-Return.)

In[1]:=

Needs["Graphics`PlotField`"]
PlotVectorField[ {-y/2, x/2}, {x, -5, 5}, {y, -5, 5}, Axes -> True,
ColorFunction -> Hue, AxesLabel -> {x, y} ]

Out[2]=

$⁃\mathrm{Graphics}⁃$

The next routine illustrates use of the Plotfield3D package for the three-dimensional vector field F with formula F(x, y, z) = y i + z j + x k. Try it!

In[3]:=

Needs["Graphics`PlotField3D`"]
PlotVectorField3D[{y, z, x}, {x, -2, 2}, {y, -2, 2},
{z, -2, 2}, Axes -> True, ColorFunction -> Hue,
PlotPoints -> 5, AxesLabel -> {x, y, z},

Out[4]=

$⁃\mathrm{Graphics3D}⁃$

Mathematica
also has a built-in command to plot the gradient field f of a scalar function f of two or three real variables. The next routine illustrates that for the gradient field of the scalar length function l that maps 3-dimensional vectors x to their length ||x||. You can experiment with the options by removing the call to add arrowheads at the ends of each vector. (Note: Mathematica issues many error messages about division by 0, but still will produce a figure for most fields like this.)

In[5]:=

Needs["Graphics`PlotField3D`"]
PlotGradientField3D[ Sqrt[x^2 + y^2 + z^2],{x, -2, 2}, {y, -2, 2},
{z, -2, 2}, Axes -> True, ColorFunction->Hue,
PlotPoints -> 5, AxesLabel -> {x, y, z},
$⁃\mathrm{Graphics3D}⁃$