TExcelTAD
Home › Calculus Essentials › Vector Fields and Line Integrals

Vector Fields and Line Integrals

A vector field attaches an arrow to every point: wind velocity on a weather map, the force of gravity around a planet, the flow direction in a crowd simulation. A line integral adds up a quantity along a curve, and its most important use is the work a force field does on an object that moves along a path.

Vector fields

A vector field in the plane is a function F(x,y)=⟨P(x,y),Q(x,y)⟩\mathbf{F}(x, y) = \langle P(x, y), Q(x, y) \rangle that returns a vector at each point (in 3D, ⟨P,Q,R⟩\langle P, Q, R \rangle).

Field Picture
F=⟨1,0⟩\mathbf{F} = \langle 1, 0 \rangle uniform wind blowing east
F=⟨x,y⟩\mathbf{F} = \langle x, y \rangle arrows pointing straight out from the origin, longer farther out
F=⟨−y,x⟩\mathbf{F} = \langle -y, x \rangle arrows circling the origin counter-clockwise (a vortex)
F=−⟨x,y⟩/∥⟨x,y⟩∥3\mathbf{F} = -\langle x, y \rangle / \lVert \langle x, y \rangle \rVert^3 inverse-square attraction to the origin (gravity)
F=∇f\mathbf{F} = \nabla f a gradient field: arrows point uphill on ff
python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

X, Y = np.meshgrid(np.linspace(-2, 2, 15), np.linspace(-2, 2, 15))
fig, axes = plt.subplots(1, 2, figsize=(8, 4))
axes[0].quiver(X, Y, X, Y, color="tab:blue")
axes[0].set_title("F = ⟨x, y⟩ (source)")
axes[1].quiver(X, Y, -Y, X, color="tab:red")
axes[1].set_title("F = ⟨−y, x⟩ (vortex)")
for ax in axes:
    ax.set_aspect("equal")
print("F = <-y, x> at (1, 0):", (-0, 1), " at (0, 1):", (-1, 0))
F = <-y, x> at (1, 0): (0, 1)  at (0, 1): (-1, 0)

Line integrals of a scalar function

For a curve CC traced by r(t)\mathbf{r}(t), a≤t≤ba \le t \le b, and a scalar function ff (say, the density of a wire), the line integral with respect to arc length is

∫Cf ds=∫abf(r(t))⋅∥r′(t)∥ dt\int_C f \, ds = \int_a^b f(\mathbf{r}(t)) \cdot \lVert \mathbf{r}'(t) \rVert \, dt

With f=1f = 1 it is the length of CC, the arc length formula. With f=linear densityf = \text{linear density} it is the mass of a wire shaped like CC.

Work: the line integral of a vector field

A constant force F\mathbf{F} moving an object along a straight displacement d\mathbf{d} does work W=F⋅dW = \mathbf{F} \cdot \mathbf{d} (only the component along the motion counts, as in the dot product). For a varying force along a curve, add up F⋅dr\mathbf{F} \cdot d\mathbf{r} over tiny steps:

W=∫CF⋅dr=∫abF(r(t))⋅r′(t) dtW = \int_C \mathbf{F} \cdot d\mathbf{r} = \int_a^b \mathbf{F}(\mathbf{r}(t)) \cdot \mathbf{r}'(t) \, dt

This also covers circulation (work around a closed loop, written ∮CF⋅dr\oint_C \mathbf{F} \cdot d\mathbf{r}). Reversing the direction of the curve flips the sign.

Example. F=⟨−y,x⟩\mathbf{F} = \langle -y, x \rangle around the unit circle r(t)=⟨cos⁡t,sin⁡t⟩\mathbf{r}(t) = \langle \cos t, \sin t \rangle, 0≤t≤2π0 \le t \le 2\pi:

F(r(t))=⟨−sin⁡t,cos⁡t⟩,r′(t)=⟨−sin⁡t,cos⁡t⟩F⋅r′=sin⁡2t+cos⁡2t=1→W=∫02π1 dt=2π\begin{aligned} &\mathbf{F}(\mathbf{r}(t)) = \langle -\sin t, \cos t \rangle, \qquad \mathbf{r}'(t) = \langle -\sin t, \cos t \rangle \\ &\mathbf{F} \cdot \mathbf{r}' = \sin^2 t + \cos^2 t = 1 \quad\to\quad W = \int_0^{2\pi} 1 \, dt = 2\pi \end{aligned}

The vortex pushes the object along the whole way round, so the work is positive.

python · try it yourself
import numpy as np

def work(F, r, dr, a, b, n=100_000):
    t = np.linspace(a, b, n + 1)
    tm = (t[:-1] + t[1:]) / 2                     # midpoint rule
    integrand = np.sum(F(*r(tm)) * dr(tm), axis=0)
    return float(np.sum(integrand) * (b - a) / n)

vortex = lambda x, y: np.array([-y, x])
source = lambda x, y: np.array([x, y])
circle = lambda t: (np.cos(t), np.sin(t))
dcircle = lambda t: np.array([-np.sin(t), np.cos(t)])

print("vortex around circle:", round(work(vortex, circle, dcircle, 0, 2 * np.pi), 6), " (2π =", round(2 * np.pi, 6), ")")
print("source around circle:", round(work(source, circle, dcircle, 0, 2 * np.pi), 6))
vortex around circle: 6.283185  (2π = 6.283185 )
source around circle: 0.0

The source field points straight out, perpendicular to the circle at every point, so it does no work.

Conservative fields and path independence

A field is conservative if it is a gradient, F=∇φ\mathbf{F} = \nabla\varphi, for some potential φ\varphi. Then the chain rule gives F(r(t))⋅r′(t)=ddtφ(r(t))\mathbf{F}(\mathbf{r}(t)) \cdot \mathbf{r}'(t) = \frac{d}{dt} \varphi(\mathbf{r}(t)), and the line integral collapses, like the Fundamental Theorem:

∫C∇φ⋅dr=φ(end)−φ(start)\int_C \nabla\varphi \cdot d\mathbf{r} = \varphi(\text{end}) - \varphi(\text{start})

So in a conservative field the work depends only on the endpoints, not on the path, and around every closed loop it is zero. Gravity and spring forces are conservative, which is why potential energy makes sense for them. Friction is not.

Test (2D, on a region without holes): F=⟨P,Q⟩\mathbf{F} = \langle P, Q \rangle is conservative exactly when ∂P/∂y=∂Q/∂x\partial P/\partial y = \partial Q/\partial x. For the vortex, ∂P/∂y=−1\partial P/\partial y = -1 but ∂Q/∂x=1\partial Q/\partial x = 1, so it is not conservative, matching its non-zero circulation.

python · try it yourself
import numpy as np

F = lambda x, y: np.array([2 * x * y, x**2 + 3 * y**2])     # = grad of phi = x^2 y + y^3
phi = lambda x, y: x**2 * y + y**3

def work(r, dr, n=200_000):
    t = (np.arange(n) + 0.5) / n                            # midpoints of [0, 1]
    return float(np.sum(np.sum(F(*r(t)) * dr(t), axis=0)) / n)

straight = (lambda t: (2 * t, t), lambda t: np.array([2 + 0 * t, 1 + 0 * t]))
wiggly = (lambda t: (2 * t, t + np.sin(np.pi * t)), lambda t: np.array([2 + 0 * t, 1 + np.pi * np.cos(np.pi * t)]))
print("straight path (0,0)->(2,1):", round(work(*straight), 6))
print("wiggly path   (0,0)->(2,1):", round(work(*wiggly), 6))
print("phi(2,1) - phi(0,0)       :", phi(2, 1) - phi(0, 0))
straight path (0,0)->(2,1): 5.0
wiggly path   (0,0)->(2,1): 5.0
phi(2,1) - phi(0,0)       : 5

In software

  • Games and physics engines. The work done by forces along a path equals the change in kinetic energy. Checking that total energy stays constant in a conservative system (no friction) is a standard test of a physics integrator: drift means numerical error. See Integrators.
  • Flow fields for AI movement. Crowd and RTS pathfinding often precompute a vector field pointing toward the goal and let thousands of units simply follow it. If the field is the negative gradient of a distance-to-goal map, it is conservative: no unit can circle forever.
  • Robotics and planning. Potential-field planners steer along −∇φ-\nabla\varphi, where φ\varphi is low at the goal and high near obstacles.
  • Electromagnetism in simulations. Voltage is the line integral of the electric field; induced currents come from the circulation of a field.

Exercises

Exercise 1: Scalar line integral

Compute ∫C(x+y) ds\int_C (x + y) \, ds where CC is the straight segment from (0, 0) to (3, 4).

Answer

35/2=17.535/2 = 17.5.

Solution
r(t)=⟨3t,4t⟩, 0≤t≤1,∥r′(t)∥=5∫01(3t+4t)⋅5 dt=35∫01t dt=35/2\begin{aligned} &\mathbf{r}(t) = \langle 3t, 4t \rangle,\ 0 \le t \le 1, \qquad \lVert \mathbf{r}'(t) \rVert = 5 \\ &\int_0^1 (3t + 4t) \cdot 5 \, dt = 35 \int_0^1 t \, dt = 35/2 \end{aligned}

Exercise 2: Work along a parabola

Find the work done by F=⟨y,x2⟩\mathbf{F} = \langle y, x^2 \rangle along y=x2y = x^2 from (0, 0) to (1, 1).

Answer

5/6.

Solution
r(t)=⟨t,t2⟩,r′(t)=⟨1,2t⟩,F(r(t))=⟨t2,t2⟩F⋅r′=t2+2t3W=∫01(t2+2t3) dt=1/3+1/2=5/6\begin{aligned} &\mathbf{r}(t) = \langle t, t^2 \rangle, \qquad \mathbf{r}'(t) = \langle 1, 2t \rangle, \qquad \mathbf{F}(\mathbf{r}(t)) = \langle t^2, t^2 \rangle \\ &\mathbf{F} \cdot \mathbf{r}' = t^2 + 2t^3 \\ &W = \int_0^1 (t^2 + 2t^3) \, dt = 1/3 + 1/2 = 5/6 \end{aligned}

Exercise 3: Conservative?

Is F=⟨3x2+y,x+4y⟩\mathbf{F} = \langle 3x^2 + y, x + 4y \rangle conservative? If so, find a potential φ\varphi and use it to compute the work from (1, 0) to (2, 3).

Answer

Yes; φ=x3+xy+2y2\varphi = x^3 + xy + 2y^2, and the work is 31.

Solution
∂P∂y=1=∂Q∂xconservativeφx=3x2+y→φ=x3+xy+g(y)φy=x+g′(y)=x+4y→g=2y2φ(2,3)−φ(1,0)=(8+6+18)−1=31\begin{aligned} &\frac{\partial P}{\partial y} = 1 = \frac{\partial Q}{\partial x} && \text{conservative} \\ &\varphi_x = 3x^2 + y \quad\to\quad \varphi = x^3 + xy + g(y) \\ &\varphi_y = x + g'(y) = x + 4y \quad\to\quad g = 2y^2 \\ &\varphi(2, 3) - \varphi(1, 0) = (8 + 6 + 18) - 1 = 31 \end{aligned}

Exercise 4: Circulation from samples (code)

A game samples a wind field F(x,y)=⟨−y+0.5x,x⟩\mathbf{F}(x, y) = \langle -y + 0.5x, x \rangle and moves a balloon around the square with corners (0, 0), (1, 0), (1, 1), (0, 1), counter-clockwise. Approximate the circulation by summing F(midpoint)⋅Δr\mathbf{F}(\text{midpoint}) \cdot \Delta\mathbf{r} over 1000 steps per side.

Answer

The circulation is 2 (exactly; the sum gives 2.0).

Solution

On each small step the work is about F(midpoint)⋅Δr\mathbf{F}(\text{midpoint}) \cdot \Delta\mathbf{r}. The 0.5x0.5x part of the field is a gradient (of x2/4x^2/4) and contributes nothing around a closed loop; the rest gives ∂Q/∂x−∂P/∂y=1−(−1)=2\partial Q/\partial x - \partial P/\partial y = 1 - (-1) = 2 per unit area (that is Green's theorem).

python · try it yourself
import numpy as np
F = lambda p: np.array([-p[1] + 0.5 * p[0], p[0]])
corners = [np.array(c, dtype=float) for c in [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]]
total = 0.0
for A, B in zip(corners[:-1], corners[1:]):
    pts = A + np.linspace(0, 1, 1001)[:, None] * (B - A)
    for p, q in zip(pts[:-1], pts[1:]):
        total += F((p + q) / 2) @ (q - p)
print(round(total, 6))
2.0

Test yourself

The work done by a force field F\mathbf{F} along a curve r(t)\mathbf{r}(t) is…

  1. ∫∥F∥ dt\int \lVert \mathbf{F} \rVert \, dt
  2. ∫F(r(t))⋅r′(t) dt\int \mathbf{F}(\mathbf{r}(t)) \cdot \mathbf{r}'(t) \, dt
  3. ∫F(r(t))×r′(t) dt\int \mathbf{F}(\mathbf{r}(t)) \times \mathbf{r}'(t) \, dt
  4. F(end)−F(start)\mathbf{F}(\text{end}) - \mathbf{F}(\text{start})

For a conservative field F=∇φ\mathbf{F} = \nabla\varphi, the work around a closed loop is…

  1. 2π2\pi
  2. always positive
  3. zero
  4. the length of the loop

Which test shows that F=⟨P,Q⟩\mathbf{F} = \langle P, Q \rangle is NOT conservative?

  1. P=QP = Q
  2. ∂P/∂y≠∂Q/∂x\partial P/\partial y \ne \partial Q/\partial x
  3. PP and QQ are polynomials
  4. F\mathbf{F} is zero at the origin