Plotting Vector Fields in Mathematica

Copyright © 1997, 2001 by James F. Hurley, University of Connecticut, Department of Mathematics, Unit 3009, Storrs CT 06269-3009. All rights reserved.

     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} ]

[Graphics:HTMLFiles/VectFieldPlot_1.gif]

Out[2]=

Graphics TagBox[RowBox[List["\[SkeletonIndicator]", "Graphics", "\[SkeletonIndicator]"]], False, Rule[Editable, False]]

   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},
                  VectorHeads -> True]

[Graphics:HTMLFiles/VectFieldPlot_2.gif]

Out[4]=

Graphics3D TagBox[RowBox[List["\[SkeletonIndicator]", "Graphics3D", "\[SkeletonIndicator]"]], False, Rule[Editable, False]]

     
     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},
                     VectorHeads -> True]

[Graphics:HTMLFiles/VectFieldPlot_3.gif]

Out[6]=

Graphics3D TagBox[RowBox[List["\[SkeletonIndicator]", "Graphics3D", "\[SkeletonIndicator]"]], False, Rule[Editable, False]]


Converted by Mathematica  (June 19, 2003)