Angles, sine and cosine
Angles, the unit circle, sine and cosine (lesson 1.7.1)
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.
Complex numbers
Complex numbers (lesson 1.7.2)
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.
Euler's formula
Euler's formula (lesson 1.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
Polar form by hand
Write three functions without using cmath.polar, cmath.rect or cmath.phase.
to_polar(z)returns(r, theta): the distance and the anglemath.atan2(b, a), wherea = z.realandb = z.imag.from_polar(r, theta)returns the complex number .multiply_polar(p, q)takes two pairs(r1, t1)and(r2, t2)and returns the pair for the product: multiply the distances, add the angles (lesson 1.7.3).
math.atan2(b, a) gives the angle of the point , between and . Unlike math.atan(b / a), it looks at the signs of both parts, so it puts at , not .
The tests compare your answers with cmath in every quadrant and on the negative real axis.
See the tests
import cmath
import math
def test_polar_one_plus_i():
"""1 + i has distance √2 and angle π/4"""
expect_close(to_polar(1 + 1j), (math.sqrt(2), math.pi / 4), what="to_polar(1 + 1j)")
def test_polar_matches_cmath():
"""to_polar agrees with cmath.polar, in every quarter of the plane"""
for z in (3 + 4j, -2 + 1j, -1 - 1j, 2 - 5j):
expect_close(to_polar(z), cmath.polar(z), what=f"to_polar({z})")
def test_polar_negative_real():
"""−2 has distance 2 and angle π"""
expect_close(to_polar(-2 + 0j), (2.0, math.pi), what="to_polar(-2 + 0j)")
def test_from_polar():
"""Distance 2 at angle π/2 is 2i"""
z = from_polar(2, math.pi / 2)
expect_close((z.real, z.imag), (0.0, 2.0), what="from_polar(2, π/2)", abs_tol=1e-12)
def test_round_trip():
"""from_polar undoes to_polar"""
z = -3.5 + 1.25j
back = from_polar(*to_polar(z))
expect_close((back.real, back.imag), (z.real, z.imag), what="from_polar(*to_polar(z))")
def test_multiply_polar():
"""2 at π/6 times 3 at π/3 is 6 at π/2"""
expect_close(multiply_polar((2, math.pi / 6), (3, math.pi / 3)), (6.0, math.pi / 2), what="multiply_polar((2, π/6), (3, π/3))")
def test_multiply_matches_product():
"""Multiplying in polar form gives the same number as z * w"""
for z, w in ((1 + 1j, 1 + math.sqrt(3) * 1j), (-2 + 1j, 3 - 4j), (-1 - 1j, -1 - 1j)):
back = from_polar(*multiply_polar(to_polar(z), to_polar(w)))
expect_close((back.real, back.imag), ((z * w).real, (z * w).imag), what=f"the product of {z} and {w}", abs_tol=1e-12)