BRAGA

02 Writing02-02 Notes02-02-282

Double Integral

Published 16 Apr 20269 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
∬Df(x,y) dx dy\iint_D f(x,y)\,dx\,dy
(1)

Deep Breakdown

What it tells me (Situation Awareness): A double integral extends the idea of a single integral from a line (1D) to a planar region (2D). Instead of summing thin rectangles of area f(x) dxf(x)\,dx along a line, you sum thin rectangular prisms of volume f(x,y) dx dyf(x,y)\,dx\,dy over a 2D domain DD. If f(x,y)≥0f(x,y) \geq 0, the result is the volume under the surface z=f(x,y)z = f(x,y) above the region DD. If ff is a joint probability density function (joint PDF), the integral over any region gives the probability that the random vector (X,Y)(X, Y) falls in that region. In DA/DS, double integrals appear in: joint distribution analysis (bivariate normal), computing expected values of functions of two random variables, marginalizing out one variable (marginalization = integrating out = one inner integral of the double integral), and in 2D kernel density estimation. They also underlie the derivation of the multivariate normal normalizing constant.

Flowchart

Yes (Fubini applies directly)No (non-rectangular D)YesNoDouble integral:iint_D f(x,y) dxdyIdentify theregion D andorder ofintegrationRectangularregion D = [a,b]x [c,d]?Inner integral: fixx, integrate overy from c to dExpress y limitsas functions ofx: y from g1(x)to g2(x)Outer integral:integrate resultover x from a tobResult: scalarvolume orprobabilityf is a joint PDF?Outer integral =marginaldistribution of XResult is volumeunder surface z= f(x,y) over D

Real-world use

Where it is used

Probability theory: computing probabilities from joint PDFs, marginal distributions, expectations of functions of two random variables. Bayesian inference: joint posterior over two parameters. Signal processing: 2D convolution (image filtering), 2D Fourier transforms. Spatial statistics: kernel density estimation over a 2D domain, computing expected values under bivariate distributions.

Problem it solves

Single integrals cannot capture two-dimensional accumulation. When two variables interact (joint distributions, surface areas, expected value of g(X,Y)g(X, Y)), you need to accumulate over both simultaneously. The double integral provides the exact theoretical answer by iterating single integrals.

How it solves the problem

By Fubini's theorem: for a continuous function on a rectangle D=[a,b]×[c,d]D = [a,b] \times [c,d]:

∬Df(x,y) dx dy=∫ab[∫cdf(x,y) dy]dx=∫cd[∫abf(x,y) dx]dy\iint_D f(x,y)\,dx\,dy = \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
(2)

You integrate with respect to one variable (treating the other as a constant) to get a function of the remaining variable, then integrate that. For non-rectangular regions, the inner limits become functions of the outer variable.

Example in a business

A marketing analytics team models joint click probability with a bivariate normal over (age, income). The probability that a user has age in [25,40][25, 40] and income in [40K,80K][40K, 80K] is a double integral of the bivariate normal PDF over that rectangle. Marginalizing to get the age-only distribution requires integrating out income: fage(x)=∫−∞∞f(x,y) dyf_{\text{age}}(x) = \int_{-\infty}^{\infty} f(x,y)\,dy, which is the inner integral of the double integral evaluated at each xx.

The formula, piece by piece

∬Df(x,y) dx dy\iint_D f(x,y)\,dx\,dy
(3)

Each symbol:

  • ∬\iint: double integral sign — sum over a 2D region
  • DD: the domain of integration, a region in the xyxy-plane
  • f(x,y)f(x,y): the integrand — height/density/weight at point (x,y)(x,y)
  • dx dydx\,dy: the infinitesimal area element (Δx⋅Δy\Delta x \cdot \Delta y in Riemann sum terms) Iterated form (rectangular region):
∬Df(x,y) dx dy=∫ab∫cdf(x,y) dy dx\iint_D f(x,y)\,dx\,dy = \int_a^b \int_c^d f(x,y)\,dy\,dx
(4)

Non-rectangular region (y-limits depend on x):

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

Change to polar coordinates (circular domains):

∬Df(x,y) dx dy=∬f(rcos⁡θ,rsin⁡θ) r dr dθ\iint_D f(x,y)\,dx\,dy = \iint f(r\cos\theta, r\sin\theta)\,r\,dr\,d\theta
(6)

(The extra rr is the Jacobian of the polar change of variables.)

The formula in words

"Chop the region DD into tiny rectangular cells of area Δx⋅Δy\Delta x \cdot \Delta y. At each cell (xi,yj)(x_i, y_j), the function value f(xi,yj)f(x_i, y_j) is the height of a tiny rectangular prism. Sum all those tiny volumes: ∑i,jf(xi,yj) Δx Δy\sum_{i,j} f(x_i, y_j)\,\Delta x\,\Delta y. As Δx,Δy→0\Delta x, \Delta y \to 0, this sum converges to the double integral." In practice (Fubini): "Fix xx, integrate over all yy-values in DD — this gives a 1D function g(x)g(x). Then integrate g(x)g(x) over all xx."

Critical Concepts

  • Fubini's theorem: order of integration is swappable for continuous ff on a closed bounded region. The result is identical regardless of which variable is inner.
  • Marginalization: for a joint PDF fX,Y(x,y)f_{X,Y}(x,y), the marginal is fX(x)=∫−∞∞fX,Y(x,y) dyf_X(x) = \int_{-\infty}^{\infty} f_{X,Y}(x,y)\,dy — the inner integral of a double integral.
  • Joint probability: P(X∈A,Y∈B)=∫A∫BfX,Y(x,y) dy dxP(X \in A, Y \in B) = \int_A \int_B f_{X,Y}(x,y)\,dy\,dx.
  • Expected value: E[g(X,Y)]=∬g(x,y) fX,Y(x,y) dx dyE[g(X,Y)] = \iint g(x,y)\,f_{X,Y}(x,y)\,dx\,dy.
  • Jacobian for change of variables: when switching from (x,y)(x,y) to (u,v)(u,v), the area element transforms: dx dy=∣J∣ du dvdx\,dy = |J|\,du\,dv where JJ is the determinant of the Jacobian matrix.
  • Bivariate normal: ∬R2N(x,y;μ,Σ) dx dy=1\iint_{\mathbb{R}^2} \mathcal{N}(x,y;\mu,\Sigma)\,dx\,dy = 1 is a double improper integral equal to 1, derivable via polar coordinates.
  • Numerical: scipy.integrate.dblquad computes double integrals numerically; for high-dimensional extensions, Monte Carlo integration is used.

Step-by-step calculation (tiny example)

Compute ∬D(x+y) dx dy\iint_D (x + y)\,dx\,dy where D=[0,1]×[0,2]D = [0,1] \times [0,2].

Step 1: Set up the iterated integral (integrate yy first)

∫01[∫02(x+y) dy]dx\int_0^1 \left[\int_0^2 (x + y)\,dy\right]dx
(7)

Step 2: Inner integral — integrate with respect to yy (treat xx as constant)

∫02(x+y) dy=[xy+y22]02=(2x+2)−0=2x+2\int_0^2 (x + y)\,dy = \left[xy + \frac{y^2}{2}\right]_0^2 = (2x + 2) - 0 = 2x + 2
(8)

Step 3: Outer integral — integrate result with respect to xx

∫01(2x+2) dx=[x2+2x]01=(1+2)−0=3\int_0^1 (2x + 2)\,dx = \left[x^2 + 2x\right]_0^1 = (1 + 2) - 0 = 3
(9)

Result: ∬D(x+y) dx dy=3\iint_D (x+y)\,dx\,dy = 3. Verification: swap order (integrate xx first) ∫02[∫01(x+y) dx]dy=∫02[x22+xy]01 dy=∫02(12+y) dy=[y2+y22]02=1+2=3\int_0^2 \left[\int_0^1 (x + y)\,dx\right]dy = \int_0^2 [\frac{x^2}{2} + xy]_0^1\,dy = \int_0^2 (\frac{1}{2} + y)\,dy = [\frac{y}{2} + \frac{y^2}{2}]_0^2 = 1 + 2 = 3

Code examples

Beginner example (Python)

python
import numpy as np
from scipy import integrate

def f(x: float, y: float) -> float:
    """Integrand: f(x, y) = x + y over [0,1] x [0,2]."""
    return x + y


# scipy.integrate.dblquad(f, x_lower, x_upper, y_lower_fn, y_upper_fn)
# Note: dblquad integrates y first (inner), then x (outer),
# and calls the integrand as func(y, x)
result, error = integrate.dblquad(
    lambda y, x: f(x, y),
    0, 1,  # x limits (outer)
    lambda x: 0,  # y lower limit (inner, can depend on x)
    lambda x: 2,  # y upper limit (inner, can depend on x)
)
print(f"Double integral (x+y) over [0,1]x[0,2]: {result:.6f}")  # 3.0
print(f"Error estimate: {error:.2e}")

# Verify with 2D Riemann sum (brute force approximation)
N = 1_000
x_vals = np.linspace(0, 1, N)
y_vals = np.linspace(0, 2, N)
dx = 1.0 / (N - 1)
dy = 2.0 / (N - 1)
xx, yy = np.meshgrid(x_vals, y_vals)
riemann_sum = float(np.sum(f(xx, yy)) * dx * dy)
print(f"Riemann sum (N={N}x{N}): {riemann_sum:.6f}")

Beginner example (R)

r
library(cubature)  # or use manual iterated integrate()
f <- function(x, y) x + y

# Method 1: iterated integrate() calls
inner_integral <- function(x) {
  integrate(function(y) f(x, y), lower = 0, upper = 2)$value
}
result <- integrate(Vectorize(inner_integral), lower = 0, upper = 1)$value
cat("Double integral (x+y) over [0,1]x[0,2]:", result, "\n")  # 3

# Method 2: 2D Riemann sum verification
n <- 500L
x_vals <- seq(0, 1, length.out = n)
y_vals <- seq(0, 2, length.out = n)
dx <- 1 / (n - 1)
dy <- 2 / (n - 1)
grid <- outer(x_vals, y_vals, FUN = f)  # n x n matrix of f values
riemann_sum <- sum(grid) * dx * dy
cat("Riemann sum (N=500x500): ", riemann_sum, "\n")

Professional example (Python)

python
"""
Double integral for bivariate normal marginalisation and joint probability.

Joint probability: P(0 < X < 1, 0 < Y < 1) for a bivariate normal.
Marginal: f_X(x) = int_{-inf}^{inf} f_{X,Y}(x,y) dy (inner integral).

Business context: model joint distribution of (click_propensity, purchase_propensity)
for a digital advertising segment. Compute the probability that both are > 0.5
(high-value users) and the marginal click distribution.
"""
import numpy as np
from scipy import integrate, stats

# Bivariate normal parameters
MU = np.array([0.6, 0.5])  # mean: (click_prop, purchase_prop)
SIGMA = np.array([[0.04, 0.02],  # covariance matrix
                  [0.02, 0.09]])
rv = stats.multivariate_normal(mean=MU, cov=SIGMA)


# Joint PDF
def joint_pdf(x: float, y: float) -> float:
    return float(rv.pdf([x, y]))


# P(X > 0.5, Y > 0.5): double integral from 0.5 to inf on both
# (dblquad calls the integrand as func(y, x))
p_high_value, error = integrate.dblquad(
    lambda y, x: joint_pdf(x, y),
    0.5, np.inf,  # x limits
    lambda x: 0.5,  # y lower
    lambda x: np.inf,  # y upper
)
print(f"P(click_prop > 0.5 AND purchase_prop > 0.5): {p_high_value:.4f}")
print(f"Integration error: {error:.2e}")


# Marginal of X (click_propensity) via inner integral over Y
def marginal_x(x: float) -> float:
    """f_X(x) = int_{-inf}^{inf} f_{X,Y}(x,y) dy"""
    result, _ = integrate.quad(lambda y: joint_pdf(x, y), -np.inf, np.inf)
    return result


# Compare to analytic marginal: Normal(mu_x, sigma_x^2)
x_test_points = np.array([0.4, 0.5, 0.6, 0.7, 0.8])
analytic_marginal = stats.norm(loc=MU[0], scale=np.sqrt(SIGMA[0, 0]))
print("\nMarginal PDF of click_propensity:")
print(f" {'x':>6} | {'Numerical':>12} | {'Analytic':>12} | {'Match':>8}")
for x_val in x_test_points:
    num = marginal_x(x_val)
    ana = float(analytic_marginal.pdf(x_val))
    match = abs(num - ana) < 1e-5
    print(f" {x_val:>6.2f} | {num:>12.6f} | {ana:>12.6f} | {str(match):>8}")

# Verify total probability = 1
total_prob, _ = integrate.dblquad(
    lambda y, x: joint_pdf(x, y),
    -np.inf, np.inf,
    lambda x: -np.inf,
    lambda x: np.inf,
)
print(f"\nTotal probability (double integral over R^2): {total_prob:.6f} (expected: 1.0)")

Source: 1300 p. 265

#calculus#integral-calculus#improper-integrals-multiple-integrals-and-volumes

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close