22. Vector fields

📖 Reading · 10 min
💡 Every code box below is live — edit it and hit Run.

Every function studied so far has produced a single number (or, in Module 9, a vector depending on a single parameter t). A vector field produces a vector at every point of the plane or of space — one arrow, with its own direction and magnitude, attached to each location. This module's entire toolkit — line integrals, Green's theorem, curl, divergence, Stokes' theorem — is built on top of this one new object.

Definition

A vector field on the plane assigns a vector to each point (x,y):

\vec F(x,y)=\langle P(x,y),Q(x,y)\rangle

— two ordinary scalar functions, P and Q, bundled into components, the same construction as §9.4's vector-valued function, except the input is now a point (x,y) rather than a single parameter t. In space, a vector field has three components: \vec F(x,y,z)=\langle P,Q,R\rangle.

Physical readings: a vector field can represent the velocity of a fluid at every point (a velocity field), the force exerted by gravity or an electric charge at every point (a force field), or the direction and rate of steepest increase of some quantity (a gradient field — see below). The same mathematical object, three very different physical stories.

Visualizing a vector field

Plot a short arrow at a grid of sample points, each pointing in the direction of \vec F at that point, scaled (or not) by its magnitude. Some recognizable patterns:

  • \vec F(x,y)=\langle x,y\rangle: every arrow points directly away from the origin, growing longer farther out — a field that looks like something expanding or radiating outward.
  • \vec F(x,y)=\langle-y,x\rangle: every arrow is perpendicular to the position vector \langle x,y\rangle (check: their dot product is -xy+xy=0), pointing counterclockwise — a rotational field, the kind that appears around a whirlpool or a spinning object.
  • \vec F(x,y)=\langle1,0\rangle: every arrow is identical, pointing purely in the x-direction — a constant field, like a uniform wind.

Gradient fields

§10.5's gradient, \nabla f=\langle f_x,f_y\rangle, is itself a vector field — built directly from a scalar function f rather than specified independently. A vector field \vec F that arises this way, $\vec F=\nabla f$ for some scalar f, is called a gradient field, and f is called its potential function.

Not every vector field is a gradient field. This distinction turns out to matter enormously — §12.3 shows that gradient fields (also called conservative fields) have a special, highly useful property that general vector fields lack: the work done moving through them depends only on start and end points, never on the path taken between them. Recognizing whether a given \vec F is a gradient field, and if so, finding its potential f, is exactly what §12.3 builds toward.

Doing it in Python

Evaluating a rotational vector field at several sample points, and confirming it's always perpendicular to the position vector:

import sympy as sp

x, y = sp.symbols('x y')
F = sp.Matrix([-y, x])

points = [(1, 0), (0, 1), (1, 1), (2, -1)]
for px, py in points:
    Fp = F.subs({x: px, y: py})
    position = sp.Matrix([px, py])
    perpendicularity = Fp.dot(position)
    print(f"F({px},{py}) = {Fp.T}, F . position = {perpendicularity}")

Confirming a specific vector field is a gradient field, by finding a potential function through inspection and checking it directly:

import sympy as sp

x, y = sp.symbols('x y')
P, Q = 2*x, 2*y   # candidate F = <2x, 2y>

f = x**2 + y**2   # a guessed potential
grad_f = sp.Matrix([sp.diff(f, x), sp.diff(f, y)])

print(f"grad f = {grad_f.T}")
print(f"matches <P,Q> = <{P}, {Q}>: {grad_f == sp.Matrix([P, Q])}")

Sampling a vector field on a small grid, the computational version of sketching arrows by hand:

def F(x, y):
    return (x, -y)   # a "saddle" flow: expands along x, contracts along y

print(f"{'(x,y)':>10} {'F(x,y)':>14}")
for x in (-1, 0, 1):
    for y in (-1, 0, 1):
        print(f"({x:>2},{y:>2})    {F(x, y)}")

Worked example

Determine whether \vec F(x,y)=\langle2xy,x^2\rangle is a gradient field, and if so, find its potential function.

If \vec F=\nabla f, then f_x=2xy and f_y=x^2. Integrate the first equation with respect to x (treating y as constant, §10.2):

f(x,y)=\int2xy\,dx=x^2y+g(y)

for some unknown function g(y) (the "constant" of integration can depend on y, since it was held fixed during this integration). Differentiate this candidate with respect to y and match against the required f_y=x^2:

f_y=x^2+g'(y)\overset!=x^2\ \Longrightarrow\ g'(y)=0\ \Longrightarrow\ g(y)=C

\boxed{f(x,y)=x^2y+C\text{ is a valid potential function}}

Sanity check. Differentiate f=x^2y directly: f_x=2xy ✓, f_y=x^2 ✓ — both match \vec F's components exactly. This confirms \vec F genuinely is a gradient field (not every vector field would have allowed the two integration results to agree so cleanly — if g'(y) had come out depending on x, that would signal \vec F is not a gradient field at all, an outcome §12.3 examines directly).

Your turn

1. Evaluate the vector field \vec F(x,y)=\langle y,-x\rangle at the points (1,0), (0,1), and (1,1), and describe the rotational direction (clockwise or counterclockwise) it represents.

2. Verify that f(x,y)=x^3y^2 is a potential function for \vec F(x,y)=\langle3x^2y^2,2x^3y\rangle.

3. True or false: a constant vector field, like \vec F(x,y)=\langle3,4\rangle everywhere, is a gradient field.

Solutions

1. \vec F(1,0)=\langle0,-1\rangle (pointing straight down), \vec F(0,1)=\langle1,0\rangle (pointing right), \vec F(1,1)=\langle1,-1\rangle. Tracing these arrows around the origin — down at the rightmost point, right at the topmost point — traces a clockwise rotation, the opposite sense from \langle-y,x\rangle in the concept section.

2. f_x=3x^2y^2 — matches the first component. f_y=2x^3y — matches the second component exactly.

\boxed{\text{confirmed: }f(x,y)=x^3y^2\text{ is a valid potential}}

3. True. Take f(x,y)=3x+4y: \nabla f=\langle3,4\rangle — a constant gradient field is nothing more than the gradient of a linear function, exactly the way a constant single-variable derivative f'(x)=c comes from a linear function f(x)=cx (§2.0). Every constant vector field is a gradient field, with a linear potential function.

Check yourself in code

Evaluate the vector field \vec F(x,y)=\langle-y,x\rangle at the points (1,0), (0,1), (1,1), and (2,-1).

Print exactly this:

F(1,0) = [0, 1]
F(0,1) = [-1, 0]
F(1,1) = [-1, 1]
F(2,-1) = [1, 2]
import sympy as sp

x, y = sp.symbols('x y')
F = sp.Matrix([-y, x])

points = [(1, 0), (0, 1), (1, 1), (2, -1)]
for px, py in points:
    Fp = F.subs({x: px, y: py})
    print(f"F({px},{py}) = ...")
import sympy as sp

x, y = sp.symbols('x y')
F = sp.Matrix([-y, x])

points = [(1, 0), (0, 1), (1, 1), (2, -1)]
for px, py in points:
    Fp = F.subs({x: px, y: py})
    print(f"F({px},{py}) = {list(Fp)}")

A vector field \vec F(x,y)=\langle P,Q\rangle attaches a vector to every point rather than to every parameter value, and can represent fluid velocity, force, or — as a gradient field \vec F=\nabla f — the direction of steepest ascent from §10.5, now viewed as a field spanning the whole domain rather than a single vector at one point. Whether a given field is a gradient field, discoverable by attempting to integrate its components back into a single potential function f, is the thread §12.3 pulls on directly.

Next: integrating a scalar function along a curve, weighted by arc length — the first of this module's new integral types, and a direct extension of §9.5's arc-length formula.