Polynomials and Their Roots
Polynomials are the simplest functions that can curve: sums of whole-number powers of 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
| Term | Meaning | In |
|---|---|---|
| degree | highest power | 3 (a cubic) |
| leading coefficient | 2 | |
| constant term | , the value | 6 |
| root (zero) | a number with | 3, −2 and |
Names by degree: 0 constant, 1 linear, 2 quadratic, 3 cubic, 4 quartic, 5 quintic.
Shape of the graph
- A polynomial of degree has at most real roots and at most turning points.
- End behaviour depends only on the leading term : for large the other terms do not matter.
| Degree | Leading coefficient > 0 | Leading coefficient < 0 |
|---|---|---|
| even | up on both ends (like ) | down on both ends |
| odd | down on the left, up on the right (like ) | up on the left, down on the right |
An odd-degree polynomial must therefore cross the -axis at least once: every cubic has a real root.
- At a root of multiplicity (the factor appears times) the graph crosses the axis if is odd and only touches it if is even. touches at 1 and crosses at −2.
The factor theorem
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 in lowest terms has dividing the constant term and dividing the leading coefficient.
For the candidates are . Trying them:
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 . 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 :
The discriminant says what kind of roots to expect:
| Roots | |
|---|---|
| two different real roots | |
| one repeated real root | |
| 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):
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 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
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 is zero, a first preview of how calculus finds peaks and valleys.
In software
- Horner's method evaluates as , with multiplications and no powers.
np.polyvaland most math libraries do exactly this. - Approximation: libraries compute
sin,expandlogwith carefully chosen polynomials (Taylor series). - Graphics: Bézier curves are cubic polynomials in , 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 , 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 with coefficient −1. Even degree with a negative leading coefficient means as . A degree-4 polynomial has at most turning points.
Exercise 2: Quadratic formula
Solve and state the discriminant.
Answer
; roots and .
Solution
Exercise 3: Factor a cubic
Find all roots of using the rational root theorem, then factor it.
Answer
Roots −1, 2, 3; .
Solution
Candidates are the divisors of 6: . , so is a factor. Dividing leaves .
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 at and . Compare with np.polyval.
Answer
, .
Solution
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: .
Test yourself
How many real roots can a polynomial of degree 5 have?
- Exactly 5
- At least 1 and at most 5
- At most 4
- Any number
The discriminant of is negative. What does that mean?
- One repeated root
- Two real roots
- No real roots; two complex roots
- The polynomial is constant
If , which statement must be true?
- is a factor of
- has degree 4
- is a factor of