Polynomial Functions
Polynomials are the simplest functions beyond lines and parabolas: only additions and multiplications by . That makes them cheap to compute, easy to differentiate and good at approximating almost anything. This lesson is about reading a polynomial's graph from its formula: end behaviour, zeros, multiplicities and turning points.
Vocabulary
A polynomial function has the form
- is the degree, the leading coefficient, the constant term (the y-intercept, ).
- Degree 0: constant, 1: linear, 2: quadratic, 3: cubic, 4: quartic, 5: quintic.
- The domain is always all of , and the graph is a smooth unbroken curve with no corners or gaps.
The algebra of polynomials (adding, multiplying, dividing, factoring) is covered in the Algebra course, from polynomial definitions to dividing polynomials. Here we look at them as functions.
End behaviour
For large the leading term dominates all the others, so the ends of the graph depend only on the degree's parity and the leading coefficient's sign:
| even | up on both ends (like ) | down on both ends (like ) |
| odd | down on the left, up on the right (like ) | up on the left, down on the right (like ) |
p = lambda x: 2 * x**3 - 40 * x**2 + 5 * x + 100
for x in [10, 100, 1000, 10_000]:
print(f"x = {x:>6}: p(x) = {p(x):>16}, 2x³ = {2 * x**3:>16}, ratio = {p(x) / (2 * x**3):.4f}")x = 10: p(x) = -1850, 2x³ = 2000, ratio = -0.9250
x = 100: p(x) = 1600600, 2x³ = 2000000, ratio = 0.8003
x = 1000: p(x) = 1960005100, 2x³ = 2000000000, ratio = 0.9800
x = 10000: p(x) = 1996000050100, 2x³ = 2000000000000, ratio = 0.9980
Near the other terms still matter, but further out behaves like .
Zeros, factors and multiplicity
The factor theorem: is a zero of () exactly when is a factor of . A polynomial of degree has at most real zeros. (Counting complex zeros with multiplicity, it has exactly : the fundamental theorem of algebra.)
If appears times in the factorisation, has multiplicity , and the graph's behaviour at tells you whether is odd or even:
| Multiplicity | Graph at |
|---|---|
| 1 | crosses the axis like a line |
| even (2, 4, …) | touches the axis and turns back |
| odd | crosses, flattening out like |
Between consecutive zeros the sign of cannot change, because the graph has no gaps (this is the intermediate value theorem). So the zeros split the line into intervals with a constant sign, which is how you solve polynomial inequalities.
A degree- polynomial has at most turning points (local peaks and valleys).
Example. . Degree 4, leading coefficient : both ends go down. Zeros: (crosses), 1 (touches, multiplicity 2), 3 (crosses). y-intercept: .
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
x = sp.Symbol("x")
p = -(x + 2) * (x - 1)**2 * (x - 3)
print("expanded:", sp.expand(p))
print("zeros with multiplicity:", sp.roots(sp.Poly(p, x)))
print("p(0) =", p.subs(x, 0))
crit = sp.Poly(sp.diff(p, x), x).nroots()
print("turning points at x ≈", [round(float(c), 4) for c in crit])
f = sp.lambdify(x, p, "numpy")
xs = np.linspace(-2.6, 3.6, 400)
plt.figure(figsize=(6, 4))
plt.plot(xs, f(xs), color="purple")
plt.plot([-2, 1, 3], [0, 0, 0], "ko")
plt.axhline(0, color="gray", lw=0.7); plt.ylim(-25, 20); plt.grid(alpha=0.3)
plt.title("p(x) = −(x + 2)(x − 1)²(x − 3)")expanded: -x**4 + 3*x**3 + 3*x**2 - 11*x + 6
zeros with multiplicity: {3: 1, -2: 1, 1: 2}
p(0) = 6
turning points at x ≈ [-1.1472, 1.0, 2.3972]
Three turning points, the maximum possible for degree 4. One of them is the touch point at .
Finding zeros
- Factoring works for small, nice examples.
- Rational root theorem: if has integer coefficients, any rational zero in lowest terms has dividing and dividing . For the candidates are ; testing finds 1, and 3.
- Numerically:
numpy.rootsfinds all complex roots from the coefficient list (it computes the eigenvalues of the companion matrix); for a single root in a bracket, use bisection or Newton's method (Newton's method).
import numpy as np
coeffs = [1, -2, -5, 6] # x³ − 2x² − 5x + 6
candidates = [s * d for d in (1, 2, 3, 6) for s in (1, -1)]
print("rational roots:", sorted(r for r in candidates if np.polyval(coeffs, r) == 0))
print("numpy.roots :", sorted(round(float(r.real), 6) for r in np.roots(coeffs)))
q = [1, 0, 0, 0, -16] # x⁴ − 16
print("roots of x⁴ − 16:", [complex(round(r.real, 6), round(r.imag, 6)) for r in np.roots(q)])rational roots: [-2, 1, 3]
numpy.roots : [-2.0, 1.0, 3.0]
roots of x⁴ − 16: [(-2+0j), 2j, -2j, (2+0j)]
has two real zeros and two complex ones, .
In software
- Fast evaluation with Horner's rule. needs multiplications and no powers.
numpy.polyvaland most math libraries do this (Horner). - Approximating other functions.
math.sinandmath.expare implemented with carefully chosen polynomials on a small interval (Taylor series). - Animation curves. smoothstep eases from 0 to 1 with zero slope at both ends; cubic Bézier curves in CSS
cubic-bezier()and vector graphics are polynomial in (easing, Bézier curves). - Fitting data.
numpy.polyfitfinds the polynomial that best fits points; a high degree overfits, wiggling wildly between the points, a lesson that carries straight into machine learning.
Exercises
Exercise 1: End behaviour
Describe the end behaviour of and of .
Answer
: up on the left, down on the right. : up on both ends.
Solution
has odd degree and negative leading coefficient (like ). has even degree and positive leading coefficient (like ); the term only matters for moderate .
Exercise 2: Read the graph from the factors
For , give the degree, the zeros with multiplicities, and whether the graph crosses or touches at each.
Answer
Degree 6. 0 (mult. 1, crosses), 2 (mult. 2, touches), (mult. 3, crosses with a flattening).
Solution
, leading coefficient , so both ends go up.
import sympy as sp
x = sp.Symbol("x")
print(sp.roots(sp.Poly(x * (x - 2)**2 * (x + 3)**3, x))){2: 2, -3: 3, 0: 1}
Exercise 3: Build a polynomial
Find the cubic with zeros , 2 and 4 whose y-intercept is 16.
Answer
.
Solution
import sympy as sp
x = sp.Symbol("x")
p = 2 * (x + 1) * (x - 2) * (x - 4)
print(sp.expand(p), "| p(0) =", p.subs(x, 0))2*x**3 - 10*x**2 + 4*x + 16 | p(0) = 16
Exercise 4: Solve an inequality
Solve .
Answer
.
Solution
The zeros split into four intervals. Test one point in each:
Exercise 5: Horner's rule
Write horner(coeffs, x) (coefficients from highest degree down) and evaluate at . Check against numpy.polyval.
Answer
.
Solution
import numpy as np
def horner(coeffs, x):
acc = 0
for c in coeffs:
acc = acc * x + c
return acc
c = [2, -3, 0, 1, -7]
print(horner(c, 3), int(np.polyval(c, 3)))77 77
By hand: . Note the 0 in the coefficient list for the missing term; leaving it out is a classic bug.
Test yourself
At most how many turning points can a degree-5 polynomial have?
- 3
- 4
- 5
- 6
. What does the graph do at ?
- Crosses the axis
- Touches the axis and turns back
- Has a vertical asymptote
- Has a gap
Which polynomial falls on both ends?