TExcelTAD
Home › Calculus Essentials › Polynomials and Their Roots

Polynomials and Their Roots

Polynomials are the simplest functions that can curve: sums of whole-number powers of xx with constant coefficients. They are easy to evaluate, differentiate and integrate, which is why calculus, computer graphics and numerical code approximate almost everything else with them. This lesson covers their shape and how to find their roots.

Vocabulary

p(x)=anxn+an−1xn−1+⋯+a1x+a0an≠0p(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0 \qquad a_n \ne 0
Term Meaning In p(x)=2x3−3x2−11x+6p(x) = 2x^3 - 3x^2 - 11x + 6
degree highest power nn 3 (a cubic)
leading coefficient ana_n 2
constant term a0a_0, the value p(0)p(0) 6
root (zero) a number rr with p(r)=0p(r) = 0 3, −2 and 1/21/2

Names by degree: 0 constant, 1 linear, 2 quadratic, 3 cubic, 4 quartic, 5 quintic.

Shape of the graph

  • A polynomial of degree nn has at most nn real roots and at most n−1n - 1 turning points.
  • End behaviour depends only on the leading term anxna_n x^n: for large ∣x∣\lvert x \rvert the other terms do not matter.
Degree Leading coefficient > 0 Leading coefficient < 0
even up on both ends (like x2x^2) down on both ends
odd down on the left, up on the right (like x3x^3) up on the left, down on the right

An odd-degree polynomial must therefore cross the xx-axis at least once: every cubic has a real root.

  • At a root of multiplicity kk (the factor (x−r)(x - r) appears kk times) the graph crosses the axis if kk is odd and only touches it if kk is even. (x−1)2(x+2)(x - 1)^2(x + 2) touches at 1 and crosses at −2.

The factor theorem

p(r)=0  ⟺  (x−r) is a factor of p(x)p(r) = 0 \iff (x - r) \text{ is a factor of } p(x)

Once you know one root, divide it out to get a polynomial of lower degree. For integer coefficients, the rational root theorem gives the candidates: any rational root p/qp/q in lowest terms has pp dividing the constant term and qq dividing the leading coefficient.

For 2x3−3x2−11x+62x^3 - 3x^2 - 11x + 6 the candidates are ±1,±2,±3,±6,±1/2,±3/2\pm 1, \pm 2, \pm 3, \pm 6, \pm 1/2, \pm 3/2. Trying them:

python · try it yourself
from fractions import Fraction as F

def p(x):
    return 2*x**3 - 3*x**2 - 11*x + 6

candidates = sorted({F(s * a, b) for a in [1, 2, 3, 6] for b in [1, 2] for s in [1, -1]})
roots = [c for c in candidates if p(c) == 0]
print("candidates:", [str(c) for c in candidates])
print("roots:", [str(r) for r in roots])
candidates: ['-6', '-3', '-2', '-3/2', '-1', '-1/2', '1/2', '1', '3/2', '2', '3', '6']
roots: ['-2', '1/2', '3']

So 2x3−3x2−11x+6=(x+2)(2x−1)(x−3)2x^3 - 3x^2 - 11x + 6 = (x + 2)(2x - 1)(x - 3). Fraction keeps the arithmetic exact, so p(c) == 0 is a safe test here; with floats you would compare against a small tolerance instead.

The quadratic formula

For degree 2 there is a formula for the roots of ax2+bx+c=0ax^2 + bx + c = 0:

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

The discriminant D=b2−4acD = b^2 - 4ac says what kind of roots to expect:

DD Roots
D>0D > 0 two different real roots
D=0D = 0 one repeated real root
D<0D < 0 no real roots: two complex roots (see Complex Numbers)

Formulas exist for degrees 3 and 4 but are long. For degree 5 and higher, no general formula using roots exists (the Abel–Ruffini theorem), so in practice roots are found numerically.

Roots in Python

SymPy factors and solves exactly; NumPy finds all roots numerically from the list of coefficients (highest power first):

python · try it yourself
import sympy as sp
import numpy as np

x = sp.symbols('x')
p = 2*x**3 - 3*x**2 - 11*x + 6
print("factor:", sp.factor(p))
print("solve: ", sp.solve(p, x))
print("x^2 + 2x + 5:", sp.solve(x**2 + 2*x + 5, x))

print("np.roots:", np.roots([2, -3, -11, 6]))
q = np.poly1d([1, 0, -2, -5])            # x³ − 2x − 5, no rational roots
print("x³ − 2x − 5 real root ≈", round(np.roots(q).real[0], 6))
factor: (x - 3)*(x + 2)*(2*x - 1)
solve:  [-2, 1/2, 3]
x^2 + 2x + 5: [-1 - 2*I, -1 + 2*I]
np.roots: [ 3.  -2.   0.5]
x³ − 2x − 5 real root ≈ 2.094551

SymPy writes the imaginary unit as I. np.roots returns the roots in no particular order, and for x3−2x−5x^3 - 2x - 5 it also returns two complex roots; .real[0] picks the real part of the first one, which here happens to be the real root. In robust code you would filter by a small imaginary part instead.

Graph of a cubic

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

coeffs = [2, -3, -11, 6]
xs = np.linspace(-3, 4, 400)
ys = np.polyval(coeffs, xs)
roots = np.roots(coeffs)

plt.figure(figsize=(6, 4))
plt.plot(xs, ys)
plt.scatter(roots, np.zeros_like(roots), color="C3", zorder=3, label="roots")
plt.axhline(0, color="gray", linewidth=0.8)
plt.grid(alpha=0.3); plt.legend()
plt.title("2x³ − 3x² − 11x + 6")

turns = np.roots(np.polyder(coeffs))     # where the slope is zero
print("turning points at x ≈", np.round(np.sort(turns), 4))
turning points at x ≈ [-0.9434  1.9434]

The turning points sit where the derivative 6x2−6x−116x^2 - 6x - 11 is zero, a first preview of how calculus finds peaks and valleys.

In software

  • Horner's method evaluates anxn+⋯+a0a_n x^n + \cdots + a_0 as (…((anx+an−1)x+an−2)x…)+a0(\ldots((a_n x + a_{n-1})x + a_{n-2})x \ldots) + a_0, with nn multiplications and no powers. np.polyval and most math libraries do exactly this.
  • Approximation: libraries compute sin, exp and log with carefully chosen polynomials (Taylor series).
  • Graphics: Bézier curves are cubic polynomials in tt, and ray tracing a sphere means solving a quadratic (Ray vs Sphere).
  • ML: polynomial regression fits a polynomial to data.
  • Error-correcting codes (Reed–Solomon, QR codes) and CRC checksums use polynomials over finite fields.

Exercises

Exercise 1: Describe a polynomial

For p(x)=−x4+3x2+2xp(x) = -x^4 + 3x^2 + 2x, give the degree, the leading coefficient, the end behaviour and the maximum number of turning points.

Answer

Degree 4, leading coefficient −1, down on both ends, at most 3 turning points.

Solution

The highest power is x4x^4 with coefficient −1. Even degree with a negative leading coefficient means p(x)→−∞p(x) \to -\infty as x→±∞x \to \pm\infty. A degree-4 polynomial has at most 4−1=34 - 1 = 3 turning points.

Exercise 2: Quadratic formula

Solve 3x2−5x−2=03x^2 - 5x - 2 = 0 and state the discriminant.

Answer

D=49D = 49; roots x=2x = 2 and x=−1/3x = -1/3.

Solution
D=(−5)2−4⋅3⋅(−2)=25+24=49x=5±76  ⇒  x=126=2orx=−26=−13\begin{aligned} D &= (-5)^2 - 4 \cdot 3 \cdot (-2) = 25 + 24 = 49 \\ x &= \frac{5 \pm 7}{6} \;\Rightarrow\; x = \tfrac{12}{6} = 2 \quad\text{or}\quad x = -\tfrac{2}{6} = -\tfrac{1}{3} \end{aligned}

Exercise 3: Factor a cubic

Find all roots of x3−4x2+x+6x^3 - 4x^2 + x + 6 using the rational root theorem, then factor it.

Answer

Roots −1, 2, 3; (x+1)(x−2)(x−3)(x + 1)(x - 2)(x - 3).

Solution

Candidates are the divisors of 6: ±1,±2,±3,±6\pm 1, \pm 2, \pm 3, \pm 6. p(−1)=−1−4−1+6=0p(-1) = -1 - 4 - 1 + 6 = 0, so (x+1)(x + 1) is a factor. Dividing leaves x2−5x+6=(x−2)(x−3)x^2 - 5x + 6 = (x - 2)(x - 3).

python · try it yourself
import sympy as sp

x = sp.symbols('x')
print(sp.factor(x**3 - 4*x**2 + x + 6))
(x - 3)*(x - 2)*(x + 1)

Exercise 4: Horner's method

Write horner(coeffs, x) (coefficients from the highest power) and evaluate 2x3−3x2−11x+62x^3 - 3x^2 - 11x + 6 at x=4x = 4 and x=0.5x = 0.5. Compare with np.polyval.

Answer

p(4)=42p(4) = 42, p(0.5)=0.0p(0.5) = 0.0.

Solution
python · try it yourself
import numpy as np

def horner(coeffs, x):
    result = 0
    for a in coeffs:
        result = result * x + a
    return result

c = [2, -3, -11, 6]
print(horner(c, 4), horner(c, 0.5))
print(np.polyval(c, 4), np.polyval(c, 0.5))
42 0.0
42 0.0

By hand: ((2⋅4−3)⋅4−11)⋅4+6=(5⋅4−11)⋅4+6=9⋅4+6=42((2 \cdot 4 - 3) \cdot 4 - 11) \cdot 4 + 6 = (5 \cdot 4 - 11) \cdot 4 + 6 = 9 \cdot 4 + 6 = 42.

Test yourself

How many real roots can a polynomial of degree 5 have?

  1. Exactly 5
  2. At least 1 and at most 5
  3. At most 4
  4. Any number

The discriminant of x2+4x+7x^2 + 4x + 7 is negative. What does that mean?

  1. One repeated root
  2. Two real roots
  3. No real roots; two complex roots
  4. The polynomial is constant

If p(4)=0p(4) = 0, which statement must be true?

  1. (x+4)(x + 4) is a factor of pp
  2. pp has degree 4
  3. (x−4)(x - 4) is a factor of pp
  4. p(−4)=0p(-4) = 0