Lesson 18 of 18

Green's Theorem

Green's Theorem

Green's theorem connects a line integral around a closed curve to a double integral over the enclosed region:

RPdx+Qdy=R(QxPy)dA\oint_{\partial R} P\,dx + Q\,dy = \iint_R \left(\frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y}\right) dA

This is one of the central results of vector calculus — it shows that circulation around the boundary equals the total curl inside.

Area Formula

A beautiful consequence: if we choose P=y/2P = -y/2, Q=x/2Q = x/2, then:

QxPy=12+12=1\frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y} = \frac{1}{2} + \frac{1}{2} = 1

So:

Area(R)=12R(ydx+xdy)\text{Area}(R) = \frac{1}{2} \oint_{\partial R} (-y\,dx + x\,dy)

Numerical Verification

We can verify Green's theorem numerically by computing both sides independently:

  1. Double integral side: integrate the curl Q/xP/y\partial Q/\partial x - \partial P/\partial y over RR
  2. Line integral side: integrate Pdx+QdyP\,dx + Q\,dy around the boundary

For P=yP = -y, Q=xQ = x over the unit square [0,1]×[0,1][0,1]\times[0,1]:

  • Curl: Q/xP/y=1(1)=2\partial Q/\partial x - \partial P/\partial y = 1 - (-1) = 2
  • Double integral: 2×Area=2×1=22 \times \text{Area} = 2 \times 1 = 2

Implementing the Double Integral Side

double greens_double_integral(
    double (*curl)(double, double),
    double ax, double bx, double ay, double by, int n) {
    double hx = (bx - ax) / n, hy = (by - ay) / n, sum = 0.0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            sum += curl(ax + i*hx, ay + j*hy) * hx * hy;
    return sum;
}

Your Task

Implement double greens_double_integral(curl, ax, bx, ay, by, n) that numerically integrates a curl function over the rectangle [ax,bx]×[ay,by][ax, bx] \times [ay, by].

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