Area Under and Between Curves
A definite integral gives signed area, which is not always what you want. This lesson shows how to get the real (geometric) area when a curve dips below the axis, and how to find the area trapped between two curves.
Signed area versus total area
counts area below the x-axis as negative. To get the total area, integrate the absolute value:
In practice you find where crosses zero, split the interval there, and flip the sign of the negative pieces. For on (zero at ):
Area between two curves
If on , the area between them is
It does not matter whether the curves are above or below the axis; only the vertical gap counts. The usual recipe:
- Find where the curves meet: solve . These are often the limits.
- Decide which curve is on top between those points (test one value).
- Integrate top minus bottom.
Example. The parabola and the line .
import sympy as sp
x = sp.symbols("x")
top, bottom = 4 - x**2, x + 2
a, b = sorted(sp.solve(sp.Eq(top, bottom), x))
print("curves meet at x =", a, "and", b)
print("area =", sp.integrate(top - bottom, (x, a, b)))
f = x**2 - 1
print("signed area of x^2-1 on [0,2]:", sp.integrate(f, (x, 0, 2)))
print("total area of x^2-1 on [0,2]:", -sp.integrate(f, (x, 0, 1)) + sp.integrate(f, (x, 1, 2)))curves meet at x = -2 and 1
area = 9/2
signed area of x^2-1 on [0,2]: 2/3
total area of x^2-1 on [0,2]: 2
import numpy as np
import matplotlib.pyplot as plt
xs = np.linspace(-2.5, 1.5, 300)
top, bottom = 4 - xs ** 2, xs + 2
inside = (xs >= -2) & (xs <= 1)
plt.figure(figsize=(6, 4))
plt.plot(xs, top, label="y = 4 − x²")
plt.plot(xs, bottom, label="y = x + 2")
plt.fill_between(xs, bottom, top, where=inside, alpha=0.3, label="area = 4.5")
plt.axhline(0, color="gray", linewidth=0.8)
plt.legend()
print("numerical check:", round(float(np.trapezoid((top - bottom)[inside], xs[inside])), 3))numerical check: 4.5
The trapezoid rule on 300 sample points agrees with the exact to three decimals.
Tip: If the curves cross inside the interval, the "top" curve changes. Split at every crossing, or integrate .
Integrating with respect to y
Sometimes a region is easier to describe sideways, as and . Then between the -limits. Example: the region between and has .
In software
- ML model evaluation: the AUC in AUC – ROC Curve is the area under the ROC curve, computed from points with the trapezoid rule.
- Probability: the chance that a value falls in a range is the area under its density (see The Definite Integral).
- Performance testing: the area between a "before" and an "after" latency curve over time measures total time saved.
- Graphics: filled shapes in vector graphics and font rendering use signed area (the shoelace formula is a discrete version) to decide winding and coverage.
Exercises
Exercise 1: Total area
Find the total area between and the x-axis on .
Answer
Solution
Exercise 2: Line and parabola
Find the area between and .
Answer
Solution
Exercise 3: Sine and cosine
Find the area between and from to .
Answer
Solution
The curves cross at , so split there:
import sympy as sp
x = sp.symbols("x")
A = sp.integrate(sp.Abs(sp.sin(x) - sp.cos(x)), (x, 0, sp.pi / 2))
print(sp.nsimplify(sp.simplify(A)), "≈", round(float(A), 4))-2 + 2*sqrt(2) ≈ 0.8284
Exercise 4: Area from samples
Two curves are only known as samples at : f = [5, 5.2, 5.5, 5.3, 5, 4.6, 4.4] and g = [1, 1.5, 2.2, 2.6, 3, 3.1, 3.4]. Estimate the area between them with the trapezoid rule.
Answer
7.85
Solution
import numpy as np
x = np.arange(0, 3.01, 0.5)
f = np.array([5, 5.2, 5.5, 5.3, 5, 4.6, 4.4])
g = np.array([1, 1.5, 2.2, 2.6, 3, 3.1, 3.4])
print(round(float(np.trapezoid(f - g, x)), 4))7.85
Test yourself
What is the area between and for ?
- 4
- 2
. What is the total area between and the x-axis on ?
- 0
- 2
- 1
What is the first step when finding the area between two curves without given limits?
- Differentiate both curves
- Solve to find where they meet
- Integrate each curve from 0
- Take the absolute value of each