SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 1.2.1 Lines: slope and interceptConcept · 25 min
      2. 1.2.2 Quadratics and completing the squareConcept · 25 min
      3. 1.2.3 Practice set: lines and quadraticsPractice set · 20 min
      4. 1.2.4 Case study: the minimum-variance two-asset portfolioCase study · 30 min

Level 1, Precalculus 1.2 Lines and quadratics Lesson 3 of 4

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

Practice set: lines and quadratics

Lines

Lines (lesson 1.2.1)

0 of 9 correct

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

Quadratics

Quadratics (lesson 1.2.2)

0 of 10 correct

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

Vertex and roots of any quadratic

Write two functions for ax2+bx+cax^2 + bx + c, using the vertex rule and the quadratic formula from lesson 1.2.2.

  1. vertex(a, b, c) returns the vertex as a tuple (x, y). It is the lowest point when a > 0 and the highest when a < 0.
  2. real_roots(a, b, c) returns a list of the real roots, smallest first: two, one or none, as the discriminant says.

Both raise ValueError when a == 0, because then the expression is not a quadratic.

See the tests
def _raises_value_error(fn, *args):
    try:
        fn(*args)
    except ValueError:
        return True
    return False


def test_vertex():
    """The vertex of x² − 6x + 5 is (3, −4)"""
    expect_close(vertex(1, -6, 5), (3.0, -4.0), what="vertex(1, -6, 5)")


def test_vertex_downward():
    """The vertex of −x² + 6x is the maximum (3, 9)"""
    expect_close(vertex(-1, 6, 0), (3.0, 9.0), what="vertex(-1, 6, 0)")


def test_two_roots():
    """x² − 6x + 5 = 0 has roots 1 and 5, smallest first"""
    expect_close(real_roots(1, -6, 5), [1.0, 5.0], what="real_roots(1, -6, 5)")


def test_two_roots_negative_a():
    """−2x² + 2x + 4 = 0 has roots −1 and 2, still smallest first"""
    expect_close(real_roots(-2, 2, 4), [-1.0, 2.0], what="real_roots(-2, 2, 4)")


def test_one_root():
    """x² − 4x + 4 = 0 has the single root 2"""
    expect_close(real_roots(1, -4, 4), [2.0], what="real_roots(1, -4, 4)")


def test_no_real_roots():
    """2x² + 3x + 5 = 0 has no real roots: an empty list"""
    roots = real_roots(2, 3, 5)
    assert roots == [], f"expected [], got {roots!r}"


def test_not_a_quadratic():
    """a = 0 raises ValueError in both functions"""
    assert _raises_value_error(vertex, 0, 2, 1), "vertex(0, 2, 1) should raise ValueError"
    assert _raises_value_error(real_roots, 0, 2, 1), "real_roots(0, 2, 1) should raise ValueError"

Free further reading

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

  • Lines

    Paul's Online Notes. Notes.

    Slope, the slope-intercept and point-slope forms, and parallel and perpendicular lines.

  • College Algebra 2e, 2.5 Quadratic Equations

    OpenStax. Free book.

    Factoring, completing the square and the quadratic formula, with many exercises.