BetaFree coursewareRewritten from MIT OpenCourseWareCC BY-NC-SA 4.0
Open CosmologyPhysics & cosmology, from high school to a graduate year

The dartboard, and numerical integration

The lecture finishes the dartboard problem: with hits spread like e^(−r²), the chance of a ring of the board is e^(−r₁²) − e^(−r₂²), and a little brother standing next to the board is hit by about 1% of the darts. Then numerical integration, for integrals without a formula: Riemann sums, the trapezoidal rule (the average of left and right sums), and Simpson's rule, which fits parabolas and weights the values 1, 4, 2, 4, …, 4, 1. Simpson's rule is far more accurate.

You need this first

Full reading path (19 pages)
  1. The derivative: slope of the tangent line and rate of change (18.01)
  2. Limits and continuity (18.01)
  3. Derivatives of sine and cosine, and the product and quotient rules (18.01)
  4. The chain rule and higher derivatives (18.01)
  5. Implicit differentiation and the derivatives of inverse functions (18.01)
  6. Exponentials and logarithms: the number e and its derivatives (18.01)
  7. Linear and quadratic approximations (18.01)
  8. Curve sketching with the first and second derivative (18.01)
  9. Sketching strategy and maximum–minimum problems (18.01)
  10. More max–min, and related rates (18.01)
  11. A ring on a string, and Newton's method (18.01)
  12. The mean value theorem and inequalities (18.01)
  13. Differentials and antiderivatives (18.01)
  14. Definite integrals and Riemann sums (18.01)
  15. The first fundamental theorem of calculus (18.01)
  16. The second fundamental theorem of calculus (18.01)
  17. The logarithm from an integral, and areas between curves (18.01)
  18. Volumes by disks and shells (18.01)
  19. Average value, weighted averages and probability (18.01)
On this page · 5 sections
  1. The dartboard
  2. Why numerical integration?
  3. The trapezoidal rule
  4. Simpson's rule
  5. Summary

The lecture starts with a correction: the energy in the boiling-cauldron example is heat. Energy, heat and work are the same physical quantity, measured in different units: calories, kilowatt-hours, foot-pounds (transcript, p. 1). Then it finishes the dartboard problem announced last time, and turns to integrals that have no formula.

The dartboard#

Someone throws darts at a target; your little brother stands next to it. How likely is he to be hit (transcript, pp. 1–8; notes for Lecture 23, pp. 4–6)? The model: the number of hits per unit area at distance rr from the centre is proportional to c e−r2c\,e^{-r^2}. The probability of any region is the part over the whole, so the unknown cc cancels (pp. 1–3).

Hits per area mean that a ring between r1r_1 and r2r_2 is weighted by a volume of revolution: shells of circumference 2πr2\pi r, height e−r2e^{-r^2} and thickness drdr (p. 2). The antiderivative is easy, −πe−r2-\pi e^{-r^2} (p. 5). For the whole, let rr run from 0 to infinity: unrealistic for a basement wall, but the tail is negligible and the numbers come out cleaner (p. 6). So

Probability of a ring
P(r1<r<r2)=∫r1r2e−r2 2πr dr∫0∞e−r2 2πr dr=π(e−r12−e−r22)π=e−r12−e−r22P(r_1 < r < r_2) = \frac{\int_{r_1}^{r_2} e^{-r^2}\,2\pi r\,dr}{\int_0^\infty e^{-r^2}\,2\pi r\,dr} = \frac{\pi\left(e^{-r_1^2} - e^{-r_2^2}\right)}{\pi} = e^{-r_1^2} - e^{-r_2^2}
In words

P( r one less than r less than r two ) equals the integral from r one to r two of e to the power minus r squared 2 pi r d r over the quantity the integral from 0 to infinity of e to the power minus r squared 2 pi r d r, equals pi the quantity e to the power minus r one squared minus e to the power minus r two squared, over pi equals e to the power minus r one squared minus e to the power minus r two squared

Source: 18.01 Lecture 24 transcript, pp. 5–6

Two realistic assumptions finish it (pp. 7–8). A seven-year-old hits the target, radius aa, about half the time: 1−e−a2=121 - e^{-a^2} = \tfrac12, so e−a2=12e^{-a^2} = \tfrac12. The brother stands between 2a2a and 3a3a, covering two hours of the clock, from 3 to 5 o'clock, a sixth of the ring. Then

The little brother's risk
P≈16(e−4a2−e−9a2)=16[(12)4−(12)9]≈16⋅116≈1100P \approx \frac16\left(e^{-4a^2} - e^{-9a^2}\right) = \frac16\left[\left(\tfrac12\right)^4 - \left(\tfrac12\right)^9\right] \approx \frac16\cdot\frac{1}{16} \approx \frac{1}{100}
In words

P is approximately one sixth the quantity e to the power minus 4 a squared minus e to the power minus 9 a squared, equals one sixth the quantity ( one half ) to the power 4 minus ( one half ) to the power 9, is approximately one sixth times 1 over 16 is approximately 1 over 100

Source: 18.01 Lecture 24 transcript, pp. 7–8

about 1% per dart: stand there for a hundred throws and a hit is likely (p. 8). The lecturer adds that this kind of model was used to analyse where the V-2 rockets fell on London (p. 4). Notice the weight in rr is 2πc r e−r22\pi c\,r\,e^{-r^2}, which is zero at the centre: although e−r2e^{-r^2} is largest there, the centre has so little area that a dart rarely lands near it (pp. 4, 8–9).

Why numerical integration?#

Many integrals cannot be done in closed form, such as ∫0xcos⁡(t2) dt\int_0^x \cos(t^2)\,dt or ∫03e−x2 dx\int_0^3 e^{-x^2}\,dx, and others are just a mess; then you compute the number directly (transcript, p. 9; notes, p. 1). Sample the function at x0=a,x1,…,xn=bx_0 = a, x_1, \dots, x_n = b, equally spaced by Δx\Delta x, with yi=f(xi)y_i = f(x_i), and combine the yy's (pp. 9–10).

Riemann sums use rectangles: (y0+y1+⋯+yn−1) Δx(y_0 + y_1 + \cdots + y_{n-1})\,\Delta x with left ends, or (y1+⋯+yn) Δx(y_1 + \cdots + y_n)\,\Delta x with right ends. They are "incredibly inefficient" (pp. 9–10; notes, p. 1).

The trapezoidal rule#

Join neighbouring points by straight lines instead (transcript, pp. 10–11; notes, p. 2). Each strip is a trapezoid of area Δx yi+yi+12\Delta x\,\frac{y_i + y_{i+1}}{2}, base times average height. Adding them, every inner value appears twice with a half:

Trapezoidal rule
∫abf(x) dx≈Δx(y02+y1+y2+⋯+yn−1+yn2)\int_a^b f(x)\,dx \approx \Delta x\left(\frac{y_0}{2} + y_1 + y_2 + \cdots + y_{n-1} + \frac{y_n}{2}\right)
In words

the integral from a to b of f(x) d x is approximately capital delta x the quantity y nought over 2 plus y one plus y two plus and so on plus y sub n minus 1 plus y sub n over 2

It is exactly the average of the left and right Riemann sums, treating the two ends symmetrically. Better, but still not very efficient (p. 11; notes, p. 3).

The curve y=1/(1+x2)y = 1/(1 + x^2) on [0, 1] and the two straight-line tops of the trapezoidal rule with n=2n = 2, through (0, 1), (0.5, 0.8) and (1, 0.5), all computed from the formulas. On the left half the curve bulges above its chord; on the right half it dips slightly below. The shortfall on the left is larger, so the rule gives 0.775, a little under the true π/4≈0.785\pi/4 \approx 0.785.

Simpson's rule#

Now fit a parabola through each three neighbouring points, which needs an even number of intervals (transcript, pp. 11–12; notes, pp. 3–4). For one pair of intervals the area under the parabola is the base 2Δx2\Delta x times a weighted average height, which emphasizes the middle (the computation is on the problem set):

Area under a parabola
2Δx⋅y0+4y1+y262\Delta x\cdot\frac{y_0 + 4y_1 + y_2}{6}
In words

2 capital delta x times the quantity y nought plus 4 y one plus y two, all over 6

Source: 18.01 Lecture 24 transcript, pp. 11–12

Add the pairs: the weights 1,4,11, 4, 1 overlap where pairs meet, giving 1,4,2,4,2,…,2,4,11, 4, 2, 4, 2, \dots, 2, 4, 1 (p. 12; notes, p. 4):

Simpson's rule (n even)
∫abf(x) dx≈Δx3(y0+4y1+2y2+4y3+⋯+2yn−2+4yn−1+yn)\int_a^b f(x)\,dx \approx \frac{\Delta x}{3}\left(y_0 + 4y_1 + 2y_2 + 4y_3 + \cdots + 2y_{n-2} + 4y_{n-1} + y_n\right)
In words

the integral from a to b of f(x) d x is approximately capital delta x over 3, times the quantity y nought plus 4 y one plus 2 y two plus 4 y three plus and so on plus 2 y sub n minus 2 plus 4 y sub n minus 1 plus y sub n

As a check, for f=1f = 1 the weights add up to 3n3n, so the rule gives n Δx=b−an\,\Delta x = b - a, as it should (notes, p. 4). On a small enough piece a typical function has no inflection point, so parabolas fit it extremely well (transcript, p. 11). The notes compare on ∫01dx1+x2=π4≈0.785\int_0^1 \frac{dx}{1 + x^2} = \frac{\pi}{4} \approx 0.785 with n=2n = 2: the trapezoidal rule gives 0.775 and Simpson's rule 0.7833, with an error roughly of order (Δx)4(\Delta x)^4 (notes, p. 5). The lecture promises to show how much better Simpson's rule is next time (p. 12).

Worked example

Simpson against the trapezoids

Estimate ∫01e−x2 dx\int_0^1 e^{-x^2}\,dx (no elementary antiderivative) with n=4n = 4 by both rules, and compare with the true value 0.746824.

Samples

Δx=0.25\Delta x = 0.25: y0=1y_0 = 1, y1=e−0.0625≈0.93941y_1 = e^{-0.0625} \approx 0.93941, y2=e−0.25≈0.77880y_2 = e^{-0.25} \approx 0.77880, y3=e−0.5625≈0.56978y_3 = e^{-0.5625} \approx 0.56978, y4=e−1≈0.36788y_4 = e^{-1} \approx 0.36788.

Trapezoidal

0.25 (0.5+0.93941+0.77880+0.56978+0.18394)≈0.742980.25\,(0.5 + 0.93941 + 0.77880 + 0.56978 + 0.18394) \approx 0.74298: off by about 0.0038.

Simpson

0.253 (1+4×0.93941+2×0.77880+4×0.56978+0.36788)≈0.74686\frac{0.25}{3}\,(1 + 4 \times 0.93941 + 2 \times 0.77880 + 4 \times 0.56978 + 0.36788) \approx 0.74686: off by only about 0.00003, a hundred times better for the same five values.

Summary#

  • Dartboard: with hits per area ∝e−r2\propto e^{-r^2}, P(r1<r<r2)=e−r12−e−r22P(r_1 < r < r_2) = e^{-r_1^2} - e^{-r_2^2}; standing beside the board means about a 1% chance per dart.
  • Numerical integration samples yi=f(xi)y_i = f(x_i) at spacing Δx\Delta x and combines them.
  • Trapezoidal rule: Δx (12y0+y1+⋯+yn−1+12yn)\Delta x\,(\tfrac12 y_0 + y_1 + \cdots + y_{n-1} + \tfrac12 y_n), the average of left and right sums.
  • Simpson's rule (nn even): Δx3(y0+4y1+2y2+⋯+4yn−1+yn)\frac{\Delta x}{3}(y_0 + 4y_1 + 2y_2 + \cdots + 4y_{n-1} + y_n), from parabolas; far more accurate.

Symbols on this page

Show the 46 symbols used here
Δ\Delta capital delta.
A change or difference in a quantity, e.g. Δx = x₂ − x₁. Say it: “capital delta”.
Λ\Lambda capital lambda.
As in Ω_Λ: the vacuum energy (cosmological constant). Say it: “capital lambda”.
π\pi pi.
The ratio of a circle's circumference to its diameter, π ≈ 3.14159. Say it: “pi”.
Ω\Omega capital omega.
The density parameter Ω = ρ/ρ_c. Subscripts pick one ingredient: Ω_m matter, Ω_vac (or Ω_Λ) vacuum energy, Ω_r radiation, Ω_k curvature. Say it: “capital omega”.
∞\infty infinity.
Infinity: larger than any number. Say it: “infinity”.
≈\approx approximately equal.
Is approximately equal to. Say it: “is approximately”.
∝\propto proportional to.
Is proportional to: doubling one doubles the other. Say it: “is proportional to”.
×\times times.
Times (multiplication). Between two vectors: the cross product. Say it: “times”.
⋅\cdot dot.
Times (multiplication). Between two vectors: the dot product. Say it: “times”.
∫\int integral.
Integral: the sum of infinitely many small pieces, such as the area under a curve. Say it: “the integral of”.
cos⁡\cos cosine.
Cosine of an angle. Say it: “cos”.
ln⁡\ln natural logarithm.
Natural logarithm (base e ≈ 2.718). Say it: “log”.
aa a.
The lower limit of integration; in the dartboard problem, the radius of the target. Say it: “a”.
zz z.
In the cosmology note, the redshift. Say it: “z”.
cc c.
The constant in the dartboard density c e^(−r²) (it cancels); in the cosmology note, the speed of light. Say it: “c”.
H0H_{0} Hubble constant.
The Hubble constant: today's value of H, about 67–73 km/s/Mpc. Unit: 1/s (usually km/s/Mpc). Say it: “H nought”.
Ωm\Omega_{m} matter density parameter.
The matter density as a fraction of the critical density, ρ_m/ρ_c; ',0' means today (about 0.3). Say it: “capital omega m”.
Ωvac\Omega_{\text{vac}} vacuum density parameter.
The vacuum-energy density as a fraction of the critical density; ',0' means today (about 0.7). Say it: “capital omega vac”.
xx x.
The variable of integration. Say it: “x”.
yy y.
The height of the graph, y = f(x). Say it: “y”.
tt t.
A dummy variable of integration. Say it: “t”.
dd d.
As in dx, dr and dz′: the variable of integration. Say it: “d”.
nn n.
The number of intervals (even for Simpson's rule). Say it: “n”.
ee e.
Euler's number, e ≈ 2.718. Say it: “e”.
ff f.
The function being integrated. Say it: “f”.
rr r.
The distance of a dart from the centre of the board. Say it: “r”.
PP P.
A probability (a number between 0 and 1). Say it: “P”.
bb b.
The upper limit of integration. Say it: “b”.
x0x_{0} x nought.
The first sample point, x₀ = a. Say it: “x nought”.
y0y_{0} y nought.
The sampled value f(x₀). Say it: “y nought”.
r1r_{1} r one.
The inner radius of a ring of the dartboard. Say it: “r one”.
r2r_{2} r two.
The outer radius of a ring of the dartboard. Say it: “r two”.
x1x_{1} x 1.
The second sample point. Say it: “x one”.
y1y_{1} y 1.
The sampled value f(x₁). Say it: “y one”.
y2y_{2} y 2.
The sampled value f(x₂). Say it: “y two”.
xnx_{n} x n.
The last sample point, x_n = b. Say it: “x sub n”.
y3y_{3} y three.
The sampled value f(x₃). Say it: “y three”.
xix_{i} x i.
The i-th sample point. Say it: “x sub i”.
yiy_{i} y i.
The sampled value f(xᵢ). Say it: “y initial”.
yny_{n} y n.
The last sampled value, f(x_n). Say it: “y sub n”.
yn−1y_{n-1} y n minus 1.
The next-to-last sampled value. Say it: “y sub n minus 1”.
yn−2y_{n-2} y n minus 2.
The sampled value two before the last. Say it: “y sub n minus 2”.
yi+1y_{i+1} y i plus 1.
The sampled value after yᵢ. Say it: “y sub i plus 1”.
y4y_{4} y four.
The sampled value f(x₄). Say it: “y four”.
y6y_{6} y six.
The sampled value f(x₆). Say it: “y six”.
z′z' z prime.
The redshift used as the variable of integration. Say it: “z prime”.

Tap or click a symbol in a formula to see the same explanation. All symbols: symbols and notation.

Words on this page

Show the 32 words used here

Also used

energy.
A quantity, measured in joules, that a body or field has because of its motion, position or state; a closed system keeps its total. Explained in Conservation of energy.
heat.
Energy that passes between bodies because their temperatures differ, rather than by one doing mechanical work on the other. Explained in Temperature and thermal energy.
p..
Page, in a reference to a source; pp. means pages, as in pp. 3–5.
integral.
A sum of very many very small pieces, such as the area under a graph; it undoes taking a derivative. Explained in Rates of change and area under a graph.
proportional.
Of two quantities: always in the same ratio, so that doubling one doubles the other. Explained in Graphs, straight lines and slope.
solid of revolution.
A solid made by spinning a flat region about an axis, like a vase shaped on a potter's wheel. Explained in Volumes by disks and shells.
antiderivative.
A function whose derivative is the given function; any two antiderivatives differ only by a constant. Explained in Differentials and antiderivatives.
weight.
How much one value counts in a weighted average or sum, compared with the others. Explained in Average value, weighted averages and probability.
Riemann sum.
An estimate of an integral: cut the interval into strips, multiply each strip's width by a value of the function in it, and add. Explained in Definite integrals and Riemann sums.
symmetric.
Unchanged by some swap, reflection or turn; for an expression in two quantities, unchanged when they are exchanged. Explained in Introduction to Fourier series.
parabola.
The U-shaped curve of y = ax² + bx + c, also the path of a thrown ball when air resistance is ignored. Explained in Quadratics and power laws.
interval.
A stretch between two values or two moments; in maths, all the numbers between two end points. Explained in Time dilation, length contraction and the interval.
weighted average.
An average in which some values count more: each is multiplied by its weight, and the total divided by the sum of the weights. Explained in Centre of mass and its motion.
inflection point.
A point where a graph changes the way it bends, from bending up to bending down or the other way. Explained in Curve sketching with the first and second derivative.
trapezoidal rule.
A way to estimate an integral by joining neighbouring points of the graph with straight lines and adding the areas of the strips below.
Simpson's rule.
A way to estimate an integral by fitting parabolas through groups of three points; it is far more accurate than straight lines.
flat universe.
A universe with exactly the critical density, whose space has no curvature and which expands forever, ever more slowly. Explained in Open, closed and flat universes.
vacuum energy.
Energy that empty space itself carries, the same everywhere and unchanged as the universe expands. Explained in Dark energy and the accelerating universe.
comoving distance.
The distance between two objects measured on the stretching grid of comoving coordinates, which does not change as the universe expands.
redshift.
A stretching of light to longer wavelengths, so lines in a spectrum appear shifted towards the red. Explained in Towards the universe: an expanding gas cools.
megaparsec.
A million parsecs, about 3.26 million light-years: the usual unit for distances between galaxies. Explained in Towards the universe: redshift, stretched light from moving sources.
supernova.
The explosion of a star at the end of its life, briefly as bright as a whole galaxy. Explained in How bright is a distant supernova?.
integration.
Finding an integral: adding up very many small pieces, or finding an antiderivative. Explained in Differentials and antiderivatives.

Academic

transcript.
A written record of exactly what was said in a recorded lecture, word for word.
model.
A simplified description of a real system, usually in equations, that keeps what matters and leaves out the rest.
negligible.
So small that leaving it out makes no noticeable difference to the result.
assumption.
Something accepted as true, without proof, so that an argument or calculation can proceed; to assume is to accept it so.
problem set.
A weekly sheet of exercises that students work through and hand in, to practise what the lectures taught.
error.
The difference between a measured or computed value and the true one; often how large that difference may be.
of order.
Roughly equal to, within a factor of a few; of order one means neither much bigger nor much smaller than one.
numerically.
In terms of actual numbers rather than symbols; often worked out step by step, by computer, instead of from an exact formula.
accuracy.
Closeness to the true value: an accurate measurement or calculation gives a result near the right answer.

Tap or click a word, here or in the text, for its meaning in this lesson. All words: the glossary. How many words are marked in the text: Reading options (the “Aa” button).

Where this leads

In cosmology

Pages that build on this

Practise

Check your understanding

  1. Darts land with density proportional to e−r2e^{-r^2} per unit area. The probability of landing within radius aa is…
  2. The trapezoidal rule is the same as…
  3. In Simpson's rule with n=6n = 6 intervals, the weights on y0,…,y6y_0, \dots, y_6 are…
  4. With n=2n = 2, Simpson's rule for ∫12dx/x\int_1^2 dx/x gives about…
0 of 4 answered

Flashcards

1 / 3