Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 39 · Projects and Practice

Project: Verifying the Big Theorems Numerically

Build small numerical tools to test Green's theorem, Stokes' theorem and the divergence theorem on fields of your choice, using Monte Carlo and grids.

Mathematical theorems are proved once and for all, but it is satisfying (and a good debugging habit) to test them on concrete examples. In this project you will write small numerical tools that compute both sides of Green's theorem, Stokes' theorem and the divergence theorem, and compare them. You will also use Monte Carlo integration to estimate a volume integral without any grid.

Throughout, the tools are calculators that apply the definitions; they approximate the integrals, so the two sides agree to a few digits, not exactly.

Tool 1: a line integral calculator

Everything about circulation reduces to summing F · Δr along short steps of a closed curve.

Python Line integral over any parametrized curve

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Tool 2: Green's theorem

Pick any smooth field ⟨P, Q⟩ and a region. Here we compare ∮ P dx + Q dy around a circle with the double integral of Q_x - P_y, computed on a polar grid.

Python Green's theorem: boundary versus region

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Tool 3: Monte Carlo integration and the divergence theorem

Monte Carlo integration estimates an integral over a region E by sampling random points in a simple box containing E:

Text
∭_E g dV ≈ (box volume) · average of g(p)·[p in E] over random points p

The error shrinks like 1/√N regardless of dimension, which makes it popular in high dimensions.

Let us test the divergence theorem for F = ⟨x³, y³, z³⟩ on the unit ball. The theorem says the flux equals ∭ 3(x² + y² + z²) dV = 12π/5 ≈ 7.5398. We estimate the volume integral with Monte Carlo, and the flux through the sphere with random points on the surface.

Python Divergence theorem with Monte Carlo

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The two Monte Carlo estimates and the exact value should agree to roughly two or three digits.

Tool 4: Stokes' theorem for a twisted surface

Test Stokes' theorem with a surface that is not flat: the paraboloid cap z = 1 - x² - y² for z ≥ 0, whose boundary is the unit circle in the xy-plane. Use F = ⟨y, z, x²⟩.

  • Circulation side: ∮ F · dr around the unit circle (where z = 0).
  • Surface side: curl F = ⟨∂(x²)/∂y - ∂z/∂z, ∂y/∂z - ∂(x²)/∂x, ∂z/∂x - ∂y/∂y⟩ = ⟨-1, -2x, -1⟩. For the upward normal on a graph z = g(x, y), the flux is ∬ (-P g_x - Q g_y + R) dA with P, Q, R the curl's components.
Python Stokes' theorem on a paraboloid cap

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Your turn

Choose one of these challenges and write the code in a new editor:

  1. Pick a different closed curve for Green's theorem (an ellipse, or a square split into four straight pieces) and confirm both sides.
  2. Use the divergence theorem on the cube [0, 2]³ with F = ⟨x y, y z, z x⟩. Compare six face integrals with a triple integral.
  3. Try the field F = ⟨-y, x⟩ / (x² + y²) in Green's theorem around the unit circle. The scalar curl is zero, but the circulation is not. Why does the theorem not apply?
  4. Estimate the volume of the intersection of two unit balls centered at (0, 0, 0) and (1, 0, 0) by Monte Carlo. (The exact value is 5π/12, from the standard lens-volume formula for two overlapping spheres.)

If a verification fails, check three things in order: the orientation of the curve or surface, the Jacobian or area factor, and whether the field is smooth in the whole region.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Monte Carlo integration estimates an integral by:

    Sampling random points in a box and averaging (with the region's indicator) approximates the integral; the error falls like 1/√N.
  2. 2. When a numerical check of Green's theorem fails on F = ⟨-y, x⟩ / (x² + y²) around the unit circle, the cause is:

    The hypotheses require smoothness throughout the enclosed region; the singularity at the origin breaks them.
  3. 3. Which orientation rule must hold in a Stokes check?

    Reversing either the curve or the normal changes the sign of one side.

Summary

  • You built numerical line integral, area and flux checkers.
  • Both sides of Green's, Stokes' and the divergence theorem agree to within numerical error.
  • Monte Carlo integration handles awkward regions without any limits of integration.
  • When a check fails, suspect orientation, area factors or a field singularity first.

You have reached the end of this track. Return to the Multivariable Calculus course page to review any chapter.