SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 1.3.1 Polynomials and their rootsConcept · 25 min
      2. 1.3.2 Bisection: finding a root by halvingConcept · 25 min
      3. 1.3.3 Newton's method, a first lookConcept · 25 min
      4. 1.3.4 Practice set: rootsPractice set · 20 min
      5. 1.3.5 Case study: IRR and yield to maturityCase study · 35 min

Level 1, Precalculus 1.3 Equations and roots Lesson 1 of 5

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

Polynomials and their roots

What a polynomial is

A polynomial adds up whole-number powers of xx, each multiplied by a fixed number:

p(x)=anxn+an−1xn−1+⋯+a1x+a0p(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0

The fixed numbers an,…,a1,a0a_n, \ldots, a_1, a_0 are the coefficients. The highest power with a nonzero coefficient, nn, is the degree. The last coefficient, a0a_0, is the constant term: it is the value at zero, p(0)=a0p(0) = a_0.

polynomialdegreename
770constant
3x−63x - 61linear: a line, lesson 1.2.1
x2−5x+6x^2 - 5x + 62quadratic, lesson 1.2.2
x3−6x2+11x−6x^3 - 6x^2 + 11x - 63cubic
x4−5x2+4x^4 - 5x^2 + 44quartic

The powers must be 0, 1, 2, 3 and so on. So 1x\frac{1}{x} and x\sqrt{x} are not polynomials, and neither is 2x2^x, where xx sits in the power.

Evaluating a polynomial

To evaluate pp at a number, put that number in place of every xx. The running example in this lesson is the cubic p(x)=x3−6x2+11x−6p(x) = x^3 - 6x^2 + 11x - 6. At x=4x = 4 its terms are 64−96+44−664 - 96 + 44 - 6, so p(4)=6p(4) = 6.

Here is pp at more inputs. At 0 it is −6-6, its constant term.

xx0.511.522.53
p(x)p(x)−1.875-1.87500.3750−0.375-0.3750

Try it

NumPy stores a polynomial as its list of coefficients, highest power first, with a 0 for each missing power. np.polyval evaluates it at one input or at a whole list.

The second line is the table. The cubic x3−7x+6x^3 - 7x + 6 has no x2x^2 term, so its list is [1, 0, -7, 6].

⌘/Ctrl + Enter runs the cell

Roots and factors

A root of pp is an input rr with p(r)=0p(r) = 0. On the graph, the roots are where the curve meets the xx-axis: the zeros of lesson 1.1.1. The table shows three roots of the cubic: 1, 2 and 3.

Those roots come from factors. Multiply out (x−1)(x−2)(x−3)(x - 1)(x - 2)(x - 3), two brackets at a time:

(x−1)(x−2)(x−3)=(x2−3x+2)(x−3)=x3−6x2+11x−6\begin{aligned} &(x - 1)(x - 2)(x - 3) \\ &= (x^2 - 3x + 2)(x - 3) \\ &= x^3 - 6x^2 + 11x - 6 \end{aligned}

A product is zero exactly when one of its factors is zero. So the factored form shows the roots at a glance.

Rule: Factor theorem

p(r)=0exactly when(x−r) is a factor of p(x)\begin{gathered} p(r) = 0 \\ \text{exactly when} \\ (x - r) \text{ is a factor of } p(x) \end{gathered}

If rr is a root, then p(x)p(x) is (x−r)(x - r) times a polynomial one degree lower. If (x−r)(x - r) is a factor, then rr is a root. A negative root −3-3 gives the factor x+3x + 3.

The cubic crosses the axis at its three roots, one for each factor. Its sign flips at each root.

Finding the other roots from one

Once you know one root, the rest come from a polynomial of lower degree. Take q(x)=x3−7x+6q(x) = x^3 - 7x + 6.

When the coefficients are whole numbers, a whole-number root must divide the constant term, so try ±1,±2,±3,±6\pm 1, \pm 2, \pm 3, \pm 6. The first try works: q(1)=1−7+6=0q(1) = 1 - 7 + 6 = 0.

So q(x)=(x−1)(x2+bx+c)q(x) = (x - 1)(x^2 + bx + c) for some numbers bb and cc. Multiply out the right side, then match each power with x3+0x2−7x+6x^3 + 0x^2 - 7x + 6:

(x−1)(x2+bx+c)=x3+(b−1)x2+(c−b)x−c\begin{gathered} (x - 1)(x^2 + bx + c) \\ = x^3 + (b - 1)x^2 + (c - b)x - c \end{gathered}

The x2x^2 terms give b−1=0b - 1 = 0, so b=1b = 1. The constants give −c=6-c = 6, so c=−6c = -6. The xx terms check the answer: c−b=−7c - b = -7, as it should be.

The quadratic factor is x2+x−6=(x−2)(x+3)x^2 + x - 6 = (x - 2)(x + 3), by factoring or by the quadratic formula of lesson 1.2.2. So q(x)=(x−1)(x−2)(x+3)q(x) = (x - 1)(x - 2)(x + 3), with roots 1, 2 and −3-3.

Try it

np.polydiv(q, [1, -1]) divides qq by x−1x - 1. It returns the quotient's coefficients, for x2+x−6x^2 + x - 6, and a remainder of 0, which confirms the factor.

np.roots finds every root from the coefficients. Its answers are decimals, in no fixed order.

⌘/Ctrl + Enter runs the cell

Double roots

The quadratic x2−4x+4x^2 - 4x + 4 is (x−2)2(x - 2)^2. Its discriminant is 0 (lesson 1.2.2), and its only root is 2. The factor x−2x - 2 appears twice, so 2 is a double root.

At a double root the graph touches the axis and turns back without crossing. On both sides of 2 the value is positive: 0.01 at 1.9 and 0.01 at 2.1. The sign does not change.

A cubic can have one too: (x−1)2(x−3)(x - 1)^2(x - 3) multiplies out to x3−5x2+7x−3x^3 - 5x^2 + 7x - 3. It is −0.625-0.625 at 0.5, 0 at 1 and −0.375-0.375 at 1.5, so it touches the axis at 1; at 3 it crosses.

In general, a factor repeated an even number of times touches the axis, and one repeated an odd number of times crosses it.

How many roots

The factor theorem limits the count. Each root takes a factor (x−r)(x - r) of degree 1, and a polynomial of degree nn has room for only nn of them.

Rule: Counting roots

degree n  ⟹  at most n real roots\text{degree } n \;\Longrightarrow\; \text{at most } n \text{ real roots}

A polynomial of degree nn has at most nn real roots, counting a double root twice. It may have fewer.

The cubic x3−4x=x(x−2)(x+2)x^3 - 4x = x(x - 2)(x + 2) has the full three: −2-2, 0 and 2. Its constant term is 0, so 0 is a root. Fewer is common: (x−1)2(x−3)(x - 1)^2(x - 3) has two different roots, and x3−8x^3 - 8 has just one, 2.

Three cubics with three, two and one real roots. None can have more than three.

An odd degree always gives at least one real root. Far from 0 the highest power outweighs the rest: at x=100x = 100, x3x^3 is 1,000,000 while the other terms of pp add up to −58,906-58{,}906. So a cubic ends far below the axis on one side and far above it on the other, and must cross in between.

An even degree can miss the axis altogether. x2+1x^2 + 1 is never below 1, so it has no real root.

Try it

np.roots always returns nn roots for degree nn. For x3−8x^3 - 8 it gives 2 and two complex roots, written with j; for x2+1x^2 + 1, only complex ones. They are not real numbers and do not appear on the graph; lesson 1.7.2 introduces them.

For the double root, rounding error pulls the two copies of 1 slightly apart: each gets a tiny j part, about 1.5×10−81.5 \times 10^{-8}. Rounding to six places shows 1 twice.

⌘/Ctrl + Enter runs the cell

Sign changes

Between two neighbouring roots a polynomial keeps one sign, and at a single root the sign flips. The cubic pp shows it: −1.875-1.875 at 0.5, then 0.375 at 1.5, then −0.375-0.375 at 2.5.

The graph of a polynomial has no gaps or jumps. So it cannot get from below the axis to above it without crossing, and two values are enough to prove a root exists.

Rule: A sign change brackets a root

p(a)⋅p(b)<0means a root lies between a and b\begin{gathered} p(a) \cdot p(b) < 0 \\ \text{means a root lies between } a \text{ and } b \end{gathered}

Opposite signs give a negative product, and then at least one root lies between aa and bb. Lesson 1.3.2 uses this to trap a root and close in on it.

The test only works one way.

  • A sign change means at least one root, not exactly one. p(0)=−6p(0) = -6 and p(4)=6p(4) = 6, and all three roots lie between.
  • No sign change does not mean no root. p(0.5)p(0.5) and p(2.5)p(2.5) are both negative, yet the roots 1 and 2 lie between them. A double root gives no sign change either.

A graph with no gaps or jumps is called continuous; lesson 2.1.2 makes the idea exact. Case study 1.3.5 meets a polynomial whose roots are interest rates.

Try it

brackets applies the rule to two inputs. It gives True for 0.5 and 1.5, and for 0 and 4.

It gives False for 0.5 and 2.5, although two roots lie between them.

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. A root rr gives the factor (x−r)(x - r), not (x+r)(x + r). The root −3-3 gives x+3x + 3.
  2. The degree is the highest power, not the number of terms. x5+1x^5 + 1 has degree 5.
  3. Give NumPy every power, highest first. x3−7x+6x^3 - 7x + 6 is [1, 0, -7, 6]; [1, -7, 6] would mean x2−7x+6x^2 - 7x + 6.
  4. At most nn roots, not exactly nn. The j answers of np.roots are not real roots, and a tiny j part on a real number is rounding.
  5. No sign change does not mean no root. Two roots, or a double root, leave the sign unchanged.
  6. A sign change means at least one root. There may be three, or any odd number.

Polynomials and roots

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

  • A polynomial of degree nn adds powers of xx up to xnx^n, each with a coefficient; its constant term is p(0)p(0).
  • rr is a root when p(r)=0p(r) = 0, and then (x−r)(x - r) is a factor. Knowing one root leaves a polynomial one degree lower.
  • A double root, from a squared factor, touches the axis without crossing.
  • Degree nn means at most nn real roots. An odd degree has at least one.
  • If p(a)p(a) and p(b)p(b) have opposite signs, at least one root lies between them. No sign change does not rule a root out.
  • np.polyval(coeffs, x) evaluates, np.polydiv divides out a factor, and np.roots(coeffs) finds every root. List the coefficients highest power first, with 0 for missing powers.

Free further reading

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