Learning Objectives
By the end of this section, you will be able to:
- Understand the concept of a line integral as integrating a function along a curve, rather than over a straight interval on the x-axis
- Distinguish between scalar and vector line integrals ( vs ) and pick the right one for the problem
- Derive the arc-length element from first principles
- Evaluate line integrals by parametrization and reduce a curve integral to a familiar one-variable integral in
- Compute work done by a force field along a curved path
- Implement line integrals in plain Python and then in PyTorch with automatic differentiation
Why this matters: A line integral generalizes the integral from straight intervals to arbitrary curved paths. Once you have it, you can compute mass of a non-uniform wire, work done by a varying force along a winding road, circulation of fluid around a closed loop, the EMF in a circuit by Maxwell's equations, and the cost accumulated by an optimizer as it walks through a loss landscape.
The Big Picture
Standard one-variable integration sweeps across a straight interval on the x-axis. A line integral sweeps across an arbitrary curve in 2D or 3D space. Everything else stays the same: we slice the path into infinitesimal pieces, multiply each piece by the value of the function there, and sum.
- Scalar line integral : weighs a scalar function by the arc-length element . Answer to "how much of f piles up along the curve?"
- Vector line integral : projects a vector field onto the direction of motion. Answer to "how much of F is pushing me along the curve?"
The scalar form does not care which way you walk the curve; the vector form does — reverse direction and the sign flips. That difference will turn out to be the foundation of conservative fields, Green's theorem, and Stokes' theorem in the sections to come.
Where ds Comes From (Intuition)
Before any formula, picture this. You parametrize a curve with . The parameter is like time. As ticks forward by a tiny amount , the point on the curve moves by a tiny displacement vector .
The length of that tiny displacement is the arc-length element: . This is just the Pythagorean theorem in infinitesimal form —.
That is the entire trick. A scalar line integral measures — a value times a length. A vector line integral measures — a force dotted with a displacement. Everything that follows is bookkeeping.
Historical Context
Line integrals were invented to answer concrete physical questions in the 18th and 19th centuries: Lagrange and Laplace used path integrals to study gravitational potentials and the motion of planets; Cauchy formalized them in the complex plane, leading to the powerful Cauchy integral theorem; George Green connected line integrals to double integrals through Green's Theorem; and Maxwell built electromagnetism on top of them — the EMF around a loop and the current through a surface are both line/surface integrals. The unifying problem was always the same: a force that varies along a curved path makes the schoolbook formula work = force times distance meaningless, and line integrals fix it.
Scalar Line Integrals
Definition and Notation
Given a scalar function and a smooth curve , the scalar line integral of along is the limit of Riemann sums: , where the curve is sliced into small arcs of length and is any sample point on the -th arc.
Evaluation Using Parametrization
To actually compute, parametrize for . Substituting : . The line integral on the left (geometric, hard to compute directly) becomes a plain single-variable integral on the right (mechanical).
The Arc Length Element ds
Spelled out: . In 3D add a term. When , the scalar line integral collapses to the arc length: .
Worked Example (Step by Step)
We will compute both a scalar and a vector line integral on the same curve, so you can see exactly what is shared and what is different. The curve is the parabola from to .
- Parametrization for
- Velocity
- Speed
Part 1 — Mass of a wire (scalar line integral). Click to expand.
Imagine the parabola is a thin wire with linear mass density (kilograms per meter). Heavier at the right end, lighter at the origin. Total mass is .
Step 1. Substitute the parametrization: .
Step 2. Substitute .
Step 3. The line integral becomes the ordinary integral .
Step 4. Split into two pieces: .
Step 5. The first piece is a standard arc-length-style integral. Using : , which evaluates numerically to .
Step 6. The second piece is trivial with , : .
Step 7. Add them: kilograms. We will confirm this numerically with the Python implementation below.
Part 2 — Work done by a force field (vector line integral). Click to expand.
Now keep the same curve but switch from a scalar density to a vector force field . We want the work .
Step 1. Evaluate on the curve: .
Step 2. Take the dot product with : .
Step 3. The line integral becomes .
Step 4 (sanity check via potential). Notice that with . For any conservative field, the work equals the change in potential: . Same answer, confirmed. This is a preview of the Fundamental Theorem for Line Integrals in the next section.
Interactive: Scalar Line Integral
Explore how scalar line integrals work by integrating different functions along various curves. Watch how the Riemann sum approximation converges as you increase the number of segments. The colors indicate the value of the function at each point along the curve.
- Switch to arc-length mode with the helix to see 3D integration
- Compare the circle and the line — for , which gives a larger integral?
- Crank up the number of segments and watch the Riemann sum converge
Interactive: Parametric Curves and ds
Understanding the relationship between the parameter and the arc-length element is crucial. Drag the slider to move along the curve and watch how turns parameter changes into actual distances.
Vector Line Integrals
Work and the Line Integral of a Vector Field
When a force moves an object along a path , the work done is . This is the vector line integral (or work integral). Unlike its scalar cousin, it depends on the direction of traversal: walk the curve backwards and the answer flips sign.
The Dot Product Form
With parametrization for : . Writing , this is also , where and .
Interactive: Work Done by a Force Field
Explore how different vector fields do work along various paths. Green segments show positive work (force helping motion), red segments show negative work (force opposing motion). Notice how the total work depends on both the field and the path.
- For the radial field , work between two points is the same for every path you draw — it is conservative
- For the rotational field , work around a closed loop is nonzero and equals twice the enclosed area
- For gravity , only vertical motion does work; horizontal motion does none
Properties of Line Integrals
| Property | Scalar line integral | Vector line integral |
|---|---|---|
| Direction dependence | Independent of direction | Sign flips if direction reverses |
| Additivity over paths | Integral on = sum of pieces | Same: integral on = sum of pieces |
| Reparametrization | Invariant under any smooth reparam | Invariant if orientation is preserved |
| Closed-curve result | Can be any value | Zero for conservative fields |
- Scalar:
- Vector:
More Worked Examples
Example A — Scalar line integral on a straight segment. Click to expand.
Compute where is the line segment from to .
Parametrize: for . Then and .
Substitute: .
Evaluate: .
Example B — Vector line integral on a parabola. Click to expand.
Compute where along the parabola from to .
Parametrize : , , .
Dot product times : .
Integrate: . (Matches the potential check from the worked example above.)
Example C — A non-conservative field around a closed loop. Click to expand.
Compute where and is the unit circle, counter-clockwise.
Parametrize: for . Velocity .
. Dot product: .
Integral: . Nonzero on a closed loop this field is not conservative.
Real-World Applications
Physics: Work and Circulation
Work by a force: when a particle traces path through a force field, the work done is . Gravity, electric forces on a charge, drag — all of them.
Circulation: for a fluid with velocity field , the circulation around a closed curve is — a measurement of how strongly the fluid rotates around that loop. Stokes' theorem will turn this into a surface integral of the curl.
Engineering: Mass and Charge of a Wire
For a wire along curve with linear density , the mass is . Replace with linear charge density and you get total charge. Pair this with electric/magnetic field knowledge and you can compute capacitance, inductance, and EMF of arbitrary wire shapes.
Machine Learning: Optimizer Trajectories
Gradient descent traces a path through the loss landscape. For a loss , the total change in loss along an update trajectory is . Since the optimizer steps in the negative gradient direction, this work integral is negative — that is just "the loss went down" written in vector-calculus form. It also explains why path-dependent regularizers (e.g. natural gradient, mirror descent) require this framework to analyze.
Python Implementation
Here is a clean Python implementation of both line integrals using the midpoint Riemann rule. We then test it on the exact worked example from above: on the parabola (gives mass ), and on the same curve (gives work ).
PyTorch Implementation (Differentiable)
Now we upgrade. PyTorch buys us two things on top of the Python version. First, vectorization: the inner for-loop disappears because we evaluate the integrand at all midpoints in a single tensor op. Second, differentiability: every input (the endpoints, the field parameters, the curve parameters) becomes something we can take a derivative with respect to via torch.autograd. The example below uses this to verify the Fundamental Theorem of Calculus on the upper limit: .
Test Your Understanding
Summary
- Scalar line integral : scalar function weighted by arc length. Compute via . Direction-independent.
- Vector line integral : vector field projected onto direction of motion. Compute via . Sign flips under reversal.
- Arc-length element : the conversion factor from parameter time to physical distance along the curve.
- Reduction to single-variable integration: in every case, the line integral collapses to via the parametrization.
- From Python to PyTorch: same Riemann-sum logic, but PyTorch vectorizes it and makes it differentiable end-to-end.
Looking ahead: in the next section, we will discover that for conservative (gradient) fields, the work integral depends only on the endpoints — not the path. This is the Fundamental Theorem for Line Integrals, the natural continuation of the worked example above where we recovered two different ways.