SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 4.7.1 Double integralsConcept · 35 min
      2. 4.7.2 Change of variables and the JacobianConcept · 35 min
      3. 4.7.3 Polar coordinates and the Gaussian integralConcept · 30 min
      4. 4.7.4 Practice set: multiple integralsPractice set · 25 min
      5. 4.7.5 Case study: joint densities and Monte Carlo integrationCase study · 35 min

Level 4, Multivariable calculus and optimisation 4.7 Multiple integrals Lesson 1 of 5

ConceptLesson 4.7.1 in Level 4, Multivariable calculus and optimisation. About 35 minutes.

Double integrals

Volume under a surface

A function of two variables f(x,y)f(x, y) gives a height for each point of the plane, and its graph is a surface (lesson 4.1.1). Over a region RR of the xyxy-plane, the solid between RR and the surface has a volume. The double integral ∬Rf(x,y) dA\iint_R f(x, y)\,dA is that volume.

Its units are the height's units times area units. If ff is a depth of water in metres over a pond measured in metres, the double integral is a volume in cubic metres. If ff is a density in kilograms per square metre, it is a mass in kilograms.

A constant height is the simplest case. Water 0.5 m deep over a pool 4 m by 3 m has volume 0.5×12=60.5 \times 12 = 6 cubic metres: height times area. When the height varies, cut the region into small cells, as lesson 2.5.1 cut an interval into strips.

Boxes on a grid

Take f(x,y)=x2+2y2f(x, y) = x^2 + 2y^2, a bowl, over the rectangle R=[0,2]×[0,1]R = [0, 2] \times [0, 1]: the points with 0≤x≤20 \le x \le 2 and 0≤y≤10 \le y \le 1. Cut [0,2][0, 2] into n=4n = 4 strips of width Δx=0.5\Delta x = 0.5, and [0,1][0, 1] into m=2m = 2 strips of width Δy=0.5\Delta y = 0.5. That makes 8 cells, each of area ΔA=Δx Δy=0.25\Delta A = \Delta x\,\Delta y = 0.25.

Over each cell stand a box whose height is ff at the cell's midpoint. The heights are:

x=0.25x = 0.25x=0.75x = 0.75x=1.25x = 1.25x=1.75x = 1.75
y=0.75y = 0.751.18751.68752.68754.1875
y=0.25y = 0.250.18750.68751.68753.1875

The heights add up to 15.5, so the 8 boxes have volume 15.5×0.25=3.87515.5 \times 0.25 = 3.875. The exact volume, found below, is 4.

Rule: Double integral

∬Rf(x,y) dA=lim⁡∑i∑jf(xi∗,yj∗) Δx Δy\begin{gathered} \iint_R f(x, y)\,dA \\ = \lim \sum_{i}\sum_{j} f(x_i^*, y_j^*)\,\Delta x\,\Delta y \end{gathered}

Each term is one box: the height at a point (xi∗,yj∗)(x_i^*, y_j^*) of the cell, times the cell's area Δx Δy\Delta x\,\Delta y. The limit lets the cells shrink in both directions. dAdA is a small piece of area, as dxdx was a small piece of length in lesson 2.5.1.

The volume under z=x2+2y2z = x^2 + 2y^2, estimated by 8 boxes, and one slice of it. The shaded slice at x=1x = 1 has area 53\frac{5}{3}; adding up all the slices gives the volume.

Finer grids close in on the volume. The midpoint error shrinks with the square of the cell width, as in one variable (lesson 2.5.1). Cells 10 times narrower give an error 100 times smaller.

cells4×24 \times 220×1020 \times 10200×100200 \times 100
midpoint sum3.8753.9953.99995
error0.1250.0050.00005

Try it

mid2 is the midpoint sum on an n×mn \times m grid. np.meshgrid pairs every midpoint in xx with every midpoint in yy, so f(X, Y) holds all the box heights at once.

The loop prints the table; 5e-05 means 5×10−5=0.000055 \times 10^{-5} = 0.00005. round hides float noise in the last digits.

⌘/Ctrl + Enter runs the cell

Slices: the iterated integral

The exact volume comes from slicing. Hold xx fixed and the solid's cross-section is the region under the curve y↦f(x,y)y \mapsto f(x, y), a slice as in lesson 4.1.1. Its area is an ordinary integral in yy, with xx treated as a constant (lesson 2.5.3):

A(x)=∫01(x2+2y2) dy=[x2y+23y3]01=x2+23\begin{aligned} A(x) &= \int_0^1 (x^2 + 2y^2)\,dy \\ &= \left[x^2 y + \tfrac{2}{3}y^3\right]_0^1 = x^2 + \tfrac{2}{3} \end{aligned}

The slice at x=1x = 1, shaded in the figure, has area A(1)=53≈1.667A(1) = \frac{5}{3} \approx 1.667. At x=0x = 0 the slice has area 0.667, and at x=2x = 2 it has 4.667.

A thin slab of thickness dxdx has volume about A(x) dxA(x)\,dx. Adding the slabs is a second integral, this time in xx:

∫02(x2+23)dx=83+43=4\int_0^2 \left(x^2 + \tfrac{2}{3}\right) dx = \frac{8}{3} + \frac{4}{3} = 4

Rule: Iterated integral over a rectangle

∬Rf dA=∫ab(∫cdf(x,y) dy)dxR=[a,b]×[c,d]\begin{gathered} \iint_R f\,dA = \int_a^b \left(\int_c^d f(x, y)\,dy\right) dx \\[4pt] R = [a, b] \times [c, d] \end{gathered}

The inner integral holds xx fixed and gives the area of a slice, a function of xx. The outer integral adds the slices. The brackets are usually left out: read ∫ab∫cdf dy dx\int_a^b \int_c^d f\,dy\,dx from the inside out, so dydy goes with the inner sign.

The other order

Slice the other way: hold yy fixed and integrate across xx first. The slice at a fixed yy has area ∫02(x2+2y2) dx=83+4y2\int_0^2 (x^2 + 2y^2)\,dx = \frac{8}{3} + 4y^2, and ∫01(83+4y2)dy=83+43=4\int_0^1 \left(\frac{8}{3} + 4y^2\right) dy = \frac{8}{3} + \frac{4}{3} = 4 again.

Rule: Fubini's theorem

∫ab∫cdf dy dx=∫cd∫abf dx dy\int_a^b \int_c^d f\,dy\,dx = \int_c^d \int_a^b f\,dx\,dy

For ff continuous on the rectangle, both orders give the same number, the double integral. Stated here without proof.

The condition matters. x−y(x+y)3\frac{x - y}{(x + y)^3} blows up at the corner (0,0)(0, 0) of the unit square, and its two orders give 12\frac{1}{2} and −12-\frac{1}{2}.

A function that blows up needs care, as in lesson 2.6.3. For a function that is never negative, such as the bell of lesson 4.7.3, the two orders always agree, even over the whole plane.

A product splits

When f(x,y)=g(x) h(y)f(x, y) = g(x)\,h(y), the inner integral in yy is g(x)g(x) times the number ∫cdh dy\int_c^d h\,dy. So the double integral is a product of two single integrals:

∬[a,b]×[c,d]g(x) h(y) dA=∫abg(x) dx⋅∫cdh(y) dy\begin{gathered} \iint_{[a, b] \times [c, d]} g(x)\,h(y)\,dA \\ = \int_a^b g(x)\,dx \cdot \int_c^d h(y)\,dy \end{gathered}

Over [0,2]×[0,3][0, 2] \times [0, 3], ∬xy dA=2×92=9\iint xy\,dA = 2 \times \frac{9}{2} = 9. Lesson 4.7.3 uses this to find the Gaussian integral.

Try it

SymPy integrates the inside first: sp.integrate(f, (y, 0, 1)) is the slice area A(x)A(x). Integrating that in xx gives the volume, and the second line does the other order.

The last lines check the product rule and the two orders of x−y(x+y)3\frac{x - y}{(x + y)^3}.

⌘/Ctrl + Enter runs the cell

Signed volume and area

Where ff is negative, a box hangs below the xyxy-plane, and its volume counts as negative, as signed area did in lesson 2.5.1. Take f(x,y)=x+y−1f(x, y) = x + y - 1 over [0,1]×[0,2][0, 1] \times [0, 2]. It is negative on the triangle where x+y<1x + y < 1.

The inner integral is ∫02(x+y−1) dy=[xy+y22−y]02=2x\int_0^2 (x + y - 1)\,dy = \left[xy + \frac{y^2}{2} - y\right]_0^2 = 2x, and ∫012x dx=1\int_0^1 2x\,dx = 1. That is the net volume: 76\frac{7}{6} above the plane minus 16\frac{1}{6} below it. The total volume, the integral of ∣f∣\lvert f \rvert, is 76+16=43\frac{7}{6} + \frac{1}{6} = \frac{4}{3}.

With f=1f = 1 every box has height 1, so the volume equals the base area. That turns a double integral into a way to find areas.

Rule: Signed volume and area

∬Rf dA=above−below∬R1 dA=area of R\begin{gathered} \iint_R f\,dA = \text{above} - \text{below} \\[4pt] \iint_R 1\,dA = \text{area of } R \end{gathered}

Volume below the xyxy-plane counts as negative. The total volume is ∬R∣f∣ dA\iint_R \lvert f \rvert\,dA, which counts every part as positive.

Regions between two curves

Most regions are not rectangles. Take the region RR between the parabola y=x2y = x^2 and the line y=xy = x; they meet at (0,0)(0, 0) and (1,1)(1, 1), and the line is on top. A vertical slice at xx runs from y=x2y = x^2 up to y=xy = x, so the inner limits depend on xx.

One region, sliced two ways. With xx fixed, yy runs from the parabola up to the line. With yy fixed, xx runs from the line across to the parabola, written as x=yx = \sqrt{y}.

Its area is ∬R1 dA=∫01(x−x2) dx=16\iint_R 1\,dA = \int_0^1 (x - x^2)\,dx = \frac{1}{6}. For f(x,y)=xyf(x, y) = xy, the inner integral holds xx fixed:

∫x2xxy dy=x[y22]x2x=x3−x52∫01x3−x52 dx=12(14−16)=124\begin{aligned} \int_{x^2}^{x} xy\,dy &= x\left[\tfrac{y^2}{2}\right]_{x^2}^{x} = \frac{x^3 - x^5}{2} \\ \int_0^1 \frac{x^3 - x^5}{2}\,dx &= \frac{1}{2}\left(\frac{1}{4} - \frac{1}{6}\right) = \frac{1}{24} \end{aligned}

Horizontal slices describe the same region differently. At a fixed yy, xx runs from the line, x=yx = y, to the parabola, x=yx = \sqrt{y}, for yy from 0 to 1. Then ∫01∫yyxy dx dy=∫01y2−y32 dy=124\int_0^1 \int_y^{\sqrt{y}} xy\,dx\,dy = \int_0^1 \frac{y^2 - y^3}{2}\,dy = \frac{1}{24} as well.

Rule: Iterated integral over a region

R: a≤x≤b, g1(x)≤y≤g2(x)∬Rf dA=∫ab∫g1(x)g2(x)f dy dx\begin{gathered} R: \ a \le x \le b, \ g_1(x) \le y \le g_2(x) \\[4pt] \iint_R f\,dA = \int_a^b \int_{g_1(x)}^{g_2(x)} f\,dy\,dx \end{gathered}

The inner limits may depend on the outer variable; the outer limits are numbers. To change the order, draw the region and describe it again with slices the other way. Swapping the limits alone describes a different region.

Swapping the limits alone gives ∫01∫y2y\int_0^1 \int_{y^2}^{y}, the region's mirror image in the line y=xy = x. For f=xyf = xy the mistake hides, because xyxy is the same in the mirror. For f=xf = x it shows: the right answer is 112\frac{1}{12}, but the swapped limits give 115\frac{1}{15}.

Choosing the order

The order can decide whether an integral can be done at all. Take the triangle TT where 0≤y≤x≤10 \le y \le x \le 1, and

∫01∫y1ex2 dx dy\int_0^1 \int_y^1 e^{x^2}\,dx\,dy

The inner integral needs an antiderivative of ex2e^{x^2}, and there is none made of familiar functions (lesson 2.6.1). Slice the other way: for each xx from 0 to 1, yy runs from 0 to xx. The inner integral is now easy, since ex2e^{x^2} does not depend on yy:

∫01∫0xex2 dy dx=∫01x ex2 dx=[12ex2]01=e−12\begin{aligned} \int_0^1 \int_0^x e^{x^2}\,dy\,dx &= \int_0^1 x\,e^{x^2}\,dx \\ &= \left[\tfrac{1}{2}e^{x^2}\right]_0^1 = \frac{e - 1}{2} \end{aligned}

That is about 0.859141, by the substitution u=x2u = x^2 of lesson 2.6.1.

Try it

SymPy finds both orders over the region between x2x^2 and xx, and shows the swapped-limits mistake for f=xf = x.

For the triangle, SymPy's inner integral of ex2e^{x^2} in xx needs erfi, a new function (lesson 2.6.1). In the other order it gives e−12\frac{e - 1}{2}, written -1/2 + E/2.

⌘/Ctrl + Enter runs the cell

In Python: dblquad

scipy.integrate.dblquad(func, a, b, gfun, hfun) computes ∫ab∫g(x)h(x)func dy dx\int_a^b \int_{g(x)}^{h(x)} \text{func}\,dy\,dx numerically. It returns the value and an estimate of its error, like quad in lesson 2.5.3. The limits gfun and hfun can be numbers or functions of xx.

The trap is the order of the arguments: func must take the inner variable first, func(y, x). Written as lambda x, y:, the letters swap roles and dblquad integrates a different function.

Try it

The cell checks the bowl, the region between x2x^2 and xx, and the triangle in both orders; [0] keeps the value.

The last line integrates xy2xy^2 over [0,2]×[0,1][0, 2] \times [0, 1], which is 23\frac{2}{3}. Written with the arguments the wrong way round, it returns 43\frac{4}{3}.

⌘/Ctrl + Enter runs the cell

Lesson 4.7.2 changes variables in a double integral, and case study 4.7.5 integrates a probability density over a region to get a probability.

Common mistakes

  1. A box is height times area. Each term is f(xi∗,yj∗) Δx Δyf(x_i^*, y_j^*)\,\Delta x\,\Delta y; adding the heights alone leaves out ΔA\Delta A.
  2. The inner integral treats the outer variable as a constant. In ∫02(x2+2y2) dy\int_0^2 (x^2 + 2y^2)\,dy, x2x^2 integrates to x2yx^2 y.
  3. The outer limits are numbers. Only the inner limits may depend on a variable, and only on the outer one.
  4. Redraw the region to change the order. ∫01∫x2x… dy dx\int_0^1 \int_{x^2}^{x} \ldots\,dy\,dx becomes ∫01∫yy… dx dy\int_0^1 \int_y^{\sqrt{y}} \ldots\,dx\,dy, not ∫01∫y2y\int_0^1 \int_{y^2}^{y}.
  5. dblquad wants func(y, x), the inner variable first.
  6. Volume below the plane counts as negative. For the total volume, integrate ∣f∣\lvert f \rvert.
  7. The product rule needs a rectangle. Over a region between curves the inner limits depend on xx, and the integral does not split.

Double integrals

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • ∬Rf dA\iint_R f\,dA is the volume under z=f(x,y)z = f(x, y) over RR, in height units times area units: the limit of sums of boxes f(xi∗,yj∗) Δx Δyf(x_i^*, y_j^*)\,\Delta x\,\Delta y.
  • Iterated integral: integrate across a slice with the other variable held fixed, then add the slices. Over a rectangle, either order gives the same answer for a continuous ff (Fubini).
  • Over a rectangle, ∬g(x)h(y) dA=∫g dx⋅∫h dy\iint g(x)h(y)\,dA = \int g\,dx \cdot \int h\,dy.
  • Volume below the plane counts as negative; ∬R1 dA\iint_R 1\,dA is the area of RR.
  • Between curves, ∫ab∫g1(x)g2(x)f dy dx\int_a^b \int_{g_1(x)}^{g_2(x)} f\,dy\,dx: inner limits depend on the outer variable. To change the order, redraw the region; the right order can make a hard integral easy.
  • dblquad(func, a, b, gfun, hfun) with func(y, x): the inner variable comes first.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.

  • Multiple Integrals

    Paul's Online Notes. Notes.

    Double and triple integrals, polar coordinates and change of variables.

  • 18.02SC Multivariable Calculus

    MIT OpenCourseWare. Course.

    Lectures and problem sets on partial derivatives, optimisation and multiple integrals.