multivariable calc25 min

Double Integrals

Integrate functions of two variables over planar regions to find volumes, masses, and averages

0/9Not Started

Why This Matters

A single integral sums a function along a line segment. A double integral sums a function over a two-dimensional region -- a rectangle, a disk, or any bounded shape in the plane. If f(x, y) represents height above the xy-plane, the double integral gives the volume under the surface. If f represents density, the double integral gives the total mass.

The key computational tool is the iterated integral: you integrate with respect to one variable first (treating the other as a constant), then integrate the result with respect to the second variable. The region of integration determines the limits. Double integrals appear everywhere: computing probabilities over 2D distributions, finding centers of mass, averaging a quantity over an area, and computing flux through a surface. They are the bridge from single-variable integration to the full power of multivariable calculus.

Define Terms

Visual Model

Region RBounded area in xy-plane
f(x, y)Function to integrate
Inner IntegralIntegrate w.r.t. y (or x)
Outer IntegralIntegrate w.r.t. x (or y)
Riemann SumGrid of rectangles
Volume / MassResult of double integral
Order of IntegrationCan switch via Fubini

The full process at a glance. Click Start tour to walk through each step.

A double integral sums f(x,y) over a 2D region. Compute it as an iterated integral or approximate it with a Riemann sum on a grid.

Code Example

Code
// Double integral approximation using Riemann sums
// Integrate f(x, y) = x^2 + y^2 over the rectangle [0, 2] x [0, 3]

function f(x, y) {
  return x * x + y * y;
}

function doubleIntegral(fn, xMin, xMax, yMin, yMax, nx, ny) {
  const dx = (xMax - xMin) / nx;
  const dy = (yMax - yMin) / ny;
  let sum = 0;
  for (let i = 0; i < nx; i++) {
    const x = xMin + (i + 0.5) * dx;  // midpoint
    for (let j = 0; j < ny; j++) {
      const y = yMin + (j + 0.5) * dy;  // midpoint
      sum += fn(x, y) * dx * dy;
    }
  }
  return sum;
}

// Exact answer: integral of x^2+y^2 over [0,2]x[0,3]
// = (8/3)(3) + (2)(9) = 8 + 18 = 26
console.log("n=10:", doubleIntegral(f, 0, 2, 0, 3, 10, 10).toFixed(4));
console.log("n=100:", doubleIntegral(f, 0, 2, 0, 3, 100, 100).toFixed(4));
console.log("n=1000:", doubleIntegral(f, 0, 2, 0, 3, 1000, 1000).toFixed(4));
console.log("Exact: 26");

// Non-rectangular region: x from 0 to 1, y from 0 to x
// Integrate f(x, y) = x * y
function doubleIntegralTriangle(fn, n) {
  const dx = 1.0 / n;
  let sum = 0;
  for (let i = 0; i < n; i++) {
    const x = (i + 0.5) * dx;
    const yMax = x;  // upper limit depends on x
    const dy = yMax / n;
    for (let j = 0; j < n; j++) {
      const y = (j + 0.5) * dy;
      sum += fn(x, y) * dx * dy;
    }
  }
  return sum;
}

// Exact: 1/24
console.log("Triangle integral:", doubleIntegralTriangle((x, y) => x * y, 1000).toFixed(6));
console.log("Exact: 1/24 =", (1/24).toFixed(6));

Interactive Experiment

Try these exercises:

  • Compute the double integral of f(x,y) = 1 over a rectangle. The answer should equal the area of the rectangle. Verify this.
  • Increase the grid resolution from 10 to 100 to 1000. How does the error decrease? Is it halved or quartered when you double the grid?
  • Integrate f(x,y) = x^2 + y^2 over the unit disk x^2 + y^2 at most 1 by checking if each grid point lies inside the disk. Compare to the exact answer (pi/2).
  • Switch the order of integration for the triangle region. Instead of y from 0 to x, try x from y to 1 for y from 0 to 1. Do you get the same answer?
  • Try integrating a negative function and observe that the "volume" can be negative, just like area under a curve can be negative in single-variable calculus.

Quick Quiz

Coding Challenge

Double Integral Grid Approximation

Write a function called `approxDoubleIntegral` that takes n (number of grid divisions in each direction) and approximates the double integral of f(x, y) = sin(x) * cos(y) over the rectangle [0, pi] x [0, pi/2] using the midpoint rule. Return the result rounded to 4 decimal places as a string.

Loading editor...

Real-World Usage

Double integrals solve problems across many fields:

  • Probability: The probability that a 2D random variable falls in a region R is the double integral of the joint density function over R. The total integral over all space must equal 1.
  • Physics: Computing the mass, center of mass, and moment of inertia of a 2D object with variable density requires double integrals.
  • Computer graphics: Rendering uses integration over pixel areas (anti-aliasing), light source areas (soft shadows), and lens areas (depth of field).
  • Engineering: Stress and strain on a 2D cross-section are computed by integrating force distributions over the cross-sectional area.
  • Geographic information systems: Computing average elevation, total rainfall, or population over a geographic region involves double integration over irregular boundaries.

Connections