Chapter 10
20 min read
Section 96 of 353

Work and Energy

Applications of Integration

Learning Objectives

By the end of this section, you will be able to:

  1. Understand why work done by a variable force requires integration rather than simple multiplication
  2. Calculate work as the definite integral W=abF(x)dxW = \int_a^b F(x) \, dx
  3. Apply Hooke's Law to compute work done on springs
  4. Set up and evaluate integrals for lifting problems with variable mass (ropes, chains, cables)
  5. Calculate work done pumping fluids from tanks of various shapes
  6. Connect work-energy concepts to optimization in machine learning

The Big Picture: Why Integration?

"Work is not just force times distance—it's the accumulation of infinitely many infinitesimal contributions when force varies."

In elementary physics, you learned that work equals force times distance:W=FdW = F \cdot d. This formula works perfectly when the force is constant. But what happens when the force changes as you move?

Consider these scenarios:

  • Stretching a spring: The farther you stretch, the harder it gets. Force increases with displacement.
  • Lifting a heavy rope: As you pull up more rope, less remains hanging, so you lift less weight.
  • Pumping water: Water at the bottom must be lifted higher than water at the top.
  • Rocket escaping Earth: Gravitational force weakens with altitude.

In all these cases, the simple formula W=FdW = Fd fails because FF is not constant. We need integration to sum up infinitely many small contributions:

W=abF(x)dxW = \int_a^b F(x) \, dx

Work equals the integral of force over the path of motion.

The Central Idea

Work is accumulated force times distance. When force varies, we break the path into infinitesimal pieces where force is approximately constant, compute the tiny work dW=F(x)dxdW = F(x) \, dx, and integrate to find the total.


Historical Context: From Machines to Energy

The concept of work emerged from the study of simple machines—levers, pulleys, inclined planes—during the Renaissance. Engineers wanted to quantify the "effectiveness" of machines.

Gaspard-Gustave Coriolis (1792–1843)

The French mathematician Coriolis gave the first precise definition of work as W=FdcosθW = Fd\cos\theta in his 1829 treatise on machines. He recognized that only the component of force parallel to motion contributes to work.

The Work-Energy Theorem

The profound insight connecting work to energy came from understanding that work done on an object equals its change in kinetic energy:

Wnet=ΔKE=12mvf212mvi2W_{net} = \Delta KE = \frac{1}{2}mv_f^2 - \frac{1}{2}mv_i^2

This theorem bridges mechanics and thermodynamics, showing that work and energy are two sides of the same coin.

Units of Work

Work is measured in Joules (J) in SI units, where 1 J = 1 N·m = 1 kg·m²/s². In the imperial system, work is measured in foot-pounds (ft·lb).


Work with Constant Force

Let's start with the simple case. When a constant force FF moves an object from position x=ax = a to x=bx = b:

W=F(ba)=FdW = F \cdot (b - a) = F \cdot d

Geometrically, this is the area of a rectangle with height FF and width dd. We can also write this as an integral:

W=abFdx=Fxab=F(ba)W = \int_a^b F \, dx = F \cdot x \Big|_a^b = F(b-a)

The integral reduces to the familiar formula when force is constant—but the integral form is more general and handles variable forces.

Example: Lifting a Box

Problem: A 5 kg box is lifted 3 meters straight up. How much work is done against gravity?

Solution: The force required equals the weight: F=mg=5×9.8=49F = mg = 5 \times 9.8 = 49 N.

W=Fd=49×3=147 JW = Fd = 49 \times 3 = 147 \text{ J}

Or using integration: W=0349dy=49y03=147W = \int_0^3 49 \, dy = 49y \Big|_0^3 = 147 J.


Work with Variable Force

When force varies with position, we cannot simply multiply. Instead, we:

  1. Divide the path from aa to bb into small intervals of width Δx\Delta x
  2. On each interval, approximate force as constant: F(xi)F(x_i^*)
  3. Compute the work on each piece: ΔWiF(xi)Δx\Delta W_i \approx F(x_i^*) \Delta x
  4. Sum all contributions: WF(xi)ΔxW \approx \sum F(x_i^*) \Delta x
  5. Take the limit as Δx0\Delta x \to 0: W=abF(x)dxW = \int_a^b F(x) \, dx

Work Done by a Variable Force

If a force F(x)F(x) acts on an object as it moves from x=ax = a to x=bx = b, the work done is:

W=abF(x)dxW = \int_a^b F(x) \, dx

Geometrically: Work = Area under the force-position curve

Interactive: Work as an Integral

Explore how work is calculated for different force functions. Adjust the bounds and see how the area under the curve (work) changes:

Interactive: Work as the Integral of Force
Position x (m)Force F(x) (N)012345050100a = 0.0b = 3.0F(x) = a + bxWork W = ∫F dx
Exact Work (Integral)
W = 120.00 J
Riemann Sum (10 rectangles)
W ≈ 120.00 J
Error: 0.000 J (0.00%)

Force increases linearly with position (like a spring)

Formula:
W = ∫ₐᵇ F(x) dx
Work equals the area under the force-position curve, which is calculated using a definite integral.

Work Done on Springs: Hooke's Law

One of the most important applications of work integrals involves springs.Hooke's Law states that the force required to stretch or compress a spring is proportional to the displacement:

F(x)=kxF(x) = kx

where kk is the spring constant (N/m) and xx is displacement from natural length.

Deriving the Work Formula

To stretch a spring from its natural length (x = 0) to displacement x=dx = d:

W=0dF(x)dx=0dkxdxW = \int_0^d F(x) \, dx = \int_0^d kx \, dx
=kx220d=12kd2= k \cdot \frac{x^2}{2} \Big|_0^d = \frac{1}{2}kd^2

Work to Stretch a Spring

W=12kx2W = \frac{1}{2}kx^2

This equals the elastic potential energy stored in the spring.

Geometric Interpretation

Since F=kxF = kx is linear, the graph is a straight line through the origin. The work is the area of the triangle under this line: Area = 12\frac{1}{2} × base × height =12xkx=12kx2\frac{1}{2} \cdot x \cdot kx = \frac{1}{2}kx^2.

Example: Stretching from One Position to Another

Problem: A spring with k = 200 N/m is stretched from x = 0.1 m to x = 0.3 m. Find the work done.

Solution: We integrate from 0.1 to 0.3 (not from 0):

W=0.10.3200xdx=100x20.10.3W = \int_{0.1}^{0.3} 200x \, dx = 100x^2 \Big|_{0.1}^{0.3}
=100(0.090.01)=100(0.08)=8 J= 100(0.09 - 0.01) = 100(0.08) = 8 \text{ J}

Interactive: Spring Work Demo

Watch how work accumulates as a spring is stretched. Notice that the force grows linearly, and the work (area under the curve) is a triangle:

Interactive: Work Done on a Spring
Natural lengthmDisplacement x (m)Force F (N)Area = ½kx² = 0.00 J
Force (F = kx)
0.0 N
Displacement
0.000 m
Work Done
0.00 J
Hooke's Law
F(x) = kx
Work Done
W = ∫₀ˣ F(s) ds = ∫₀ˣ ks ds
W = [½ks²]₀ˣ = ½kx²
Key Insight: The work done equals the area of the triangle under the force-displacement curve. Since force increases linearly from 0 to kx, the area is ½ × base × height = ½ × x × kx = ½kx².

Work Lifting Variable Mass: Ropes and Chains

Consider lifting a heavy rope hanging over a cliff. As you pull, the amount of rope remaining decreases, so the weight you lift changes. This requires an integral.

Setup for Rope Problems

Let a rope of length LL hang from a cliff, with linear density λ\lambda kg/m.

  • A segment of length dydy at position yy from the bottom has mass dm=λdydm = \lambda \, dy
  • This segment must be lifted a distance yy to reach the top
  • Work to lift this segment: dW=gλydydW = g \cdot \lambda \cdot y \, dy

Total work to pull up the entire rope:

W=0Lgλydy=gλy220L=12gλL2W = \int_0^L g \lambda y \, dy = g\lambda \cdot \frac{y^2}{2} \Big|_0^L = \frac{1}{2}g\lambda L^2

Example: Pulling Up a Chain

Problem: A 10-meter chain weighing 3 kg/m hangs from a rooftop. How much work is done pulling it completely up?

Solution: Here L=10L = 10 m, λ=3\lambda = 3 kg/m, and g=9.8g = 9.8 m/s².

W=12(9.8)(3)(102)=12(9.8)(3)(100)=1470 JW = \frac{1}{2}(9.8)(3)(10^2) = \frac{1}{2}(9.8)(3)(100) = 1470 \text{ J}

Note: This equals the work to lift the chain's center of mass (at L/2) by distance L/2, giving W=(λLg)L2=12gλL2W = (\lambda L \cdot g) \cdot \frac{L}{2} = \frac{1}{2}g\lambda L^2.


Work Pumping Fluids

Pumping water (or any fluid) from a tank is a classic work problem. The key insight is that water at different heights must be lifted different distances.

General Setup

Consider a tank with water filled to height hh. We want to pump all water to an outlet at height H+dH + d (where HH is the tank height and dd is how high the outlet is above the tank).

  1. Consider a thin horizontal slice of water at height yy with thickness dydy
  2. The slice has cross-sectional area A(y)A(y) (depends on tank shape)
  3. Volume of slice: dV=A(y)dydV = A(y) \, dy
  4. Mass of slice: dm=ρA(y)dydm = \rho \cdot A(y) \, dy where ρ\rho is fluid density
  5. Distance to lift: (Hy)+d(H - y) + d
  6. Work to lift slice: dW=ρgA(y)(H+dy)dydW = \rho g A(y)(H + d - y) \, dy

Work to Pump Fluid from a Tank

W=0hρgA(y)(H+dy)dyW = \int_0^h \rho g A(y) (H + d - y) \, dy

where A(y)A(y) is the cross-sectional area at height y

Example: Cylindrical Tank

Problem: A cylindrical tank with radius 2 m and height 4 m is full of water (ρ = 1000 kg/m³). Find the work to pump all water to a spout 1 m above the top.

Solution: For a cylinder, A(y)=πr2=4πA(y) = \pi r^2 = 4\pi (constant).

W=0410009.84π(4+1y)dyW = \int_0^4 1000 \cdot 9.8 \cdot 4\pi (4 + 1 - y) \, dy
=39200π04(5y)dy=39200π[5yy22]04= 39200\pi \int_0^4 (5 - y) \, dy = 39200\pi \left[ 5y - \frac{y^2}{2} \right]_0^4
=39200π(208)=39200π121.48×106 J= 39200\pi (20 - 8) = 39200\pi \cdot 12 \approx 1.48 \times 10^6 \text{ J}

Interactive: Pumping Work Demo

Explore work calculations for different tank shapes. Watch the water level drop as you pump, and see how the work accumulates:

Interactive: Work Done Pumping Water
OutletH = 3mh = 2.00m+1mWork IntegralW = ∫₀ʰ ρgA(y)(H+d-y) dyρ = 1000 kg/m³g = 9.8 m/s²H = 3m, d = 1mW = 0.00 kJ
Initial Volume
8.00
Water Mass
8.0 tons
Total Work
235.20 kJ

Constant cross-section

Why Integration? Each thin slice of water at height y must be lifted a different distance (H + d - y) to reach the outlet. The work varies by layer, requiring integration to sum all contributions.

Connection to Energy

Work and energy are intimately connected through the Work-Energy Theorem and the concept of potential energy.

Work-Energy Theorem

The net work done on an object equals its change in kinetic energy:

Wnet=ΔKE=12mvf212mvi2W_{net} = \Delta KE = \frac{1}{2}mv_f^2 - \frac{1}{2}mv_i^2

Potential Energy

When work is done against a conservative force (like gravity or a spring), that work is stored as potential energy:

Force TypePotential Energy
Gravity (near Earth)U = mgh
Spring (Hooke's Law)U = ½kx²
Gravity (universal)U = -GMm/r
Coulomb (electrostatic)U = kq₁q₂/r

The Energy-Work Connection

Work done by a force decreases its potential energy:W=ΔUW = -\Delta U. Work done against a force increases potential energy:W=+ΔUW = +\Delta U.


Real-World Applications

Engineering: Elevators and Cranes

Elevator motors must do work against gravity. For a fully-loaded elevator car of mass mm traveling height hh, the minimum work is W=mghW = mgh. Real systems account for counterweights, friction, and acceleration.

Physics: Escape Velocity

To escape Earth's gravity, an object must have enough kinetic energy to overcome the gravitational potential energy. This leads to:

W=RGMmr2dr=GMmRW = \int_R^\infty \frac{GMm}{r^2} \, dr = \frac{GMm}{R}

Setting this equal to initial kinetic energy gives the escape velocity:vescape=2gRv_{escape} = \sqrt{2gR}.

Biology: Muscle Work

Muscles produce variable force depending on their length and activation. The work done during muscle contraction is the integral of force over the range of motion—critical for understanding athletic performance and biomechanical design.


Machine Learning Connection

The concepts of work and energy have direct analogs in optimization and machine learning.

Loss Functions as Potential Energy

In physics, systems naturally evolve to minimize potential energy. In machine learning, we minimize loss functions. The analogy is precise:

PhysicsMachine Learning
Potential energy U(x)Loss function L(θ)
Force F = -∇UNegative gradient -∇L
Equilibrium (F = 0)Optimum (∇L = 0)
Work W = F · dLoss change ΔL ≈ ∇L · Δθ
Energy conservationGradient descent dynamics

Gradient Descent as Rolling Downhill

Gradient descent can be viewed as a ball rolling on a loss landscape, driven by the "force" of the negative gradient. Each parameter update does "work" on the system:

ΔLθLΔθ=ηθL2\Delta L \approx \nabla_\theta L \cdot \Delta\theta = -\eta \|\nabla_\theta L\|^2

This shows that gradient descent always decreases the loss (for small enough learning rate η\eta)—just like a ball rolling downhill always decreases its potential energy.

The Work-Energy Theorem in ML

Just as the physics work-energy theorem relates work to kinetic energy change, in ML the "work" done by parameter updates (LΔθ\nabla L \cdot \Delta\theta) relates to the change in loss. This connection underlies momentum methods, learning rate schedules, and second-order optimization.


Python Implementation

Computing Work with Variable Forces

Here's how to calculate work using numerical integration in Python:

Work Calculation with Python
🐍work_calculation.py
9Spring Force (Hooke's Law)

The force required to stretch or compress a spring is F = kx, where k is the spring constant and x is the displacement from natural length.

20Numerical Integration

scipy.integrate.quad performs adaptive quadrature to compute definite integrals. It returns both the result and an error estimate.

43Slice Work Formula

Each horizontal slice of water at height y has volume A(y)dy and must be lifted a distance (H - y + d). The work is force × distance = ρgA(y)(H - y + d)dy.

55Analytical Verification

For a cylindrical tank, the integral can be computed exactly. This provides a check on our numerical result.

81 lines without explanation
1import numpy as np
2from scipy import integrate
3import matplotlib.pyplot as plt
4
5def work_by_variable_force():
6    """
7    Calculate work done by a variable force using integration.
8    W = ∫[a to b] F(x) dx
9    """
10    # Define force functions
11    def spring_force(x, k=50):
12        """Hooke's Law: F = kx"""
13        return k * x
14
15    def gravity_force(y, m=10, g=9.8):
16        """Constant gravitational force"""
17        return m * g
18
19    def inverse_square_force(r, G_M_m=1e10):
20        """Gravitational attraction: F = GMm/r²"""
21        return G_M_m / (r ** 2)
22
23    # Calculate work done compressing a spring from 0 to 0.5 m
24    k = 100  # N/m
25    x_max = 0.5  # meters
26
27    # Analytical: W = ½kx²
28    W_analytical = 0.5 * k * x_max**2
29
30    # Numerical integration
31    W_numerical, error = integrate.quad(lambda x: spring_force(x, k), 0, x_max)
32
33    print("Spring Work Calculation")
34    print("=" * 40)
35    print(f"Spring constant k = {k} N/m")
36    print(f"Displacement x = {x_max} m")
37    print(f"Analytical: W = ½kx² = {W_analytical:.4f} J")
38    print(f"Numerical:  W = {W_numerical:.4f} J")
39    print(f"Error: {abs(W_analytical - W_numerical):.2e} J")
40
41    return W_numerical
42
43def work_pumping_water():
44    """
45    Calculate work to pump water from a tank.
46    Each slice at height y must be lifted (H - y + d) meters.
47    """
48    # Tank parameters
49    rho = 1000  # kg/m³ (water density)
50    g = 9.8     # m/s²
51    H = 3       # tank height (m)
52    r = 1       # tank radius (m)
53    d = 1       # height above tank to pump (m)
54
55    def work_per_slice(y):
56        """
57        Work to lift a thin slice at height y.
58        dW = ρ * g * A(y) * distance * dy
59        """
60        A = np.pi * r**2  # cross-sectional area
61        distance = (H - y) + d  # distance to lift
62        return rho * g * A * distance
63
64    # Total work = ∫[0 to H] ρgA(H - y + d) dy
65    W, error = integrate.quad(work_per_slice, 0, H)
66
67    print("\nPumping Water Calculation")
68    print("=" * 40)
69    print(f"Tank height: {H} m, radius: {r} m")
70    print(f"Pump outlet: {d} m above tank")
71    print(f"Water density: {rho} kg/m³")
72    print(f"Total work: {W/1000:.2f} kJ")
73
74    # Analytical solution for cylindrical tank:
75    # W = ρgπr² ∫[0 to H] (H + d - y) dy
76    #   = ρgπr² [(H+d)y - y²/2] from 0 to H
77    #   = ρgπr² [(H+d)H - H²/2]
78    #   = ρgπr² H[H/2 + d]
79    W_analytical = rho * g * np.pi * r**2 * H * (H/2 + d)
80    print(f"Analytical: {W_analytical/1000:.2f} kJ")
81
82    return W
83
84work_by_variable_force()
85work_pumping_water()

Work-Energy Concepts in Machine Learning

This code demonstrates the analogy between physics work-energy concepts and machine learning optimization:

Work-Energy in ML Context
🐍work_energy_ml.py
8Loss as Potential Energy

In physics, systems minimize potential energy. In ML, we minimize loss functions. The gradient ∇L plays the role of force (negative gradient of potential).

26Gradient Descent as Physics

Moving in the negative gradient direction is like letting a ball roll downhill. The learning rate controls the 'time step' of this motion.

56Work-Energy Theorem Analog

In physics, W = F·d gives work done. In ML, ΔL ≈ ∇L·Δθ gives the change in loss. Both relate force/gradient to displacement/update.

75First-Order Approximation

The approximation ΔL ≈ ∇L·Δθ comes from Taylor expansion. This is exact for linear functions and approximate otherwise—just like infinitesimal work dW = F·dx.

94 lines without explanation
1import numpy as np
2
3def energy_loss_functions():
4    """
5    In machine learning, loss functions are analogous to potential energy.
6    Optimization is like finding the minimum energy state.
7
8    The gradient ∇L(θ) plays the role of force: F = -∇U
9    """
10    # Define a simple loss landscape
11    def mse_loss(theta, X, y):
12        """Mean Squared Error loss"""
13        predictions = X @ theta
14        return np.mean((predictions - y) ** 2)
15
16    def loss_gradient(theta, X, y):
17        """Gradient of MSE loss (the 'force')"""
18        predictions = X @ theta
19        return 2 * X.T @ (predictions - y) / len(y)
20
21    # Generate sample data
22    np.random.seed(42)
23    n_samples, n_features = 100, 2
24    X = np.random.randn(n_samples, n_features)
25    true_theta = np.array([2.0, -1.0])
26    y = X @ true_theta + 0.1 * np.random.randn(n_samples)
27
28    # Gradient descent = "rolling downhill in energy landscape"
29    theta = np.zeros(n_features)
30    learning_rate = 0.1
31
32    print("Gradient Descent as Energy Minimization")
33    print("=" * 45)
34    print(f"{'Step':>4} | {'Loss (Energy)':>14} | {'||Gradient|| (Force)':>20}")
35    print("-" * 45)
36
37    losses = []
38    for step in range(20):
39        loss = mse_loss(theta, X, y)
40        grad = loss_gradient(theta, X, y)
41        losses.append(loss)
42
43        if step % 4 == 0:
44            print(f"{step:>4} | {loss:>14.6f} | {np.linalg.norm(grad):>20.6f}")
45
46        # Update: move in direction of negative gradient (force)
47        theta = theta - learning_rate * grad
48
49    print("-" * 45)
50    print(f"Final loss: {losses[-1]:.6f}")
51    print(f"True θ: {true_theta}")
52    print(f"Found θ: {theta}")
53    print("\nNote: Loss acts like potential energy, gradient like force.")
54    print("Optimization finds equilibrium where gradient = 0.")
55
56def work_energy_theorem_ml():
57    """
58    Work-Energy Theorem in ML context:
59    Change in loss = 'work' done by parameter updates
60
61    ΔL ≈ ∇L · Δθ (analogous to W = F · d)
62    """
63    print("\n" + "=" * 45)
64    print("Work-Energy Theorem in Machine Learning")
65    print("=" * 45)
66
67    # Simple 1D example
68    def loss(theta):
69        return (theta - 2) ** 2  # minimum at θ = 2
70
71    def gradient(theta):
72        return 2 * (theta - 2)
73
74    theta = 0.0
75    lr = 0.1
76
77    print("\nEach step: ΔL ≈ ∇L · Δθ (work done)")
78    print(f"{'θ':>6} | {'L(θ)':>10} | {'∇L':>10} | {'Δθ':>10} | {'ΔL':>10} | {'∇L·Δθ':>10}")
79    print("-" * 70)
80
81    for _ in range(5):
82        L = loss(theta)
83        grad = gradient(theta)
84        delta_theta = -lr * grad
85        theta_new = theta + delta_theta
86        L_new = loss(theta_new)
87        delta_L = L_new - L
88        work = grad * delta_theta  # Analogous to F · d
89
90        print(f"{theta:>6.3f} | {L:>10.4f} | {grad:>10.4f} | {delta_theta:>10.4f} | {delta_L:>10.4f} | {work:>10.4f}")
91
92        theta = theta_new
93
94    print("\nNote: ∇L·Δθ approximates the actual change ΔL")
95    print("This is analogous to W = F·d in physics!")
96
97energy_loss_functions()
98work_energy_theorem_ml()

Common Mistakes to Avoid

Mistake 1: Using W = Fd for Variable Forces

Wrong: If force varies, you cannot just multiply an average force by distance.

Correct: Set up and evaluate the integral W=F(x)dxW = \int F(x) \, dx.

Mistake 2: Wrong Distance in Pumping Problems

Wrong: Assuming all water travels the same distance.

Correct: Water at height y must travel distance (Hy)+d(H - y) + d to reach an outlet at height H+dH + d.

Mistake 3: Forgetting Cross-Section Varies

For non-cylindrical tanks (cones, hemispheres), the cross-sectional area A(y)A(y) changes with height. Include this in your integral!

Mistake 4: Confusing Force Direction

Work is positive when force and displacement are in the same direction. When lifting against gravity, you do positive work on the object (increasing its potential energy).


Test Your Understanding

Test Your UnderstandingQuestion 1 of 8

A force F(x) = 3x² N acts on an object as it moves from x = 0 to x = 2 m. What is the work done?


Summary

Work is a fundamental concept connecting force, motion, and energy. When force varies with position, integration becomes essential.

Key Formulas

SituationFormula
Constant forceW = Fd
Variable forceW = ∫ₐᵇ F(x) dx
Spring (from natural length)W = ½kx²
Rope/chain liftW = ½gλL²
Pumping fluidW = ∫ρgA(y)(H+d-y) dy

Key Takeaways

  1. Work is accumulated force: When force varies, W=F(x)dxW = \int F(x) \, dx sums infinitely many infinitesimal contributions.
  2. Geometric meaning: Work equals the area under the force-displacement curve.
  3. Springs store energy: Work 12kx2\frac{1}{2}kx^2 becomes elastic potential energy.
  4. Pumping problems: Each layer travels a different distance, requiring careful integral setup.
  5. ML connection: Loss functions act like potential energy; gradient descent minimizes this "energy."
The Core Insight:
"Work is the integral of force over path—the accumulation of infinitely many infinitesimal pushes that together accomplish the task."
Coming Next: In the next section on Hydrostatic Force and Pressure, we'll use integration to compute the total force exerted by fluids on submerged surfaces—another beautiful application of calculus to the physical world.
Loading comments...