TExcelTAD
Home › Calculus in Depth › The Fundamental Theorem for Line Integrals

The Fundamental Theorem for Line Integrals

For a gradient field, the work along a path depends only on where the path starts and ends. This is the line-integral version of the Fundamental Theorem of Calculus, and it explains path independence, potential energy and conservation of energy. This lesson proves the theorem, gives the test for whether a field is conservative (and the fine print about holes in the domain), shows how to construct a potential function, and checks everything numerically.

The theorem

Theorem. Let CC be a smooth curve given by r(t)\mathbf{r}(t), a≤t≤ba \le t \le b, and let ff be a differentiable function whose gradient ∇f\nabla f is continuous on CC. Then

∫C∇f⋅dr=f(r(b))−f(r(a))\int_C \nabla f \cdot d\mathbf{r} = f(\mathbf{r}(b)) - f(\mathbf{r}(a))

Proof. By the chain rule, ddtf(x(t),y(t),z(t))=fxx′+fyy′+fzz′=∇f(r(t))⋅r′(t)\frac{d}{dt} f(x(t), y(t), z(t)) = f_x x' + f_y y' + f_z z' = \nabla f(\mathbf{r}(t)) \cdot \mathbf{r}'(t). So

∫C∇f⋅dr=∫ab∇f(r(t))⋅r′(t) dt=∫abddtf(r(t)) dt=f(r(b))−f(r(a))\int_C \nabla f \cdot d\mathbf{r} = \int_a^b \nabla f(\mathbf{r}(t)) \cdot \mathbf{r}'(t)\,dt = \int_a^b \frac{d}{dt} f(\mathbf{r}(t))\,dt = f(\mathbf{r}(b)) - f(\mathbf{r}(a))

by the ordinary Fundamental Theorem of Calculus. For a piecewise-smooth curve, apply this to each piece; the intermediate values telescope. ∎

Compare with the survey lesson Green's, Stokes' and Divergence Theorems: every theorem of vector calculus has this shape, "integral of a derivative over a region=values on the boundary\text{integral of a derivative over a region} = \text{values on the boundary}", and here the boundary of a curve is its two endpoints.

Path independence and closed curves

Say ∫CF⋅dr\int_C \mathbf{F} \cdot d\mathbf{r} is independent of path in a region DD if any two paths in DD with the same initial and terminal points give the same value. Three statements turn out to be equivalent for a continuous field F\mathbf{F} on an open connected region DD:

Statement Why it follows
(1) F=∇f\mathbf{F} = \nabla f for some ff (F\mathbf{F} is conservative) assumption
(2) ∫CF⋅dr\int_C \mathbf{F} \cdot d\mathbf{r} is independent of path in DD (1)⇒(2)(1) \Rightarrow (2) by the theorem
(3) ∮CF⋅dr=0\oint_C \mathbf{F} \cdot d\mathbf{r} = 0 for every closed path CC in DD a closed path is two paths with the same ends, one reversed

(3)⇒(1)(3) \Rightarrow (1) is the deeper direction: fix a point (a,b)(a, b) and define f(x,y)=∫F⋅drf(x, y) = \int \mathbf{F} \cdot d\mathbf{r} along any path from (a,b)(a, b) to (x,y)(x, y). Path independence makes this well defined, and differentiating along a horizontal final segment gives fx=Pf_x = P, along a vertical one fy=Qf_y = Q.

A test for conservative fields

If F=⟨P,Q⟩=∇f\mathbf{F} = \langle P, Q \rangle = \nabla f with continuous second partials, then Py=fxy=fyx=QxP_y = f_{xy} = f_{yx} = Q_x by Clairaut's theorem. So

F conservative  ⟹  ∂P∂y=∂Q∂x(in 3D: curl⁡F=0)\mathbf{F} \text{ conservative} \implies \frac{\partial P}{\partial y} = \frac{\partial Q}{\partial x} \qquad \text{(in 3D: } \operatorname{curl} \mathbf{F} = \mathbf{0}\text{)}

The converse needs a condition on the region: if DD is simply connected (open, connected, and every simple closed curve in DD encloses only points of DD, i.e. no holes) and Py=QxP_y = Q_x throughout DD, then F\mathbf{F} is conservative. The proof uses Green's theorem. Without that condition the converse fails, as the vortex field below shows.

python · try it yourself
import sympy as sp
import numpy as np

x, y, z = sp.symbols('x y z')
F = sp.Matrix([2*x*y + z, x**2, x + 3*z**2])
curl = [sp.diff(F[2], y) - sp.diff(F[1], z), sp.diff(F[0], z) - sp.diff(F[2], x), sp.diff(F[1], x) - sp.diff(F[0], y)]
print("curl F =", curl)

f = sp.integrate(F[0], x)                                  # x**2*y + x*z, plus g(y, z)
f += sp.integrate(sp.simplify(F[1] - sp.diff(f, y)), y)    # nothing new in y
f += sp.integrate(sp.simplify(F[2] - sp.diff(f, z)), z)    # adds z**3
print("potential f =", f)
print("f(1,2,1) - f(0,0,0) =", f.subs({x: 1, y: 2, z: 1}) - f.subs({x: 0, y: 0, z: 0}))

t = np.linspace(0, 1, 200_001)                             # a wiggly path between the same points
r = np.array([t, 2 * t + np.sin(3 * np.pi * t), t**3])
Fn = sp.lambdify((x, y, z), list(F), "numpy")
mid, dr = (r[:, 1:] + r[:, :-1]) / 2, np.diff(r, axis=1)
print("numerical work along the wiggle ≈", round(float(np.sum(np.array(Fn(*mid)) * dr)), 6))
curl F = [0, 0, 0]
potential f = x**2*y + x*z + z**3
f(1,2,1) - f(0,0,0) = 4
numerical work along the wiggle ≈ 4.0

The curl is zero on all of R3\mathbb{R}^3 (simply connected), SymPy builds the potential step by step (integrate PP in xx, then add what is missing in yy and in zz), and the wiggly path gives exactly f(end)−f(start)=4f(\text{end}) - f(\text{start}) = 4.

The vortex: curl zero but not conservative

The field F=⟨−y,x⟩/(x2+y2)\mathbf{F} = \langle -y, x \rangle / (x^2 + y^2) is defined on the plane minus the origin. A short computation gives Py=Qx=y2−x2(x2+y2)2P_y = Q_x = \frac{y^2 - x^2}{(x^2 + y^2)^2}, so the test passes everywhere in its domain. Yet around the unit circle F⋅r′=sin⁡2t+cos⁡2t=1\mathbf{F} \cdot \mathbf{r}' = \sin^2 t + \cos^2 t = 1, so ∮F⋅dr=2π≠0\oint \mathbf{F} \cdot d\mathbf{r} = 2\pi \ne 0. The domain has a hole, and the converse needs simple connectivity. Locally F=∇θ\mathbf{F} = \nabla\theta (the polar angle), but θ\theta cannot be defined continuously all the way around the origin: it jumps by 2π2\pi.

python · try it yourself
import numpy as np

F = lambda x, y: (-y / (x**2 + y**2), x / (x**2 + y**2))
def loop(cx, cy, R, n=100_000):
    t = (np.arange(n) + 0.5) * 2 * np.pi / n
    x, y = cx + R * np.cos(t), cy + R * np.sin(t)
    P, Q = F(x, y)
    return float(np.sum(P * -R * np.sin(t) + Q * R * np.cos(t)) * 2 * np.pi / n)

print("circle around the origin     :", round(loop(0, 0, 1), 6), " 2π =", round(2 * np.pi, 6))
print("bigger circle, off-centre    :", round(loop(0.5, 0, 3), 6))
print("circle NOT around the origin :", round(loop(3, 0, 1), 6) + 0.0)   # + 0.0 turns -0.0 into 0.0
circle around the origin     : 6.283185  2π = 6.283185
bigger circle, off-centre    : 6.283185
circle NOT around the origin : 0.0

Every loop that winds once around the hole gives 2π2\pi; a loop that avoids it gives 0. This number divided by 2π2\pi is the winding number, used in graphics for point-in-polygon tests.

Conservation of energy

If a force F=−∇U\mathbf{F} = -\nabla U (UU the potential energy) moves a particle of mass mm along CC from AA to BB, Newton's law F=mr′′\mathbf{F} = m\mathbf{r}'' gives work=12m∣v(B)∣2−12m∣v(A)∣2\text{work} = \frac{1}{2}m\lvert \mathbf{v}(B) \rvert^2 - \frac{1}{2}m\lvert \mathbf{v}(A) \rvert^2 (change in kinetic energy), while the theorem gives work=U(A)−U(B)\text{work} = U(A) - U(B). Equating them: K(A)+U(A)=K(B)+U(B)K(A) + U(A) = K(B) + U(B). The total energy is constant, which is why such forces are called conservative.

In software

  • Game AI and robotics. In a potential-field planner the "cost" of reaching a point is the potential difference, independent of the route taken, as long as the field is a true gradient. Hand-tuned force fields that are not gradients can make agents circle forever.
  • Physics engines. A good integrator should keep K+UK + U nearly constant for gravity and springs; energy drift is a standard bug check (integrators).
  • Geometry. The winding number (∮ of the vortex field ÷2π\oint \text{ of the vortex field } \div 2\pi) decides point-in-polygon and inside/outside tests, including for the non-zero fill rule in vector graphics.
  • Optimization. For a loss LL, the change L(θend)−L(θstart)L(\theta_{\text{end}}) - L(\theta_{\text{start}}) is ∫∇L⋅dθ\int \nabla L \cdot d\theta along the training trajectory, regardless of the optimizer's path.

Exercises

Exercise 1: Use the theorem

Show that F=⟨ycos⁡x,sin⁡x+2y⟩\mathbf{F} = \langle y \cos x, \sin x + 2y \rangle is conservative and compute ∫CF⋅dr\int_C \mathbf{F} \cdot d\mathbf{r} along any path from (0,0)(0, 0) to (π/2,1)(\pi/2, 1).

Answer

f=ysin⁡x+y2f = y \sin x + y^2; the integral is 2.

Solution
Py=cos⁡x,Qx=cos⁡xequal on all of R2 (simply connected)  ⟹  conservativefx=ycos⁡x  ⟹  f=ysin⁡x+g(y);fy=sin⁡x+g′(y)=sin⁡x+2y  ⟹  g=y2f(π/2,1)−f(0,0)=(1⋅1+1)−0=2\begin{aligned} &P_y = \cos x, \quad Q_x = \cos x && \text{equal on all of } \mathbb{R}^2 \text{ (simply connected)} \implies \text{conservative} \\ &f_x = y \cos x \implies f = y \sin x + g(y); && f_y = \sin x + g'(y) = \sin x + 2y \implies g = y^2 \\ &f(\pi/2, 1) - f(0, 0) = (1 \cdot 1 + 1) - 0 = 2 \end{aligned}

Exercise 2: Not conservative

Is F=⟨xy,x2⟩\mathbf{F} = \langle xy, x^2 \rangle conservative on R2\mathbb{R}^2?

Answer

No.

Solution

Py=xP_y = x and Qx=2xQ_x = 2x. They differ wherever x≠0x \ne 0, and a conservative field must have Py=QxP_y = Q_x everywhere, so F\mathbf{F} is not conservative.

Exercise 3: Work done by gravity (code)

With units chosen so that GMm=1GMm = 1, gravity is F=−r/∣r∣3\mathbf{F} = -\mathbf{r}/\lvert \mathbf{r} \rvert^3 with potential f=1/∣r∣f = 1/\lvert \mathbf{r} \rvert (F=∇f\mathbf{F} = \nabla f). Find the work done by gravity as an object moves from the point (2,0,0)(2, 0, 0) to (0,0,4)(0, 0, 4) by hand, then verify numerically along a spiral path.

Answer

−14=−0.25-\frac{1}{4} = -0.25 (the object moves away, so gravity does negative work).

Solution
work=f(end)−f(start)=14−12=−14\text{work} = f(\text{end}) - f(\text{start}) = \frac{1}{4} - \frac{1}{2} = -\frac{1}{4}
python · try it yourself
import numpy as np

t = np.linspace(0, 1, 200_001)
r = np.array([2 * (1 - t) * np.cos(4 * np.pi * t), 2 * (1 - t) * np.sin(4 * np.pi * t), 4 * t])
mid, dr = (r[:, 1:] + r[:, :-1]) / 2, np.diff(r, axis=1)
F = -mid / np.linalg.norm(mid, axis=0)**3
print(round(float(np.sum(F * dr)), 6))
-0.25

Exercise 4: A potential in 3D

Find ff with ∇f=⟨yz,xz+2y,xy⟩\nabla f = \langle yz, xz + 2y, xy \rangle and evaluate ∫CF⋅dr\int_C \mathbf{F} \cdot d\mathbf{r} from (1,1,1)(1, 1, 1) to (2,3,1)(2, 3, 1).

Answer

f=xyz+y2+Cf = xyz + y^2 + C; the integral is 13.

Solution
fx=yz  ⟹  f=xyz+g(y,z)fy=xz+gy=xz+2y  ⟹  g=y2+h(z)fz=xy+h′(z)=xy  ⟹  h constantf(2,3,1)−f(1,1,1)=(6+9)−(1+1)=13\begin{aligned} &f_x = yz \implies f = xyz + g(y, z) \\ &f_y = xz + g_y = xz + 2y \implies g = y^2 + h(z) \\ &f_z = xy + h'(z) = xy \implies h \text{ constant} \\ &f(2, 3, 1) - f(1, 1, 1) = (6 + 9) - (1 + 1) = 13 \end{aligned}

Test yourself

F=∇f\mathbf{F} = \nabla f and CC runs from AA to BB. Then ∫CF⋅dr\int_C \mathbf{F} \cdot d\mathbf{r} equals…

  1. f(A)−f(B)f(A) - f(B)
  2. 0
  3. ∣∇f(B)∣−∣∇f(A)∣\lvert \nabla f(B) \rvert - \lvert \nabla f(A) \rvert
  4. f(B)−f(A)f(B) - f(A)

On which domain does Py=QxP_y = Q_x guarantee that ⟨P,Q⟩\langle P, Q \rangle is conservative?

  1. Any open domain
  2. A simply connected open domain
  3. Only on circles
  4. Only when PP and QQ are polynomials of degree 1

A field F\mathbf{F} has ∮CF⋅dr=0\oint_C \mathbf{F} \cdot d\mathbf{r} = 0 for every closed curve CC in a region. What else is true there?

  1. Line integrals of F\mathbf{F} are path-independent
  2. F\mathbf{F} is the zero field
  3. F\mathbf{F} has constant length
  4. F\mathbf{F} is perpendicular to every curve