A920 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A9 · Lesson 20 · Lab: multiple integrals

Grids, random points and coordinate changes

Lessons 14 to 19 evaluated integrals over regions by slicing and by changing coordinates. Most real regions and integrands don't have antiderivatives, and engineers integrate them numerically. In this lab you'll integrate over a non-rectangular region on a grid, estimate a volume by throwing random points, check the Gaussian-beam power formula in polar coordinates, find the centroid of a semicircular plate, and confirm the spherical Jacobian numerically.

  • Monte Carlo integration estimates an area or volume as the fraction of random points that land inside, times the box's size.
  • The curve shows how its typical error shrinks with the number of points N: as 1/N.
  • A grid rule's error in two dimensions shrinks much faster for smooth integrands, but in ten dimensions Monte Carlo wins, because its rate doesn't depend on the dimension.

Predict

A Monte Carlo estimate uses 10 000 points and has about 1% error. How many points would give 0.1%?

Name it

Grid rules in two dimensions

The midpoint rule samples the integrand at the center of each small cell and adds fΔxΔy. A region that isn't a rectangle can be handled by multiplying by an indicator that is 1 inside and 0 outside, though the jagged edge limits the accuracy to about the cell size.

Monte Carlo

Draw N uniform random points in a box of volume Vbox. The fraction p inside a region estimates its volume as pVbox, with a relative error of about 1−ppN. To integrate f, average f at the points and multiply by Vbox.

Polar and spherical integrals in code

Changing coordinates puts the Jacobian into the integrand: r in polar, r2sin⁡φ in spherical. A numerical integral in those coordinates uses a rectangular grid in (r,θ) or (r,φ,θ), weighted by the Jacobian.

Worked example

Estimate the volume of the unit sphere by Monte Carlo with 200 000 points.

Show the solution
  1. Sample the cube. Draw points uniformly in the cube [−1,1]3 of volume 8, and count those with x2+y2+z2≤1.
  2. Expected fraction. 4π/38=0.524
  3. One run. It gives a fraction of 0.5217, so the estimate is 8×0.5217=4.173 against the true 4.189: 0.4% low.
  4. Compare with the expected error. 0.4760.524×200000=0.2% The run is within twice that.

Answer one run estimates the volume at 4.173, 0.4% below the true 4.189.

Worked example

Find the centroid of a semicircular plate of radius R.

Show the solution
  1. Set up in polar coordinates. The half disk is 0≤r≤R, 0≤θ≤π, with y¯=1A∬ydA,A=πR22
  2. Integrate y. ∬rsin⁡θ⋅rdrdθ=R33⋅2
  3. Divide by the area. y¯=2R3/3πR2/2=4R3π=0.424R
  4. Interpret. Its balance point is a little under halfway up, because the plate is wider near the base.

Answer the centroid sits on the axis of symmetry, 4R3π=0.424R above the straight edge.

Check

A Monte Carlo region catches a fraction 0.8 of the points. About how many points give a relative error of 1%?

Check

How far above its flat edge is the centroid of a semicircular plate of radius 3 cm?

Write units the way you normally would: 1.5 cm, 15 mm and 0.015 m are the same answer.

Check

Integrate f=xy over the triangle 0≤y≤x≤1 with the midpoint rule on an n×n grid over the unit square (n = 400), using an indicator for the triangle. Set I and exact (=18).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Estimate the unit sphere's volume by Monte Carlo: 200 000 points in [−1,1]3 from np.random.default_rng(1). Set vol.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

A Gaussian beam has I=I0e−2r2/w2 with I0 = 2 W/cm² and w = 1 mm. Integrate numerically in polar coordinates (r from 0 to 5 mm, 2000 steps, trapezoid) and set P in watts and formula to πw2I02.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Find the centroid height y¯ of a semicircular plate of radius 1 numerically: integrate y and 1 over 0≤r≤1, 0≤θ≤π with the midpoint rule on a 300 × 300 polar grid (Jacobian r), and set ybar.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Check the spherical Jacobian numerically: write the map (r,φ,θ)→(x,y,z), compute its 3 × 3 Jacobian matrix by central differences at (2,0.7,1.1), and set det to its determinant and formula to r2sin⁡φ.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does Monte Carlo integration beat a grid in high dimensions, even though it converges so slowly?

Practice

Keep practicing

4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.