Double integrals
Double integrals (lesson 4.7.1)
0 of 7 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 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,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for 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.
- 2.
- 3.
- 4.
- 5.
- 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,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for 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.
- 2.
- 3.
- 4.
- 5.
- 6.
- 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,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for 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
A midpoint rule over a region
Write region_midpoint(f, a, b, lower, upper, n=200). It estimates over the region , , as in lesson 4.7.1.
- Cut into
nstrips of width , and take the midpoint of each. - At that , cut the slice from
lower(x)toupper(x)intoncells of height , and add at each cell's midpoint times . - Raise
ValueErrorifnis less than 1.
The tests try a rectangle, the region between and , the triangle with , 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")