BRAGA

02 Writing02-02 Notes02-02-284

Triple 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
∭Vf(x,y,z) dx dy dz\iiint_V f(x,y,z)\,dx\,dy\,dz
(1)

Deep Breakdown

What it tells me (Situation Awareness): A triple integral extends integration to three-dimensional volumes. Instead of summing over a 2D region (area element dx dydx\,dy), you sum over a 3D region VV (volume element dx dy dzdx\,dy\,dz). If f(x,y,z)=1f(x,y,z) = 1, the triple integral gives the geometric volume of VV. If ff is a probability density function in 3D (joint PDF of three continuous random variables), the integral over a region gives the probability that the random vector (X,Y,Z)(X,Y,Z) falls in that region. In DA/DS, triple integrals appear most directly in: multivariate probability calculations involving three continuous features, Bayesian inference over three-parameter models (numerically via Monte Carlo), and spatial data science (3D kernel density estimation, LiDAR point cloud density). In practice, closed-form triple integrals are solved analytically only for simple regions and separable functions; otherwise Monte Carlo integration replaces nested numerical quadrature.

Flowchart

YesNo, f=1No, other fTriple integral:iiint_V f(x,y,z) dxdy dzIdentify thevolume V andlimitsWrite as iteratedintegral: 3nested singleintegralsInnermostintegral: fix xand y, integrateover zMiddle integral:fix x, integrateresult over yOuter integral:integrate finalresult over xf is a joint PDF?Result =probabilityP((X,Y,Z) in V)Result =geometricvolume of VResult =weighted sum /expectation overVForhigh-dimensional cases, useMonte Carlointegration

Real-world use

Where it is used

Multivariate probability: P(X∈A,Y∈B,Z∈C)P(X \in A, Y \in B, Z \in C) for continuous joint distributions. Marginalizing trivariate distributions down to bivariate by integrating out one variable (inner integral). Computing expectations E[g(X,Y,Z)]E[g(X,Y,Z)] for three-feature models. Computing 3D kernel density estimates over spatial data (geolocation + elevation, or geolocation + time). Bayesian posterior normalization over three hyperparameters.

Problem it solves

When three continuous variables interact simultaneously, a single or double integral is insufficient to describe their joint accumulation. Triple integrals provide the exact theoretical framework for 3D accumulation, though in practice Monte Carlo methods are used for anything beyond toy examples.

How it solves the problem

By Fubini's theorem extended to 3D: under mild continuity conditions, the integral over a box [a,b]×[c,d]×[e,f][a,b]\times[c,d]\times[e,f] can be evaluated as three nested 1D integrals in any order:

∭Vf dx dy dz=∫ab∫cd∫eff(x,y,z) dz dy dx\iiint_V f\,dx\,dy\,dz = \int_a^b\int_c^d\int_e^f f(x,y,z)\,dz\,dy\,dx
(2)

For spherical or cylindrical domains, change of variables (with the appropriate Jacobian: r2sin⁡ϕr^2\sin\phi for spherical, rr for cylindrical) simplifies the limits.

Example in a business

An e-commerce recommendation system models user engagement with a trivariate Gaussian over (session_duration, page_views, spend). The probability that all three metrics exceed their median (identifying high-value sessions) is a triple integral of the trivariate Gaussian PDF over the region [med1,∞)×[med2,∞)×[med3,∞)[\text{med}_1, \infty) \times [\text{med}_2, \infty) \times [\text{med}_3, \infty). This is computed numerically via scipy.integrate.tplquad or Monte Carlo sampling.

The formula, piece by piece

∭Vf(x,y,z) dx dy dz\iiint_V f(x,y,z)\,dx\,dy\,dz
(3)

Each symbol:

  • ∭\iiint: triple integral sign — sum over a 3D region
  • VV: the volume of integration, a region in 3D space
  • f(x,y,z)f(x,y,z): the integrand — density/height/weight at each 3D point
  • dx dy dzdx\,dy\,dz: the infinitesimal volume element (a tiny cube of sides dxdx, dydy, dzdz) Iterated form (box region):
∭Vf dV=∫ab∫cd∫eff(x,y,z) dz dy dx\iiint_V f\,dV = \int_a^b \int_c^d \int_e^f f(x,y,z)\,dz\,dy\,dx
(4)

Cylindrical coordinates (x=rcos⁡θx = r\cos\theta, y=rsin⁡θy = r\sin\theta, z=zz = z):

∭f dV=∭f(rcos⁡θ,rsin⁡θ,z) r dr dθ dz\iiint f\,dV = \iiint f(r\cos\theta, r\sin\theta, z)\,r\,dr\,d\theta\,dz
(5)

Spherical coordinates (x=rsin⁡ϕcos⁡θx = r\sin\phi\cos\theta, y=rsin⁡ϕsin⁡θy = r\sin\phi\sin\theta, z=rcos⁡ϕz = r\cos\phi):

∭f dV=∭f r2sin⁡ϕ dr dϕ dθ\iiint f\,dV = \iiint f\,r^2\sin\phi\,dr\,d\phi\,d\theta
(6)

The formula in words

"Chop the 3D region VV into tiny cubes of side lengths Δx\Delta x, Δy\Delta y, Δz\Delta z. At each cube located at (xi,yj,zk)(x_i, y_j, z_k), evaluate ff, multiply by the cube's volume Δx Δy Δz\Delta x\,\Delta y\,\Delta z, and sum over all cubes inside VV. As cube size goes to zero, this triple Riemann sum converges to the triple integral." In practice: "Integrate over zz (innermost), holding xx and yy fixed. This gives a 2D function. Then integrate over yy. Then over xx."

Critical Concepts

  • Fubini in 3D: all six orderings of (dx, dy, dz)(dx,\,dy,\,dz) give the same result for continuous ff on a closed bounded region.
  • Volume formula: when f(x,y,z)=1f(x,y,z) = 1, ∭V1 dV=volume of V\iiint_V 1\,dV = \text{volume of }V.
  • Joint PDF in 3D: requires ∭R3fX,Y,Z(x,y,z) dx dy dz=1\iiint_{\mathbb{R}^3} f_{X,Y,Z}(x,y,z)\,dx\,dy\,dz = 1.
  • Marginal: fX,Y(x,y)=∫−∞∞fX,Y,Z(x,y,z) dzf_{X,Y}(x,y) = \int_{-\infty}^{\infty} f_{X,Y,Z}(x,y,z)\,dz — the inner integral marginalizes out ZZ.
  • Monte Carlo for high dd: numerical dd-dimensional integration using nested quad becomes exponentially slow. For d≥3d \geq 3, Monte Carlo (sample (x,y,z)(x,y,z) from a proposal distribution and average ff values) converges at O(1/N)O(1/\sqrt{N}) regardless of dimension.
  • Jacobian for change of variables: changing from Cartesian to spherical or cylindrical introduces a Jacobian factor (rr in cylindrical, r2sin⁡ϕr^2\sin\phi in spherical).

Step-by-step calculation (tiny example)

Compute ∭V(x+y+z) dx dy dz\iiint_V (x + y + z)\,dx\,dy\,dz where V=[0,1]3V = [0,1]^3 (unit cube).

Step 1: Set up iterated integral

∫01∫01∫01(x+y+z) dz dy dx\int_0^1 \int_0^1 \int_0^1 (x + y + z)\,dz\,dy\,dx
(7)

Step 2: Innermost integral (over zz, treating x,yx, y as constants)

∫01(x+y+z) dz=[xz+yz+z22]01=x+y+12\int_0^1 (x + y + z)\,dz = \left[xz + yz + \frac{z^2}{2}\right]_0^1 = x + y + \frac{1}{2}
(8)

Step 3: Middle integral (over yy, treating xx as constant)

∫01(x+y+12)dy=[xy+y22+y2]01=x+12+12=x+1\int_0^1 \left(x + y + \frac{1}{2}\right)dy = \left[xy + \frac{y^2}{2} + \frac{y}{2}\right]_0^1 = x + \frac{1}{2} + \frac{1}{2} = x + 1
(9)

Step 4: Outer integral (over xx)

∫01(x+1) dx=[x22+x]01=12+1=32\int_0^1 (x + 1)\,dx = \left[\frac{x^2}{2} + x\right]_0^1 = \frac{1}{2} + 1 = \frac{3}{2}
(10)

Result: ∭[0,1]3(x+y+z) dx dy dz=32=1.5\iiint_{[0,1]^3} (x + y + z)\,dx\,dy\,dz = \frac{3}{2} = 1.5. By symmetry: E[X+Y+Z]E[X + Y + Z] for (X,Y,Z)∼Uniform([0,1]3)(X,Y,Z) \sim \text{Uniform}([0,1]^3) is E[X]+E[Y]+E[Z]=3×0.5=1.5E[X]+E[Y]+E[Z] = 3 \times 0.5 = 1.5

Code examples

Beginner example (Python)

python
import numpy as np
from scipy import integrate

def f(z: float, y: float, x: float) -> float:
    """Integrand: x + y + z. Note: scipy.tplquad takes z, y, x order."""
    return x + y + z


# scipy.integrate.tplquad(f, x_lower, x_upper, y_lower_fn, y_upper_fn, z_lower_fn, z_upper_fn)
# Function signature must be f(z, y, x) — innermost variable first
result, error = integrate.tplquad(
    f,
    0, 1,  # x limits (outermost)
    lambda x: 0,  # y lower
    lambda x: 1,  # y upper
    lambda x, y: 0,  # z lower (innermost)
    lambda x, y: 1,  # z upper
)
print(f"Triple integral (x+y+z) over [0,1]^3: {result:.6f}")  # 1.5
print(f"Error estimate: {error:.2e}")

# Monte Carlo verification (for high-D intuition)
N = 1_000_000
rng = np.random.default_rng(42)
samples = rng.uniform(0, 1, size=(N, 3))  # (x, y, z) from Uniform[0,1]^3
mc_estimate = float(np.mean(samples[:, 0] + samples[:, 1] + samples[:, 2]))
print(f"Monte Carlo estimate (N={N}): {mc_estimate:.6f} (expected: 1.5)")

Beginner example (R)

r
# Triple integral (x + y + z) over [0,1]^3 via iterated integrate()
inner <- function(z, x, y) x + y + z
middle <- function(y, x) {
  integrate(inner, lower = 0, upper = 1, x = x, y = y)$value
}
outer_fn <- function(x) {
  integrate(Vectorize(function(y) middle(y, x)), lower = 0, upper = 1)$value
}
result <- integrate(Vectorize(outer_fn), lower = 0, upper = 1)$value
cat("Triple integral (x+y+z) over [0,1]^3:", result, "\n")  # 1.5

# Monte Carlo verification
set.seed(42)
n_mc <- 1e6L
x_mc <- runif(n_mc); y_mc <- runif(n_mc); z_mc <- runif(n_mc)
mc_estimate <- mean(x_mc + y_mc + z_mc)
cat("Monte Carlo estimate:", mc_estimate, "\n")

Professional example (Python)

python
"""
Triple integral for trivariate Gaussian probability and Monte Carlo comparison.

Business context: a product team models three engagement signals jointly:
    X = log_session_duration (z-scored)
    Y = log_page_views (z-scored)
    Z = log_purchase_amount (z-scored)

Goal: P(X > 0, Y > 0, Z > 0) = P(all three above median) for a correlated model.
Analytically this is a triple integral; numerically we use Monte Carlo
(tplquad would be too slow for small correlations with infinite limits).
"""
import numpy as np
from scipy import stats

RANDOM_SEED = 42
rng = np.random.default_rng(RANDOM_SEED)

# Trivariate normal parameters (all z-scored, mean=0)
MU_3D = np.array([0.0, 0.0, 0.0])
# Correlation structure: moderate positive correlations
SIGMA_3D = np.array([
    [1.00, 0.40, 0.25],  # session_dur corr with page_views=0.4, purchase=0.25
    [0.40, 1.00, 0.35],  # page_views corr with purchase=0.35
    [0.25, 0.35, 1.00],
])
rv_3d = stats.multivariate_normal(mean=MU_3D, cov=SIGMA_3D)

# Monte Carlo: P(X > 0, Y > 0, Z > 0)
N_MC = 5_000_000
samples_3d = rng.multivariate_normal(MU_3D, SIGMA_3D, size=N_MC)
p_all_above_median_mc = float(np.mean(
    (samples_3d[:, 0] > 0) & (samples_3d[:, 1] > 0) & (samples_3d[:, 2] > 0)
))

# For independent standard normals, P(X>0,Y>0,Z>0) = 0.5^3 = 0.125
# With positive correlations, probability > 0.125
p_independent = 0.5**3  # baseline: no correlation

# Importance sampling estimate (more variance-efficient for tails)
# Here we simply report MC which is accurate for this central region
print("=== Trivariate Engagement Model ===")
print(f"P(X>0, Y>0, Z>0) independent: {p_independent:.4f} (no correlation baseline)")
print(f"P(X>0, Y>0, Z>0) Monte Carlo: {p_all_above_median_mc:.4f} (N={N_MC:,})")
print(f"Correlation boost factor: {p_all_above_median_mc / p_independent:.3f}x")
print()

# Verify: marginal probabilities (each should be 0.5 by symmetry)
p_x = float(np.mean(samples_3d[:, 0] > 0))
p_y = float(np.mean(samples_3d[:, 1] > 0))
p_z = float(np.mean(samples_3d[:, 2] > 0))
print(f"Marginal checks (should all be ~0.5):")
print(f" P(X > 0) = {p_x:.4f}")
print(f" P(Y > 0) = {p_y:.4f}")
print(f" P(Z > 0) = {p_z:.4f}")
print()

# Demonstrate marginalization (triple -> double -> single)
# f_XY(x,y) = int_{-inf}^{inf} f_{XYZ}(x,y,z) dz <- inner integral of triple
# Result should match bivariate normal marginal
x_test, y_test = 0.5, 0.3
marginal_xy_rv = stats.multivariate_normal(mean=MU_3D[:2], cov=SIGMA_3D[:2, :2])
marginal_pdf_analytic = float(marginal_xy_rv.pdf([x_test, y_test]))
print(f"Marginal f_XY({x_test},{y_test}) analytic: {marginal_pdf_analytic:.6f}")
print(f"[Note: equals int_{{-inf}}^{{inf}} f_XYZ({x_test},{y_test},z) dz]")
print(f"[In 3D, this is the inner integral of the triple integral]")

Source: 1300 p. 277

#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