TExcelTAD
Home › Calculus Essentials › Double and Triple Integrals

Double and Triple Integrals

A single integral adds up a quantity along an interval. A double integral adds it up over a region of the plane, and a triple integral over a solid in space. They give volumes, masses, averages and probabilities, and they are computed as one ordinary integral inside another.

The double integral as a volume

For f(x,y)≥0f(x, y) \ge 0 on a region DD, the double integral ∬Df(x,y) dA\iint_D f(x, y) \, dA is the volume between the surface z=f(x,y)z = f(x, y) and the region DD in the xy-plane. It is defined like a Riemann sum: chop DD into small rectangles of area ΔA\Delta A, multiply each by the height ff at a sample point, add, and let the rectangles shrink:

∬Df dA=lim⁡∑f(xi,yi) ΔA\iint_D f \, dA = \lim \sum f(x_i, y_i) \, \Delta A

With f=1f = 1 the integral is simply the area of DD. Dividing ∬f dA\iint f \, dA by the area gives the average value of ff over DD.

Iterated integrals (Fubini)

On a rectangle a≤x≤ba \le x \le b, c≤y≤dc \le y \le d, the double integral can be computed as two single integrals, in either order:

∬Rf dA=∫ab(∫cdf(x,y) dy)dx=∫cd(∫abf(x,y) dx)dy\iint_R f \, dA = \int_a^b \left( \int_c^d f(x, y) \, dy \right) dx = \int_c^d \left( \int_a^b f(x, y) \, dx \right) dy

Do the inner integral treating the outer variable as a constant (like a partial derivative in reverse), then integrate the result.

Example. ∬(x+2y) dA\iint (x + 2y) \, dA over 0≤x≤20 \le x \le 2, 0≤y≤10 \le y \le 1:

inner: ∫01(x+2y) dy=[xy+y2]01=x+1outer: ∫02(x+1) dx=[x2/2+x]02=2+2=4\begin{aligned} \text{inner: } & \int_0^1 (x + 2y) \, dy = \Big[xy + y^2\Big]_0^1 = x + 1 \\ \text{outer: } & \int_0^2 (x + 1) \, dx = \Big[x^2/2 + x\Big]_0^2 = 2 + 2 = 4 \end{aligned}

Non-rectangular regions

If DD lies between two curves, g1(x)≤y≤g2(x)g_1(x) \le y \le g_2(x) for a≤x≤ba \le x \le b, the inner limits become functions:

∬Df dA=∫ab∫g1(x)g2(x)f(x,y) dy dx\iint_D f \, dA = \int_a^b \int_{g_1(x)}^{g_2(x)} f(x, y) \, dy \, dx

Sketch the region first. Sometimes swapping the order of integration turns an impossible inner integral into an easy one.

python · try it yourself
import sympy as sp

x, y = sp.symbols('x y')

# rectangle example from above
print("rectangle:", sp.integrate(x + 2*y, (y, 0, 1), (x, 0, 2)))

# region between y = x² and y = x (0 <= x <= 1), integrand f = x*y
D1 = sp.integrate(x*y, (y, x**2, x), (x, 0, 1))
D2 = sp.integrate(x*y, (x, y, sp.sqrt(y)), (y, 0, 1))     # same region, other order
print("between curves, dy dx:", D1, "  dx dy:", D2)
print("area of that region  :", sp.integrate(1, (y, x**2, x), (x, 0, 1)))
rectangle: 4
between curves, dy dx: 1/24   dx dy: 1/24
area of that region  : 1/6

SymPy's integrate(f, (y, …), (x, …)) integrates in the order listed: the first tuple is the inner integral.

Polar coordinates

For discs, rings and sectors, use x=rcos⁡θx = r\cos\theta, y=rsin⁡θy = r\sin\theta. A small polar "rectangle" dr×dθdr \times d\theta has area r dr dθr \, dr \, d\theta, not dr dθdr \, d\theta, because the arc length of a dθd\theta wedge grows with rr. That factor rr is the Jacobian determinant of the change of variables:

∬Df dA=∬f(rcos⁡θ,rsin⁡θ)⋅r dr dθ\iint_D f \, dA = \iint f(r\cos\theta, r\sin\theta) \cdot r \, dr \, d\theta

A famous case is the Gaussian over the whole plane, ∬e−(x2+y2) dA=∫02π∫0∞e−r2r dr dθ=2π⋅12=π\iint e^{-(x^2 + y^2)} \, dA = \int_0^{2\pi} \int_0^\infty e^{-r^2} r \, dr \, d\theta = 2\pi \cdot \frac{1}{2} = \pi. Taking the square root gives ∫e−x2 dx=π\int e^{-x^2} \, dx = \sqrt{\pi} over the real line, the constant inside the normal distribution.

Triple integrals

A triple integral ∭Ef dV\iiint_E f \, dV adds ff over a solid EE. With f=1f = 1 it is the volume; with f=densityf = \text{density} it is the mass. It is computed as three nested integrals. Cylindrical (dV=r dz dr dθdV = r \, dz \, dr \, d\theta) and spherical (dV=ρ2sin⁡φ dρ dφ dθdV = \rho^2 \sin\varphi \, d\rho \, d\varphi \, d\theta) coordinates handle round solids.

python · try it yourself
import sympy as sp

x, y, z, r, th, rho, phi = sp.symbols('x y z r theta rho phi', nonnegative=True)

gauss = sp.integrate(sp.exp(-r**2) * r, (r, 0, sp.oo), (th, 0, 2*sp.pi))
print("Gaussian over the plane:", gauss)

# volume of the solid under z = 4 - x^2 - y^2 above the xy-plane (polar)
print("paraboloid volume:", sp.integrate((4 - r**2) * r, (r, 0, 2), (th, 0, 2*sp.pi)))

# volume of a ball of radius R (spherical)
R = sp.symbols('R', positive=True)
print("ball volume:", sp.integrate(rho**2 * sp.sin(phi), (rho, 0, R), (phi, 0, sp.pi), (th, 0, 2*sp.pi)))

# mass of the unit cube with density x + y + z
print("cube mass:", sp.integrate(x + y + z, (x, 0, 1), (y, 0, 1), (z, 0, 1)))
Gaussian over the plane: pi
paraboloid volume: 8*pi
ball volume: 4*pi*R**3/3
cube mass: 3/2

Monte Carlo integration

In many dimensions, or over awkward regions, nested formulas become impractical. Monte Carlo integration samples random points, averages ff at them, and multiplies by the volume of the sampling box. Its error shrinks like 1/N1/\sqrt{N} regardless of the number of dimensions, which is why it rules in high dimensions. See also Numerical Integration.

python · try it yourself
import numpy as np

rng = np.random.default_rng(42)
N = 200_000
pts = rng.uniform(-1, 1, size=(N, 3))            # box [-1, 1]^3, volume 8
inside = np.sum(pts**2, axis=1) <= 1
print("ball volume  ≈", round(8 * inside.mean(), 4), " exact", round(4 / 3 * np.pi, 4))

# mass of the ball with density 1 + z^2
f = np.where(inside, 1 + pts[:, 2]**2, 0.0)
print("ball mass    ≈", round(8 * f.mean(), 4), " exact", round(4 / 3 * np.pi + 4 * np.pi / 15, 4))
ball volume  ≈ 4.2017  exact 4.1888
ball mass    ≈ 5.0462  exact 5.0265

In software

  • Rendering. The light reaching a pixel is an integral over the pixel's area, the lens, the directions of incoming light and time. Path tracers estimate it with Monte Carlo, which is why their images start noisy and clean up as samples accumulate.
  • Probability and statistics. For two random variables with joint density p(x,y)p(x, y), probabilities are double integrals: P((X,Y)∈D)=∬Dp dAP((X, Y) \in D) = \iint_D p \, dA. Expected values are integrals of x⋅px \cdot p.
  • Physics and games. Mass, centre of mass and moment of inertia of a body are volume integrals; engines compute them once per shape to set up rigid-body dynamics (Rotation Dynamics).

Exercises

Exercise 1: Rectangle

Compute ∬6xy2 dA\iint 6xy^2 \, dA over 0≤x≤10 \le x \le 1, 1≤y≤21 \le y \le 2.

Answer
Solution
inner: ∫126xy2 dy=6x⋅[y3/3]12=6x⋅(7/3)=14xouter: ∫0114x dx=7\begin{aligned} \text{inner: } & \int_1^2 6xy^2 \, dy = 6x \cdot \Big[y^3/3\Big]_1^2 = 6x \cdot (7/3) = 14x \\ \text{outer: } & \int_0^1 14x \, dx = 7 \end{aligned}

Exercise 2: Triangle

Find ∬Dx dA\iint_D x \, dA where DD is the triangle with corners (0, 0), (2, 0), (0, 2).

Answer

4/3.

Solution

The triangle is 0≤x≤20 \le x \le 2, 0≤y≤2−x0 \le y \le 2 - x.

inner: ∫02−xx dy=x(2−x)outer: ∫02(2x−x2) dx=[x2−x3/3]02=4−8/3=4/3\begin{aligned} \text{inner: } & \int_0^{2-x} x \, dy = x(2 - x) \\ \text{outer: } & \int_0^2 (2x - x^2) \, dx = \Big[x^2 - x^3/3\Big]_0^2 = 4 - 8/3 = 4/3 \end{aligned}

Exercise 3: Polar area

Use polar coordinates to find the area of the ring 1≤r≤31 \le r \le 3.

Answer

8π≈25.138\pi \approx 25.13.

Solution
∫02π∫13r dr dθ=2π⋅[r2/2]13=2π⋅(9−1)/2=8π\int_0^{2\pi} \int_1^3 r \, dr \, d\theta = 2\pi \cdot \Big[r^2/2\Big]_1^3 = 2\pi \cdot (9 - 1)/2 = 8\pi

Check: π⋅32−π⋅12=8π\pi \cdot 3^2 - \pi \cdot 1^2 = 8\pi.

Exercise 4: Monte Carlo check (code)

Estimate ∬e−(x2+y2) dA\iint e^{-(x^2 + y^2)} \, dA over the square [−3,3]×[−3,3][-3, 3] \times [-3, 3] by Monte Carlo with 100 000 points (seed 1), and compare with π\pi (the tails outside the square are tiny).

Answer

The estimate is about 3.155, within about 0.014 of π≈3.1416\pi \approx 3.1416 (Monte Carlo error with N=100 000N = 100\,000 is of that order).

Solution

The box has area 36, so the estimate is 36×(mean of f at random points)36 \times (\text{mean of } f \text{ at random points}).

python · try it yourself
import numpy as np
rng = np.random.default_rng(1)
p = rng.uniform(-3, 3, size=(100_000, 2))
est = 36 * np.mean(np.exp(-(p**2).sum(axis=1)))
print(round(float(est), 4), round(float(np.pi), 4))
3.1551 3.1416

Test yourself

In polar coordinates, dAdA equals…

  1. dr dθdr \, d\theta
  2. r dr dθr \, dr \, d\theta
  3. r2 dr dθr^2 \, dr \, d\theta
  4. dr dθ/rdr \, d\theta / r

What does ∬D1 dA\iint_D 1 \, dA compute?

  1. The perimeter of DD
  2. The area of DD
  3. The volume above DD
  4. Zero

Why is Monte Carlo integration popular in high dimensions?

  1. It is exact
  2. Its error shrinks like 1/N1/\sqrt{N} regardless of dimension
  3. It needs no random numbers
  4. It only works in 3D