Single integrals add up slices along a line. Double integrals add up over a region in the plane. Triple integrals add up over a volume. Change of variables (polar, cylindrical, spherical) makes hard regions easy by matching the coordinate system to the geometry.
Double integrals
The double integral of f(x, y) over a region R gives the signed volume under the surface. Compute it as an iterated integral: integrate with respect to one variable, then the other.
Scheme
; Double integral of f(x,y) = x*y over [0,1] x [0,2]; = integral from 0 to 1 of (integral from 0 to 2 of x*y dy) dx; Inner: integral of x*y dy = x*y^2/2 evaluated 0 to 2 = 2x; Outer: integral of 2x dx from 0 to 1 = x^2 evaluated 0 to 1 = 1
(define (double-integrate f x0 x1 y0 y1 n)
(let* ((dx (/ (- x1 x0) n))
(dy (/ (- y1 y0) n))
(sum 0))
(do ((i 0 (+ i 1)))
((= i n) (* sum dx dy))
(do ((j 0 (+ j 1)))
((= j n))
(let ((x (+ x0 (* dx (+ i 0.5))))
(y (+ y0 (* dy (+ j 0.5)))))
(set! sum (+ sum (f x y))))))))
(define result
(double-integrate (lambda (x y) (* x y)) 0102200))
(display "Double integral of x*y over [0,1]x[0,2] = ")
(display result) (newline)
(display "Exact: 1")
Python
import numpy as np
n = 500
x = np.linspace(0, 1, n)
y = np.linspace(0, 2, n)
X, Y = np.meshgrid(x, y)
dx, dy = x[1]-x[0], y[1]-y[0]
result = np.sum(X * Y * dx * dy)
print(f"Double integral of x*y over [0,1]x[0,2] = {result:.4f}")
print(f"Exact: 1.0")
Triple integrals
Triple integrals extend the pattern to three dimensions. They compute mass, charge, or probability over a solid region. The setup is the same: slice, approximate, integrate.
Scheme
; Triple integral of 1 over the unit cube [0,1]^3; = volume of the unit cube = 1; For a more interesting example:; integral of (x + y + z) over [0,1]^3; = 3 * integral of x over [0,1] = 3 * 1/2 = 3/2
(define (triple-integrate f n)
(let* ((dx (/ 1.0 n)) (sum 0))
(do ((i 0 (+ i 1))) ((= i n) (* sum dx dx dx))
(do ((j 0 (+ j 1))) ((= j n))
(do ((k 0 (+ k 1))) ((= k n))
(let ((x (* dx (+ i 0.5)))
(y (* dx (+ j 0.5)))
(z (* dx (+ k 0.5))))
(set! sum (+ sum (f x y z)))))))))
(define result
(triple-integrate (lambda (x y z) (+ x y z)) 50))
(display "Triple integral of (x+y+z) over [0,1]^3 = ")
(display result) (newline)
(display "Exact: 3/2 = ") (display 1.5)
Python
# Triple integral of (x+y+z) over [0,1]^3import numpy as np
n = 50
dx = 1.0 / n
total = 0.0for i inrange(n):
for j inrange(n):
for k inrange(n):
x = dx * (i + 0.5)
y = dx * (j + 0.5)
z = dx * (k + 0.5)
total += (x + y + z)
result = total * dx**3print("Triple integral of (x+y+z) over [0,1]^3 = " + format(result, ".4f"))
print("Exact: 3/2 = 1.5")
Change of variables
When the region has circular, cylindrical, or spherical symmetry, switch coordinates. The Jacobian determinant accounts for how area/volume elements change: dA = r dr dθ in polar, dV = r dz dr dθ in cylindrical, dV = ρ² sin(φ) dρ dθ dφ in spherical.
Scheme
; Area of a disk of radius R using polar coordinates; integral from 0 to 2*pi of (integral from 0 to R of r dr) d_theta; = integral from 0 to 2*pi of R^2/2 d_theta = pi*R^2
(define pi 3.141592653589793)
(define R 3.0)
; Polar double integral
(define (polar-integrate f R n-r n-theta)
(let* ((dr (/ R n-r))
(dtheta (/ (* 2 pi) n-theta))
(sum 0))
(do ((i 0 (+ i 1))) ((= i n-r) (* sum dr dtheta))
(do ((j 0 (+ j 1))) ((= j n-theta))
(let* ((r (+ (* dr (+ i 0.5))))
(theta (* dtheta (+ j 0.5))))
; Jacobian: r
(set! sum (+ sum (* (f r theta) r))))))))
(define area
(polar-integrate (lambda (r theta) 1) R 200200))
(display "Area of disk R=3 (polar) = ") (display area) (newline)
(display "Exact: pi*R^2 = ") (display (* pi R R))
Python
# Area of disk R=3 using polar coordinatesimportmath
R = 3.0
n_r, n_theta = 200, 200
dr = R / n_r
dtheta = 2 * math.pi / n_theta
total = 0.0for i inrange(n_r):
r = dr * (i + 0.5)
for j inrange(n_theta):
total += r # integrand=1, Jacobian=r
area = total * dr * dtheta
print("Area of disk R=3 (polar) = " + format(area, ".4f"))
print("Exact: pi*R^2 = " + format(math.pi * R**2, ".4f"))