Vector Fields and Gradient Vector Fields

Mathematica needs the following package to be able to plot vector fields.

Needs["VectorFieldPlots`"]

Vector fields in (ℝ^2)

field=VectorFieldPlot[{-y,x},{x,-5,5},{y,-5,5}]

The length of the arrow represents the strength of the vector field. If we normalize the vector field, the lengths will all be 1:

field=VectorFieldPlot[(1/(Sqrt[(x^2)+(y^2)])){-y,x},{x,-5,5},{y,-5,5}]

The above direction field is not defined at the origin.

field=VectorFieldPlot[{y,Sin[x]},{x,-6,6},{y,-6,6}]

field=VectorFieldPlot[{Log[1+(y^2)],Log[1+(x^2)]},{x,-5,5},{y,-5,5}]

Vector fields are what you are looking at when you construct Direction Fields in solving differential equations.

Gradient field in (ℝ^2)

The gradient field of a differentiable function f is given by ∇ f.

f[x_,y_]=Log[(x^2)+(y^2)+1]
gradfieldf[x_,y_]={D[f[x,y],x],D[f[x,y],y]}
field=VectorFieldPlot[gradfieldf[x,y],{x,-5,5},{y,-5,5}]

f[x_,y_]=Exp[-(x^2)]Cos[x+y]
gradfieldf[x_,y_]={D[f[x,y],x],D[f[x,y],y]}
field=VectorFieldPlot[gradfieldf[x,y],{x,-5,5},{y,-5,5}]

Vector fields in (ℝ^3)

field=VectorFieldPlot3D[(({-x,y,-z})/(1+((((x^2)+(y^2)+(z^2)))^(3/2)))),{x,-1,1},{y,-1,1},{z,-1,1},PlotPoints->5,VectorHeads->True]

field=VectorFieldPlot3D[{x,y,z},{x,-2,2},{y,-2,2},{z,-2,2},PlotPoints->5,VectorHeads->True]

field=VectorFieldPlot3D[{0,0,z},{x,-2,2},{y,-2,2},{z,-2,2},PlotPoints->5,VectorHeads->True]

Here is an example of a gradient vector field, and the contour plot of the function. Notice how the gradient vector field is orthogonal to the contour plot. Also, notice that the gradient vector field has arrows which are longest where the lines of the contour plot are closest together. That is because this is where the function is changing most rapidly.

f[x_,y_]=(x^2) y-(y^3)
field=GradientFieldPlot[f[x,y],{x,-6,6},{y,-6,6}]
contour=ContourPlot[f[x,y],{x,-6,6},{y,-6,6},PlotPoints->30]
Show[contour,field]

Gradient field in (ℝ^3)

The gradient field of a differentiable function f is given by ∇ f.

f[x_,y_,z_]=Sqrt[(x^2)+(y^2)+(z^2)]
gradfieldf[x_,y_,z_]={D[f[x,y,z],x],D[f[x,y,z],y],D[f[x,y,z],z]}
field=VectorFieldPlot3D[gradfieldf[x,y,z],{x,-5,5},{y,-5,5},{z,-5,5},VectorHeads->True]

f[x_,y_,z_]=Exp[z]-Log[(x^2)+(y^2)+1]
gradfieldf[x_,y_,z_]={D[f[x,y,z],x],D[f[x,y,z],y],D[f[x,y,z],z]}
field=VectorFieldPlot3D[gradfieldf[x,y,z],{x,-5,5},{y,-5,5},{z,-5,5},VectorHeads->True]