14. Area between curves
§4.2 through §4.4 built the definite integral as the area between a curve and the x-axis — y=0 was always the bottom boundary. Drop that restriction and let the bottom boundary be any curve g(x), and the same machinery computes the area between two curves. This is the first of eight lessons where the integral, once built, gets pointed at a geometric or physical quantity.
The formula
If f(x)\ge g(x) on [a,b], the region between them is a stack of thin vertical strips, each of height f(x)-g(x) and width dx:
A=\int_a^b\big[f(x)-g(x)\big]\,dx
This is nothing new — it's linearity of the integral (§4.0) applied to \int f\,dx-\int g\,dx — but the geometric reading, "top minus bottom," is the part worth internalising, because it's about to generalize in two directions.
When the curves cross
"Top minus bottom" only holds where the labels don't swap. If f and g cross inside [a,b], integrating f-g straight through cancels area instead of adding it — the piece where g>f contributes a negative amount that eats into the piece where f>g.
The fix: find every intersection point in [a,b], split the interval there, and on each sub-interval integrate whichever difference is positive:
A=\int_a^c\big[f(x)-g(x)\big]dx+\int_c^b\big[g(x)-f(x)\big]dx
for a single crossing at x=c. This is the same discipline as \int|f| whenever f changes sign (§4.3) — signed area only equals the geometric area once you account for where the sign flips.
Integrating with respect to y
Some regions are awkward as a function of x but clean as a function of y — a sideways parabola, or a region more naturally bounded left-and-right than top-and-bottom. Nothing in the derivation required the strips to be vertical; horizontal strips of width dy work identically, with right minus left playing the role of top minus bottom:
A=\int_c^d\big[f(y)-g(y)\big]\,dy
Which variable to integrate against is a choice, not a rule — pick whichever makes the boundary functions single-valued and easy to write down. The region between x=y^2 and x=y+2 is far more painful sliced vertically (the left boundary is two different branches of x=y^2 solved for y) than sliced horizontally, where both boundaries are already functions of y. This same "solve for the other variable when it's cleaner" choice reappears in §5.1 and §5.2's washer and shell methods.
Doing it in Python
Area between y=x+2 and y=x^2, first finding where they cross:
import sympy as sp
x = sp.Symbol('x')
f = x + 2
g = x**2
crossings = sp.solve(sp.Eq(f, g), x)
print(f"crossings: {crossings}")
a, b = crossings
area = sp.integrate(f - g, (x, a, b))
print(f"area between x+2 and x^2 on [{a}, {b}] = {area}")
The crossing-curves trap, shown two ways — integrate through the crossing blindly, then correctly by splitting:
import sympy as sp
x = sp.Symbol('x')
f, g = sp.cos(x), sp.sin(x)
crossing = sp.solve(sp.Eq(f, g), x, domain=sp.Interval(0, sp.pi))
c = crossing[0]
print(f"cos(x) = sin(x) at x = {c}")
wrong = sp.integrate(f - g, (x, 0, sp.pi))
print(f"integrate cos-sin straight through [0, pi] = {wrong} (nonsense: negative area)")
correct = sp.integrate(f - g, (x, 0, c)) + sp.integrate(g - f, (x, c, sp.pi))
print(f"split at the crossing, correct area = {sp.simplify(correct)}")
The same region, sliced both ways, confirming they agree:
import sympy as sp
x, y = sp.symbols('x y')
# region between x = y^2 and x = y + 2, sliced horizontally (right - left)
crossings_y = sp.solve(sp.Eq(y**2, y + 2), y)
a, b = crossings_y
area_dy = sp.integrate((y + 2) - y**2, (y, a, b))
print(f"sliced horizontally (dy): crossings at y = {crossings_y}, area = {area_dy}")
# same region sliced vertically needs two pieces (upper and lower branch of x=y^2)
area_dx_lower = sp.integrate(sp.sqrt(x) - (-sp.sqrt(x)), (x, 0, 1))
area_dx_upper = sp.integrate(sp.sqrt(x) - (x - 2), (x, 1, 4))
area_dx = area_dx_lower + area_dx_upper
print(f"sliced vertically (dx), two pieces stitched = {area_dx}")
Worked example
Find the area of the region bounded by y=\sin x and y=\cos x between x=0 and x=\pi.
First, find where they cross on this interval: $\sin x=\cos x\Rightarrow \tan x=1\Rightarrow x=\frac\pi4$.
Check which is on top on each piece. At x=0: \cos0=1>\sin0=0, so cosine is on top for x<\frac\pi4. At x=\frac\pi2: \sin\frac\pi2=1>\cos\frac\pi2=0, so sine is on top after the crossing.
A=\int_0^{\pi/4}(\cos x-\sin x)\,dx+\int_{\pi/4}^{\pi}(\sin x-\cos x)\,dx
=\Big[\sin x+\cos x\Big]_0^{\pi/4}+\Big[-\cos x-\sin x\Big]_{\pi/4}^{\pi}
First piece: \left(\frac{\sqrt2}2+\frac{\sqrt2}2\right)-(0+1)=\sqrt2-1.
Second piece: \big(1-0\big)-\left(-\frac{\sqrt2}2-\frac{\sqrt2}2\right)=1+\sqrt2.
A=(\sqrt2-1)+(1+\sqrt2)=\boxed{2\sqrt2}\approx2.828
Sanity check. Both curves stay within [-1,1] over an interval of length \pi\approx3.14, so the region's area should be well under the bounding rectangle's 2\pi\approx6.28 — and 2\sqrt2\approx2.83 fits comfortably. ✓ Skipping the split — integrating \cos x-\sin x straight through [0,\pi] — gives -2, the two crossing-sign pieces cancelling instead of adding, exactly the trap called out above.
Your turn
1. Find the area between y=x^2 and y=4 (a horizontal line).
2. Find the area between y=x^3 and y=x on [-1,1] — check for a crossing inside the interval first.
3. Set up (don't necessarily finish) the integral for the area between x=y^2-2 and x=y, choosing whichever variable makes the boundaries single-valued.
Solutions
1. Crossings: x^2=4\Rightarrow x=\pm2. Top is the line y=4:
A=\int_{-2}^{2}(4-x^2)\,dx=\left[4x-\frac{x^3}3\right]_{-2}^2=\left(8-\frac83\right)-\left(-8+\frac83\right)=16-\frac{16}3=\boxed{\frac{32}3}
2. x^3=x\Rightarrow x^3-x=0\Rightarrow x(x-1)(x+1)=0, crossings at x=-1,0,1. The outer two are the endpoints; the one at x=0 is strictly inside the interval, and it is the entire point of the problem.
Check which curve is on top on each piece — carefully, because negative numbers are where sign-checking goes wrong:
- On (-1,0), take x=-0.5: x^3=-0.125 and x=-0.5. Now -0.125>-0.5, so the cubic is on top here. (The cubic shrinks magnitudes below 1, and shrinking the magnitude of a negative number moves it up.)
- On (0,1), take x=0.5: x^3=0.125<0.5=x, so the line is on top.
The roles swap at the origin, so the integral must be split there, with each piece written top-minus-bottom in its own orientation:
A=\int_{-1}^0(x^3-x)\,dx+\int_0^1(x-x^3)\,dx
=\left[\frac{x^4}4-\frac{x^2}2\right]_{-1}^0+\left[\frac{x^2}2-\frac{x^4}4\right]_0^1=\left(0-\left(\tfrac14-\tfrac12\right)\right)+\left(\tfrac12-\tfrac14\right)=\frac14+\frac14=\boxed{\frac12}
Both halves come to \frac14, and that is what the odd symmetry buys you: since x and x^3 are both odd, the left region is the right region rotated 180° about the origin, so the two have equal area. It justifies the shortcut A=2\int_0^1(x-x^3)\,dx — but only once you know the pieces match.
What the symmetry does not do is rescue you from splitting. Integrate x-x^3 straight through and you get
\int_{-1}^{1}(x-x^3)\,dx=0
because the left piece contributes -\frac14 and cancels the right piece's +\frac14 exactly. Odd symmetry is not a safety net here — it is precisely the thing that makes the naive route fail, and fail silently, returning a tidy zero instead of an obviously broken answer. Always locate the interior crossings first.
3. Solved for x, both boundaries are already single-valued functions of y — no need to flip to x. Find the crossings: $y^2-2=y\Rightarrow y^2-y-2=0\Rightarrow(y-2)(y+1)=0$, so y=-1,2. Check which is on the right: at y=0, x=y=0 versus x=y^2-2=-2, so the line is on the right.
A=\int_{-1}^{2}\big[y-(y^2-2)\big]\,dy
(Sliced vertically instead, x=y^2-2 would need solving for y=\pm\sqrt{x+2} — two branches, more work for the same region.)
Check yourself in code
Compute two areas with SymPy: the area between y=x+2 and y=x^2 (find the crossings, then integrate top minus bottom between them), and the area between y=\sin x and y=\cos x on [0,\pi] split correctly at the crossing — plus the naive unsplit result as a contrast.
Print exactly this:
area between x+2 and x^2 on [-1, 2] = 9/2
area between sin(x) and cos(x), correctly split = 2*sqrt(2)
naive (no split) gives = -2
import sympy as sp
x = sp.Symbol('x')
f, g = x + 2, x**2
a, b = sp.solve(sp.Eq(f, g), x)
area1 = sp.integrate(f - g, (x, a, b))
print(f"area between x+2 and x^2 on [{a}, {b}] = ...")
f2, g2 = sp.cos(x), sp.sin(x)
c = sp.solve(sp.Eq(f2, g2), x, domain=sp.Interval(0, sp.pi))[0]
correct = sp.integrate(f2 - g2, (x, 0, c)) + sp.integrate(g2 - f2, (x, c, sp.pi))
wrong = sp.integrate(f2 - g2, (x, 0, sp.pi))
print("area between sin(x) and cos(x), correctly split = ...")
print("naive (no split) gives = ...")
import sympy as sp
x = sp.Symbol('x')
f, g = x + 2, x**2
a, b = sp.solve(sp.Eq(f, g), x)
area1 = sp.integrate(f - g, (x, a, b))
print(f"area between x+2 and x^2 on [{a}, {b}] = {area1}")
f2, g2 = sp.cos(x), sp.sin(x)
c = sp.solve(sp.Eq(f2, g2), x, domain=sp.Interval(0, sp.pi))[0]
correct = sp.simplify(sp.integrate(f2 - g2, (x, 0, c)) + sp.integrate(g2 - f2, (x, c, sp.pi)))
wrong = sp.integrate(f2 - g2, (x, 0, sp.pi))
print(f"area between sin(x) and cos(x), correctly split = {correct}")
print(f"naive (no split) gives = {wrong}")
Area between curves is still just \int(\text{top}-\text{bottom}), but two things generalize: crossings force a split into pieces where the sign of top-minus-bottom is constant, and the "top/bottom" roles can be played by "right/left" when integrating against y is the cleaner choice. Both ideas — splitting at a boundary swap, and choosing the integration variable that makes the boundaries single-valued — carry directly into the next two lessons, where the same region gets spun into a solid.
Next: when that region between two curves is revolved around an axis, the integral computes a volume instead of an area.