SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 1.7.1 Angles, the unit circle, sine and cosineConcept · 30 min
      2. 1.7.2 Complex numbersConcept · 25 min
      3. 1.7.3 Euler's formulaConcept · 25 min
      4. 1.7.4 Practice set: trigonometry and complex numbersPractice set · 20 min

Level 1, Precalculus 1.7 Trigonometry and complex numbers Lesson 4 of 4

Practice setLesson 1.7.4 in Level 1, Precalculus. About 20 minutes.

Practice set: trigonometry and complex numbers

Angles, sine and cosine

Angles, the unit circle, sine and cosine (lesson 1.7.1)

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.

Complex numbers

Complex numbers (lesson 1.7.2)

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.

Euler's formula

Euler's formula (lesson 1.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

Polar form by hand

Write three functions without using cmath.polar, cmath.rect or cmath.phase.

  1. to_polar(z) returns (r, theta): the distance a2+b2\sqrt{a^2 + b^2} and the angle math.atan2(b, a), where a = z.real and b = z.imag.
  2. from_polar(r, theta) returns the complex number r(cos⁡θ+isin⁡θ)r(\cos\theta + i\sin\theta).
  3. 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 (a,b)(a, b), between −π-\pi and π\pi. Unlike math.atan(b / a), it looks at the signs of both parts, so it puts −1−i-1 - i at −3π4-\frac{3\pi}{4}, not π4\frac{\pi}{4}.

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)

Free further reading

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

  • Complex Number Primer

    Paul's Online Notes. Notes.

    Polar form, Euler's formula and powers of complex numbers.