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

ConceptLesson 1.2.2 in Level 1, Precalculus. About 25 minutes.

Quadratics and completing the square

Quadratics and parabolas

A quadratic is y=ax2+bx+cy = ax^2 + bx + c, where aa, bb and cc are numbers and a≠0a \neq 0. With a=0a = 0 it would be the line y=bx+cy = bx + c of lesson 1.2.1. Its graph is a U-shaped curve called a parabola.

Here is y=x2−6x+5y = x^2 - 6x + 5 at seven inputs.

xx0123456
yy50−3-3−4-4−3-305

The values fall, turn at x=3x = 3, then climb back in mirror image. The turning point (3,−4)(3, -4) is the vertex.

The vertical line x=3x = 3 through it is the axis of symmetry. Inputs the same distance either side, such as 2 and 4, give the same output.

The vertex answers two questions at once: how small can the quadratic get, and at which input? For x2−6x+5x^2 - 6x + 5 the smallest value is −4-4, at x=3x = 3. In the words of lesson 1.1.1, its range is [−4,∞)[-4, \infty).

Three things can be read off the formula before any working.

  • The sign of aa. If a>0a > 0 the parabola opens upwards and the vertex is its lowest point. If a<0a < 0 it opens downwards and the vertex is its highest point.
  • The size of aa. As in lesson 1.1.2, 2x22x^2 is a narrower stretch of x2x^2, and 12x2\frac{1}{2}x^2 a wider one.
  • The value of cc. At x=0x = 0 the quadratic equals cc, so (0,c)(0, c) is the yy-intercept. Here it is (0,5)(0, 5).

Try it

The cell rebuilds the table. The outputs are symmetric about x=3x = 3, where the lowest one, −4-4, sits.

⌘/Ctrl + Enter runs the cell

Completing the square

A table finds the vertex only when it lands on an input you tried. Completing the square finds it exactly. Lesson 1.1.1 used it once, to write x2−2xx^2 - 2x as (x−1)2−1(x - 1)^2 - 1.

Completing the square rewrites a quadratic as a(x−h)2+ka(x - h)^2 + k. That is x2x^2 stretched by aa, moved hh right and kk up (lesson 1.1.2), so its vertex is (h,k)(h, k).

The method rests on one square: (x−3)2=x2−6x+9(x - 3)^2 = x^2 - 6x + 9. Its xx term is −6x-6x, twice the −3-3 in the bracket. So halving the coefficient of xx gives the number to put in the bracket.

  1. 1
    x2−6x+5x^2 - 6x + 5
  2. 2
    (x−3)2−9+5(x - 3)^2 - 9 + 5
  3. 3
    (x−3)2−4(x - 3)^2 - 4

A square is never negative, so (x−3)2−4(x - 3)^2 - 4 is never below −4-4. It equals −4-4 exactly when x−3=0x - 3 = 0, at x=3x = 3. So the vertex is (3,−4)(3, -4), as the table showed.

Completing the square writes x2−6x+5x^2 - 6x + 5 as (x−3)2−4(x - 3)^2 - 4: the graph of x2x^2 moved 3 right and 4 down. Its roots, 1 and 5, sit 2 either side of the axis x=3x = 3, and (0,5)(0, 5) mirrors (6,5)(6, 5).

When aa is not 1

For 2x2−8x+32x^2 - 8x + 3, take the 2 out of the two xx terms first: 2(x2−4x)+32(x^2 - 4x) + 3. Inside the bracket, half of −4-4 is −2-2, so x2−4x=(x−2)2−4x^2 - 4x = (x - 2)^2 - 4. Then multiply back out:

2x2−8x+3=2[(x−2)2−4]+3=2(x−2)2−8+3=2(x−2)2−5\begin{aligned} 2x^2 - 8x + 3 &= 2\big[(x - 2)^2 - 4\big] + 3 \\ &= 2(x - 2)^2 - 8 + 3 \\ &= 2(x - 2)^2 - 5 \end{aligned}

The vertex is (2,−5)(2, -5). Note that the −4-4 inside the bracket was multiplied by 2.

When aa is negative

For −x2+4x+5-x^2 + 4x + 5, take out −1-1 to leave −(x2−4x)+5-(x^2 - 4x) + 5, then complete the square inside as before:

−x2+4x+5=−[(x−2)2−4]+5=−(x−2)2+9\begin{aligned} -x^2 + 4x + 5 &= -\big[(x - 2)^2 - 4\big] + 5 \\ &= -(x - 2)^2 + 9 \end{aligned}

Now the square is subtracted, so the value is never above 9. The vertex (2,9)(2, 9) is a maximum, and the parabola opens downwards, as a=−1a = -1 says.

When half of bb is a fraction

For x2+3x+1x^2 + 3x + 1, half of 3 is 1.5, and (x+1.5)2=x2+3x+2.25(x + 1.5)^2 = x^2 + 3x + 2.25. Taking 2.25 away and adding 1 gives (x+1.5)2−1.25(x + 1.5)^2 - 1.25. The bracket is x+1.5=x−(−1.5)x + 1.5 = x - (-1.5), so the vertex is (−1.5,−1.25)(-1.5, -1.25), to the left of the yy-axis.

The same steps work for any quadratic. Taking aa out leaves x2+baxx^2 + \frac{b}{a}x in the bracket, and half of ba\frac{b}{a} is b2a\frac{b}{2a}. So the square is (x+b2a)2\left(x + \frac{b}{2a}\right)^2, and the vertex is at h=−b2ah = -\frac{b}{2a}.

Rule: Vertex form

ax2+bx+c=a(x−h)2+kh=−b2ak=c−b24a\begin{gathered} ax^2 + bx + c = a(x - h)^2 + k \\[4pt] h = -\frac{b}{2a} \qquad k = c - \frac{b^2}{4a} \end{gathered}

The vertex is (h,k)(h, k): the lowest point if a>0a > 0, the highest if a<0a < 0. Instead of the formula for kk, you can put x=hx = h back into the quadratic.

Try it

SymPy multiplies each completed square back out, so each line should match the quadratic it came from. The last shows decimals (3.0) because 1.5 is typed as a decimal.

The loop then uses the rule h=−b2ah = -\frac{b}{2a} and puts hh back in for kk. It finds the four vertices of this section.

⌘/Ctrl + Enter runs the cell

Roots

The roots of a quadratic are the solutions of ax2+bx+c=0ax^2 + bx + c = 0. They are where the parabola meets the xx-axis: its zeros, from lesson 1.1.1. The completed square leads straight to them.

Example 1. (x−3)2−4=0(x - 3)^2 - 4 = 0 gives (x−3)2=4(x - 3)^2 = 4. Both 2 and −2-2 square to 4, so x−3=±2x - 3 = \pm 2. The roots are x=1x = 1 and x=5x = 5, the two zeros in the table.

The roots sit either side of the axis by the same distance: 3−23 - 2 and 3+23 + 2. Every quadratic with two roots has this mirror pattern.

Example 2. 2(x−2)2−5=02(x - 2)^2 - 5 = 0 gives (x−2)2=2.5(x - 2)^2 = 2.5, so x=2±2.5x = 2 \pm \sqrt{2.5}. Since 2.5≈1.5811\sqrt{2.5} \approx 1.5811, the roots are about 0.4189 and 3.5811. A table of whole numbers would never land on them.

The same steps, done once on ax2+bx+c=0ax^2 + bx + c = 0 with letters, give a formula for every quadratic.

Rule: Quadratic formula

x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

The ±\pm gives two answers, one with ++ and one with −-. Their midpoint is −b2a-\frac{b}{2a}, the axis of symmetry, and they sit the same distance either side of it.

For 2x2−8x+32x^2 - 8x + 3, the number under the root is 64−24=4064 - 24 = 40, so x=8±404x = \frac{8 \pm \sqrt{40}}{4}. Since 404≈1.5811\frac{\sqrt{40}}{4} \approx 1.5811, that is 2±1.58112 \pm 1.5811 again.

Two roots, one or none

The number under the square root, b2−4acb^2 - 4ac, is the discriminant. Its sign says how many real roots there are.

  • Positive: two roots. For x2−6x+5x^2 - 6x + 5 it is 36−20=1636 - 20 = 16, and the roots are 1 and 5.
  • Zero: one root. x2−6x+9x^2 - 6x + 9 is (x−3)2(x - 3)^2. Its discriminant is 36−36=036 - 36 = 0, and the vertex (3,0)(3, 0) touches the axis at the single root 3.
  • Negative: no real roots. x2−6x+13x^2 - 6x + 13 is (x−3)2+4(x - 3)^2 + 4, never below 4. Its discriminant is 36−52=−1636 - 52 = -16.

For a>0a > 0 the height of the vertex decides: below the axis gives two roots, on it one, above it none. The sign of b2−4acb^2 - 4ac says the same.

A negative discriminant would need the square root of a negative number, which has no real value (lesson 1.1.1). Lesson 1.7.2 gives such roots a meaning, as complex numbers.

Try it

The loop prints the discriminant 36−4c36 - 4c of x2−6x+cx^2 - 6x + c for the three curves above.

Then it applies the formula to 2x2−8x+32x^2 - 8x + 3, rounded to 4 places. np.roots takes the coefficients [a, b, c] and lists the larger root first. For a negative discriminant it returns complex numbers, written with j.

⌘/Ctrl + Enter runs the cell

Lesson 1.3.1 shows how each root gives a factor. Case study 1.2.4 uses the vertex to find the least risky mix of two assets.

Common mistakes

  1. The vertex is at −b2a-\frac{b}{2a}, minus sign included. For x2−6x+5x^2 - 6x + 5 that is +3+3. And (x+1.5)2(x + 1.5)^2 puts the vertex at −1.5-1.5.
  2. Keep the balance. (x−3)2(x - 3)^2 brings in an extra 9, so take 9 away: x2−6x+5=(x−3)2−9+5x^2 - 6x + 5 = (x - 3)^2 - 9 + 5.
  3. Take aa out first, then multiply back. 2x2−8x+32x^2 - 8x + 3 is 2(x−2)2−52(x - 2)^2 - 5, not 2(x−2)2−12(x - 2)^2 - 1.
  4. Minimum or maximum depends on the sign of aa. −(x−2)2+9-(x - 2)^2 + 9 has a highest value, 9, and no lowest.
  5. (x−3)2=4(x - 3)^2 = 4 has two solutions. Both x−3=2x - 3 = 2 and x−3=−2x - 3 = -2 count.
  6. Divide all of −b±b2−4ac-b \pm \sqrt{b^2 - 4ac} by 2a2a, not just the square root.
  7. A negative discriminant means no real roots. Do not drop its minus sign to force a square root.
  8. With a=0a = 0 there is no quadratic. The formulas would divide by zero; solve the line bx+c=0bx + c = 0 instead.

Quadratics

0 of 12 correct

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

Summary card

  • y=ax2+bx+cy = ax^2 + bx + c with a≠0a \neq 0 draws a parabola. It opens upwards when a>0a > 0; cc is the yy-intercept.
  • The vertex is the lowest point (if a>0a > 0) or the highest (if a<0a < 0), at x=−b2ax = -\frac{b}{2a}. The axis of symmetry is the vertical line through it.
  • Completing the square writes the quadratic as a(x−h)2+ka(x - h)^2 + k, with vertex (h,k)(h, k). Take aa out first, and halve the coefficient of xx.
  • Roots: x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}, the same distance either side of the axis.
  • The discriminant b2−4acb^2 - 4ac: positive gives two roots, zero one, negative none.

Free further reading

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

  • Parabolas

    Paul's Online Notes. Notes.

    Graphing parabolas from their vertex, with completing the square worked step by step.

  • College Algebra 2e, 2.5 Quadratic Equations

    OpenStax. Free book.

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