TExcelTAD
Home › Calculus in Depth › Change of Variables in Multiple Integrals

Change of Variables in Multiple Integrals

Polar, cylindrical and spherical coordinates are special cases of one theorem: when you change variables in a multiple integral, the area or volume element is multiplied by the absolute value of the Jacobian determinant of the transformation. This lesson explains why, applies it to regions that no standard coordinate system fits, and shows the same formula at work in probability densities and in normalizing flows, a family of generative models in machine learning.

In one variable this is the substitution rule: ∫f(x) dx=∫f(g(u)) g′(u) du\int f(x)\,dx = \int f(g(u))\,g'(u)\,du. The survey treatment of Jacobians is Jacobian and Hessian.

Transformations and the Jacobian

A transformation T(u,v)=(x(u,v),y(u,v))T(u, v) = (x(u, v), y(u, v)) maps a region SS in the uvuv-plane onto a region RR in the xyxy-plane. We assume TT is C1C^1 (continuous first partials) and one-to-one, except perhaps on the boundary of SS. Its Jacobian is the determinant

∂(x,y)∂(u,v)=∣∂x∂u∂x∂v∂y∂u∂y∂v∣=xuyv−xvyu\frac{\partial(x, y)}{\partial(u, v)} = \begin{vmatrix} \dfrac{\partial x}{\partial u} & \dfrac{\partial x}{\partial v} \\[1ex] \dfrac{\partial y}{\partial u} & \dfrac{\partial y}{\partial v} \end{vmatrix} = x_u y_v - x_v y_u

Why it measures area. Take a tiny rectangle in the uvuv-plane with corner (u0,v0)(u_0, v_0) and sides Δu\Delta u, Δv\Delta v. Its image is a curved quadrilateral, approximately the parallelogram spanned by

a=T(u0+Δu,v0)−T(u0,v0)≈⟨xu,yu⟩ Δub=T(u0,v0+Δv)−T(u0,v0)≈⟨xv,yv⟩ Δv\begin{aligned} \mathbf{a} &= T(u_0 + \Delta u, v_0) - T(u_0, v_0) \approx \langle x_u, y_u \rangle\,\Delta u \\ \mathbf{b} &= T(u_0, v_0 + \Delta v) - T(u_0, v_0) \approx \langle x_v, y_v \rangle\,\Delta v \end{aligned}

whose area is ∣a×b∣=∣xuyv−xvyu∣ Δu Δv\lvert \mathbf{a} \times \mathbf{b} \rvert = \lvert x_u y_v - x_v y_u \rvert\,\Delta u\,\Delta v. So TT stretches small areas by the factor ∣∂(x,y)∂(u,v)∣\left\lvert \frac{\partial(x, y)}{\partial(u, v)} \right\rvert.

Change of variables theorem. With TT as above and ff continuous on RR,

∬Rf(x,y) dA=∬Sf(x(u,v),y(u,v))⋅∣∂(x,y)∂(u,v)∣ du dv\iint_R f(x, y)\,dA = \iint_S f(x(u, v), y(u, v)) \cdot \left\lvert \frac{\partial(x, y)}{\partial(u, v)} \right\rvert\,du\,dv

Note the absolute value: area is never negative. (In one variable no absolute value appears because a reversed interval ∫ba\int_b^a already supplies the sign.)

Check with polar coordinates, x=rcos⁡θx = r \cos\theta, y=rsin⁡θy = r \sin\theta:

∂(x,y)∂(r,θ)=cos⁡θ⋅rcos⁡θ−(−rsin⁡θ)⋅sin⁡θ=r\frac{\partial(x, y)}{\partial(r, \theta)} = \cos\theta \cdot r \cos\theta - (-r \sin\theta) \cdot \sin\theta = r

giving dA=r dr dθdA = r\,dr\,d\theta. In three variables the Jacobian is a 3×33 \times 3 determinant; for spherical coordinates its absolute value is ρ2sin⁡φ\rho^2 \sin\varphi (previous lesson).

Linear maps scale area by ∣det⁡∣\lvert \det \rvert

If TT is linear, T(u,v)=A⋅(u,v)T(u, v) = A \cdot (u, v) for a 2×22 \times 2 matrix AA, its Jacobian is the constant det⁡A\det A, so every region's area is multiplied by ∣det⁡A∣\lvert \det A \rvert. The sign of det⁡A\det A says whether TT preserves orientation (positive) or flips it like a mirror (negative). This is the geometric meaning of the determinant in Linear Algebra.

Example: a parallelogram region

Evaluate ∬R(x+y) ex−y dA\iint_R (x + y)\,e^{x - y}\,dA where RR is the parallelogram bounded by x+y=0x + y = 0, x+y=2x + y = 2, x−y=0x - y = 0, x−y=3x - y = 3. The boundary lines suggest u=x+yu = x + y, v=x−yv = x - y. Then SS is the rectangle 0≤u≤20 \le u \le 2, 0≤v≤30 \le v \le 3, and

x=u+v2,y=u−v2∂(x,y)∂(u,v)=12⋅(−12)−12⋅12=−12∣J∣=12∬R(x+y) ex−y dA=∫03∫02uev⋅12 du dv=12⋅2⋅(e3−1)=e3−1≈19.09\begin{aligned} &x = \frac{u + v}{2}, \qquad y = \frac{u - v}{2} \\ &\frac{\partial(x, y)}{\partial(u, v)} = \tfrac{1}{2} \cdot \left(-\tfrac{1}{2}\right) - \tfrac{1}{2} \cdot \tfrac{1}{2} = -\tfrac{1}{2} \qquad \lvert J \rvert = \tfrac{1}{2} \\[1ex] &\iint_R (x + y)\,e^{x-y}\,dA = \int_0^3 \int_0^2 u e^v \cdot \tfrac{1}{2}\,du\,dv = \tfrac{1}{2} \cdot 2 \cdot (e^3 - 1) = e^3 - 1 \approx 19.09 \end{aligned}

Tip: when it is easier to write uu, vv in terms of xx, yy, use ∂(x,y)∂(u,v)=1/∂(u,v)∂(x,y)\frac{\partial(x, y)}{\partial(u, v)} = 1 \Big/ \frac{\partial(u, v)}{\partial(x, y)}. Here ∂(u,v)∂(x,y)=(1)(−1)−(1)(1)=−2\frac{\partial(u, v)}{\partial(x, y)} = (1)(-1) - (1)(1) = -2, so ∣J∣=12\lvert J \rvert = \frac{1}{2} directly.

python · try it yourself
import sympy as sp
import numpy as np

u, v = sp.symbols("u v")
x, y = (u + v) / 2, (u - v) / 2
J = sp.Matrix([x, y]).jacobian([u, v]).det()
I = sp.integrate((x + y) * sp.exp(x - y) * sp.Abs(J), (u, 0, 2), (v, 0, 3))
print("Jacobian:", J, "  integral:", I, "≈", round(float(I), 6))

# independent check in x, y: midpoint grid on a bounding box, keeping points inside R
n = 2000
xs = (np.arange(n) + 0.5) * 2.5 / n
ys = -1.5 + (np.arange(n) + 0.5) * 2.5 / n
X, Y = np.meshgrid(xs, ys)
inside = (X + Y >= 0) & (X + Y <= 2) & (X - Y >= 0) & (X - Y <= 3)
print("grid in x, y   ≈", round(float(np.sum(((X + Y) * np.exp(X - Y))[inside]) * (2.5 / n)**2), 4))
Jacobian: -1/2   integral: -1 + exp(3) ≈ 19.085537
grid in x, y   ≈ 19.1102

The grid estimate is off in the second decimal because grid cells straddle the slanted edges of RR; the substitution gives the exact value with no effort.

Example: an ellipse

The area of the ellipse x2a2+y2b2≤1\frac{x^2}{a^2} + \frac{y^2}{b^2} \le 1: put x=aux = au, y=bvy = bv, which maps the unit disk onto the ellipse with Jacobian abab. So the area is ab⋅πab \cdot \pi. Integrals over ellipsoids reduce to balls in the same way (∣J∣=abc\lvert J \rvert = abc, volume 43πabc\frac{4}{3}\pi abc).

In probability and ML: densities transform with the Jacobian

If a random vector ZZ has density pZp_Z and X=T(Z)X = T(Z) with TT invertible and differentiable, then probability mass is preserved, pX(x) dx=pZ(z) dzp_X(x)\,dx = p_Z(z)\,dz, so

pX(x)=pZ(T−1(x))⋅∣det⁡JT−1(x)∣log⁡pX(x)=log⁡pZ(z)−log⁡∣det⁡JT(z)∣,z=T−1(x)\begin{aligned} p_X(x) &= p_Z(T^{-1}(x)) \cdot \lvert \det J_{T^{-1}}(x) \rvert \\ \log p_X(x) &= \log p_Z(z) - \log \lvert \det J_T(z) \rvert, \qquad z = T^{-1}(x) \end{aligned}

Normalizing flows (RealNVP, Glow, neural spline flows) are generative models built on exactly this formula. They chain simple invertible layers whose Jacobian determinants are cheap (often triangular matrices, whose determinant is the product of the diagonal), push a standard normal through them, and train by maximising the exact log-likelihood above. The design problem of flows is "invertible, expressive, and with an easy det⁡J\det J".

python · try it yourself
import numpy as np

rng = np.random.default_rng(5)
# a tiny 2D "flow": an affine coupling layer  x1 = z1,  x2 = z2·exp(s(z1)) + t(z1)
s = lambda z1: 0.5 * np.tanh(z1)
t = lambda z1: z1**2

def forward(z):
    z1, z2 = z[:, 0], z[:, 1]
    return np.stack([z1, z2 * np.exp(s(z1)) + t(z1)], axis=1), s(z1)   # log|det J| = s(z1)

def log_px(x):
    z1 = x[:, 0]
    z2 = (x[:, 1] - t(z1)) * np.exp(-s(z1))                         # inverse map
    log_pz = -0.5 * (z1**2 + z2**2) - np.log(2 * np.pi)
    return log_pz - s(z1)                                            # change of variables

# 1) the transformed density still integrates to 1 (grid sum over a large box)
h = 0.02                                          # midpoint grid, x2 up to 42 (x2 = z2·e^s + z1²)
g1, g2 = -6 + h * (np.arange(600) + 0.5), -6 + h * (np.arange(2400) + 0.5)
X1, X2 = np.meshgrid(g1, g2, indexing="ij")
dA = h * h
P = np.exp(log_px(np.stack([X1.ravel(), X2.ravel()], axis=1)))
print("∬ p_X dA ≈", round(float(P.sum() * dA), 4))

# 2) samples pushed through the flow match the formula: P(X2 > 2)
x, _ = forward(rng.standard_normal((200_000, 2)))
mask = X2.ravel() > 2
print("P(X2 > 2): samples", round(float(np.mean(x[:, 1] > 2)), 4),
      "  formula", round(float(P[mask].sum() * dA), 4))
∬ p_X dA ≈ 1.0
P(X2 > 2): samples 0.2123   formula 0.2122

Without the −log⁡∣det⁡J∣-\log \lvert \det J \rvert term the "density" would not integrate to 1 and the model's likelihoods would be meaningless.

Other places the Jacobian determinant appears in software:

  • Sampling. Uniform disk sampling r=ur = \sqrt{u}, θ=2πv\theta = 2\pi v and Box–Muller for normal random numbers are change-of-variables results (see Triple Integrals in Cylindrical Coordinates).
  • Rendering. Converting a light integral from solid angle to surface area uses the Jacobian cos⁡θ′/d2\cos\theta'/d^2, and texture-space to world-space integrals use the mesh's UV Jacobian.
  • Finite elements and physics. Every element integral is mapped to a reference triangle or cube and multiplied by ∣det⁡J∣\lvert \det J \rvert of the element map; a negative det⁡J\det J signals an inverted (tangled) element, a classic simulation failure.

Exercises

Exercise 1: A Jacobian

Find ∂(x,y)∂(u,v)\frac{\partial(x, y)}{\partial(u, v)} for x=u2−v2x = u^2 - v^2, y=2uvy = 2uv, and evaluate it at (u,v)=(1,2)(u, v) = (1, 2).

Answer

4(u2+v2)4(u^2 + v^2); at (1,2)(1, 2) it is 20.

Solution
xu=2u,xv=−2v,yu=2v,yv=2uJ=2u⋅2u−(−2v)(2v)=4u2+4v2=4(u2+v2)(1,2):4⋅5=20\begin{aligned} &x_u = 2u, \quad x_v = -2v, \quad y_u = 2v, \quad y_v = 2u \\ &J = 2u \cdot 2u - (-2v)(2v) = 4u^2 + 4v^2 = 4(u^2 + v^2) \\ &(1, 2)\text{:} \quad 4 \cdot 5 = 20 \end{aligned}

This is the map z↦z2z \mapsto z^2 of complex numbers; ∣J∣=∣2z∣2\lvert J \rvert = \lvert 2z \rvert^2.

Exercise 2: A rotated square

Evaluate ∬R(x−y)2 dA\iint_R (x - y)^2\,dA over the square with vertices (0,0)(0, 0), (1,1)(1, 1), (2,0)(2, 0), (1,−1)(1, -1).

Answer

83≈2.667\frac{8}{3} \approx 2.667.

Solution

The sides lie on x+y=0x + y = 0, x+y=2x + y = 2, x−y=0x - y = 0, x−y=2x - y = 2. Put u=x+yu = x + y, v=x−yv = x - y: S=[0,2]×[0,2]S = [0, 2] \times [0, 2], ∣J∣=12\lvert J \rvert = \frac{1}{2}.

∫02∫02v2⋅12 du dv=12⋅2⋅83=83\int_0^2 \int_0^2 v^2 \cdot \tfrac{1}{2}\,du\,dv = \tfrac{1}{2} \cdot 2 \cdot \frac{8}{3} = \frac{8}{3}

Exercise 3: Ellipse integral

Compute ∬Ex2 dA\iint_E x^2\,dA over the ellipse x29+y24≤1\frac{x^2}{9} + \frac{y^2}{4} \le 1.

Answer

27π2≈42.41\frac{27\pi}{2} \approx 42.41.

Solution

x=3ux = 3u, y=2vy = 2v maps the unit disk DD onto EE, ∣J∣=6\lvert J \rvert = 6.

∬D9u2⋅6 du dv=54∫02π∫01r2cos⁡2θ⋅r dr dθ=54⋅14⋅π=27π2\iint_D 9u^2 \cdot 6\,du\,dv = 54 \int_0^{2\pi} \int_0^1 r^2 \cos^2\theta \cdot r\,dr\,d\theta = 54 \cdot \tfrac{1}{4} \cdot \pi = \frac{27\pi}{2}

Exercise 4: Density of a transformed variable (code)

If ZZ is uniform on [0,1][0, 1] and X=−ln⁡(Z)/λX = -\ln(Z)/\lambda with λ=2\lambda = 2, use the change-of-variables formula to find the density of XX, then check P(X≤0.5)P(X \le 0.5) by simulation.

Answer

pX(x)=2e−2xp_X(x) = 2e^{-2x} for x≥0x \ge 0 (exponential); P(X≤0.5)=1−e−1≈0.6321P(X \le 0.5) = 1 - e^{-1} \approx 0.6321.

Solution
z=T−1(x)=e−λx,∣dzdx∣=λe−λxpX(x)=pZ(e−λx)⋅λe−λx=λe−λx\begin{aligned} z &= T^{-1}(x) = e^{-\lambda x}, \qquad \left\lvert \frac{dz}{dx} \right\rvert = \lambda e^{-\lambda x} \\ p_X(x) &= p_Z(e^{-\lambda x}) \cdot \lambda e^{-\lambda x} = \lambda e^{-\lambda x} \end{aligned}

This is inverse-transform sampling of the exponential distribution.

python · try it yourself
import numpy as np
rng = np.random.default_rng(8)
X = -np.log(rng.random(100_000)) / 2
print(round(float(np.mean(X <= 0.5)), 4), round(1 - np.exp(-1), 4))
0.6335 0.6321

Test yourself

In the change of variables formula, dAdA becomes…

  1. ∂(x,y)∂(u,v) du dv\frac{\partial(x, y)}{\partial(u, v)}\,du\,dv
  2. ∣∂(x,y)∂(u,v)∣ du dv\left\lvert \frac{\partial(x, y)}{\partial(u, v)} \right\rvert\,du\,dv
  3. ∂(u,v)∂(x,y) du dv\frac{\partial(u, v)}{\partial(x, y)}\,du\,dv
  4. du dvdu\,dv

A linear map has matrix [2113]\begin{bmatrix} 2 & 1 \\ 1 & 3 \end{bmatrix}. A region of area 4 is mapped to a region of area…

  1. 4
  2. 20
  3. 24
  4. 28

In a normalizing flow x=T(z)x = T(z), the log-density is log⁡pX(x)=log⁡pZ(z)\log p_X(x) = \log p_Z(z) …

  1. +log⁡∣det⁡JT(z)∣+ \log \lvert \det J_T(z) \rvert
  2. −log⁡∣det⁡JT(z)∣- \log \lvert \det J_T(z) \rvert
  3. ⋅det⁡JT(z)\cdot \det J_T(z)
  4. unchanged