Lesson 12 of 18

Double Integral

Double Integrals

A double integral integrates a function of two variables over a 2D region:

Rf(x,y)dA\iint_R f(x,y)\, dA

Over a rectangular region [xa,xb]×[ya,yb][x_a, x_b] \times [y_a, y_b].

The Midpoint Rule in 2D

Divide the region into nx×nyn_x \times n_y small rectangles. Evaluate ff at each midpoint:

fdAijf(xi,yj)ΔxΔy\iint f\, dA \approx \sum_i \sum_j f(x_i, y_j) \cdot \Delta x \cdot \Delta y

Where xi=xa+(i+0.5)Δxx_i = x_a + (i + 0.5) \Delta x and yj=ya+(j+0.5)Δyy_j = y_a + (j + 0.5) \Delta y.

Geometric Meaning

  • 1dA\iint 1\, dA = area of the region
  • fdA\iint f\, dA = signed volume between z=f(x,y)z = f(x,y) and the xyxy-plane

Examples

1dA\iint 1\, dA over [0,3]×[0,4][0,3] \times [0,4] =12= 12 (area of 3×43 \times 4 rectangle)

(x+y)dA\iint (x+y)\, dA over [0,1]×[0,1][0,1] \times [0,1] =1= 1 (by exact integration: 12+12\frac{1}{2} + \frac{1}{2})

x2ydA\iint x^2 y\, dA over [0,2]×[0,3][0,2] \times [0,3] =8392=12= \frac{8}{3} \cdot \frac{9}{2} = 12

Fubini's Theorem

For continuous ff, you can integrate one variable at a time:

fdA=yayb[xaxbf(x,y)dx]dy\iint f\, dA = \int_{y_a}^{y_b} \left[ \int_{x_a}^{x_b} f(x,y)\, dx \right] dy

Your Task

Implement double double_integral(double (*f)(double, double), double xa, double xb, double ya, double yb, int nx, int ny) using the 2D midpoint rule.

TCC compiler loading...
Loading...
Click "Run" to execute your code.