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 4 of 5

Practice setLesson 4.7.4 in Level 4, Multivariable calculus and optimisation. About 25 minutes.

Practice set: multiple integrals

Double integrals

Double integrals (lesson 4.7.1)

0 of 7 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
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.

Change of variables

Change of variables and the Jacobian (lesson 4.7.2)

0 of 6 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
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.

Polar coordinates

Polar coordinates and the Gaussian integral (lesson 4.7.3)

0 of 7 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
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.

Coding exercise

Exercise

A midpoint rule over a region

Write region_midpoint(f, a, b, lower, upper, n=200). It estimates ∬Rf(x,y) dA\iint_R f(x, y)\,dA over the region a≤x≤ba \le x \le b, lower(x)≤y≤upper(x)\text{lower}(x) \le y \le \text{upper}(x), as in lesson 4.7.1.

  • Cut [a,b][a, b] into n strips of width Δx=b−an\Delta x = \frac{b - a}{n}, and take the midpoint xx of each.
  • At that xx, cut the slice from lower(x) to upper(x) into n cells of height Δy\Delta y, and add ff at each cell's midpoint times Δx Δy\Delta x\,\Delta y.
  • Raise ValueError if n is less than 1.

The tests try a rectangle, the region between y=x2y = x^2 and y=xy = x, the triangle with ex2e^{x^2}, the unit disc and the Gaussian of lesson 4.7.3. One checks that the error shrinks 4 times when n doubles, as a midpoint rule's should.

See the tests
import math

import numpy as np


def test_rectangle():
    """x² + 2y² over [0, 2] × [0, 1] gives about 4"""
    got = region_midpoint(lambda x, y: x**2 + 2 * y**2, 0, 2, lambda x: 0 * x, lambda x: 0 * x + 1)
    expect_close(got, 4.0, what="region_midpoint over the rectangle", rel=1e-4)


def test_one_cell():
    """With n = 1 the estimate is f at the middle, (1, 0.5), times the area 2: exactly 3"""
    got = region_midpoint(lambda x, y: x**2 + 2 * y**2, 0, 2, lambda x: 0 * x, lambda x: 0 * x + 1, n=1)
    expect_close(got, 3.0, what="region_midpoint with n = 1 (heights at midpoints)", rel=1e-12)


def test_not_symmetric():
    """x y² over [0, 2] × [0, 1] gives about 2/3, not 4/3: x and y keep their places"""
    got = region_midpoint(lambda x, y: x * y**2, 0, 2, lambda x: 0 * x, lambda x: 0 * x + 1)
    expect_close(got, 2 / 3, what="region_midpoint of x y²", rel=1e-4)


def test_between_curves():
    """xy between y = x² and y = x gives about 1/24"""
    got = region_midpoint(lambda x, y: x * y, 0, 1, lambda x: x**2, lambda x: x)
    expect_close(got, 1 / 24, what="region_midpoint of xy between x² and x", rel=1e-4)


def test_triangle():
    """e^(x²) over the triangle 0 ≤ y ≤ x ≤ 1 gives about (e − 1)/2 = 0.859141"""
    got = region_midpoint(lambda x, y: np.exp(x**2), 0, 1, lambda x: 0 * x, lambda x: x)
    expect_close(got, (math.e - 1) / 2, what="region_midpoint of e^(x²) over the triangle", rel=1e-4)


def test_disc():
    """The area of the unit disc, with y from −√(1 − x²) to √(1 − x²), is about π"""
    got = region_midpoint(lambda x, y: 0 * x + 1, -1, 1, lambda x: -np.sqrt(1 - x**2), lambda x: np.sqrt(1 - x**2))
    expect_close(got, math.pi, what="region_midpoint of 1 over the unit disc", rel=5e-4)


def test_gaussian():
    """e^−(x² + y²) over [−5, 5] × [−5, 5] gives π to 8 digits (lesson 4.7.3)"""
    got = region_midpoint(lambda x, y: np.exp(-x**2 - y**2), -5, 5, lambda x: 0 * x - 5, lambda x: 0 * x + 5)
    expect_close(got, math.pi, what="region_midpoint of the bell", rel=1e-8)


def test_second_order():
    """Doubling n from 50 to 100 cuts the error about 4 times"""
    f = lambda x, y: x**2 + 2 * y**2
    e50 = region_midpoint(f, 0, 2, lambda x: 0 * x, lambda x: 0 * x + 1, n=50) - 4
    e100 = region_midpoint(f, 0, 2, lambda x: 0 * x, lambda x: 0 * x + 1, n=100) - 4
    ratio = e50 / e100
    assert 3.5 < ratio < 4.5, f"expected the error to shrink about 4 times, it shrank {ratio:.3g} times: are the heights taken at the midpoints?"


def test_bad_n():
    """n = 0 raises ValueError"""
    try:
        region_midpoint(lambda x, y: 1.0, 0, 1, lambda x: 0.0, lambda x: 1.0, n=0)
    except ValueError:
        return
    raise AssertionError("expected ValueError for n = 0")

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.