Polynomial Evaluator | Compute f(x)
Evaluate any polynomial at a given value of x using Horner method.
Enter coefficients from highest to lowest degree. Example: 1 -3 2 = x² − 3x + 2. Include zeros for missing terms.
Presets
What Is the Polynomial Evaluator | Compute f(x)?
This polynomial evaluator computes P(x) for any polynomial entered as space- or comma-separated coefficients (highest degree first). It uses Horner's method for efficient evaluation, computes the derivative P′(x) analytically, and finds real roots using Newton–Raphson with 15 different starting points to catch multiple roots.
- ›Horner's method: Evaluates degree-n polynomial in exactly n multiplications and n additions, optimal complexity.
- ›Step-by-step trace: Every intermediate value in Horner's scheme is shown for educational clarity.
- ›Derivative: P′(x) is computed analytically by the power rule; P′(xval) is evaluated at the same point.
- ›Root finding: Newton–Raphson from 15 seed values finds all real roots for degree ≤ 12 polynomials.
- ›5 presets: Common polynomials for quick exploration, x²−3x+2, x²−4, quadratic, cubic, factored cubic.
Formula
| Operation | Formula | Multiplications |
|---|---|---|
| Direct evaluation | Sum each aₖxᵏ term | O(n²), inefficient |
| Horner's method | (···((aₙx + aₙ₋₁)x + aₙ₋₂)···)x + a₀ | O(n), optimal |
| Derivative P′(x) | kaₖxᵏ⁻¹ for each term | n−1 multiplications |
| Newton root step | x − P(x)/P′(x) | Quadratic convergence |
How to Use
- 1Enter coefficients from highest to lowest degree, separated by spaces or commas. For 2x³ − 5x² + 3x − 1, enter: 2 -5 3 -1.
- 2Include zeros for missing terms. For x³ − 1 (no x² or x term), enter: 1 0 0 -1.
- 3Enter the value of x to evaluate at.
- 4Press Enter or click Evaluate.
- 5Read P(x), P′(x), Horner's steps, and any real roots found.
- 6Click Clear to reset.
Example Calculation
Evaluating 2x³ − 5x² + 3x − 1 at x = 3
Why Horner's method is preferred
Understanding Polynomial Evaluator | Compute f(x)
Horner's Method
Horner's method (also called synthetic division or the nested multiplication scheme) rewrites P(x) = a₀ + a₁x + a₂x² + ··· + aₙxⁿ in the form P(x) = a₀ + x(a₁ + x(a₂ + ··· + x(aₙ₋₁ + xaₙ)···)). This nesting eliminates repeated power calculations. The method was known to Qin Jiushao (1247) and later described by Horner (1819). It is the algorithm used internally by virtually every computer algebra system for polynomial evaluation.
Newton–Raphson Root Finding
Newton's method finds a root of P(x) = 0 by iterating xₙ₊₁ = xₙ − P(xₙ)/P′(xₙ). Starting from an initial guess x₀, each iteration squares the number of correct decimal places, quadratic convergence. This calculator tries 15 different starting values (−50 to +50) and deduplicates roots within 10⁻⁵, catching multiple distinct real roots. Note that complex roots, repeated roots, and roots with |x| > 50 may not be found.
- ›Convergence is quadratic near a simple root: if error is 10⁻³ at one step, it is 10⁻⁶ at the next
- ›Near a double root, convergence degrades to linear, the method may require many more iterations
- ›Divergence occurs when P′(x) ≈ 0 at the current iterate, division by near-zero causes wild steps
- ›The Durand–Kerner method finds all roots simultaneously but is more complex to implement
Polynomial Derivatives and the Power Rule
The derivative of P(x) = aₙxⁿ + ··· + a₁x + a₀ is P′(x) = naₙxⁿ⁻¹ + ··· + a₁. Each coefficient is multiplied by its power and the power is reduced by one. The constant term vanishes. P′(x) has applications beyond root finding: it gives the slope of P at any point, determines local maxima and minima (where P′ = 0), and is used in Taylor series expansions.
| Polynomial P(x) | Derivative P′(x) | Roots of P′ |
|---|---|---|
| x² − 3x + 2 | 2x − 3 | x = 1.5 (minimum) |
| x³ − 6x² + 11x − 6 | 3x² − 12x + 11 | x ≈ 1.42, 2.58 |
| x⁴ − 5x² | 4x³ − 10x | x = 0, ±√2.5 ≈ ±1.58 |
Frequently Asked Questions
How do I enter a polynomial with missing terms?
Include a zero coefficient for every missing term, coefficients must go from highest degree to lowest degree without gaps. The degree of the polynomial is always one less than the total number of coefficients you enter. Missing an intermediate term is the most common input error, so it is worth double-checking the count: a degree-4 polynomial needs exactly 5 coefficients.
- ›x⁴ − 5x + 2 (no x³ or x² terms): enter 1 0 0 -5 2, 5 coefficients for degree 4
- ›x³ − 1 (no x² or x terms): enter 1 0 0 -1, 4 coefficients for degree 3
- ›x² + 1 (no x term): enter 1 0 1, 3 coefficients for degree 2
- ›Separator can be spaces, commas, or a mix: "1, 0, -5, 2" works the same as "1 0 -5 2"
What is Horner's method and why is it better?
Horner's method rewrites a degree-n polynomial as nested multiplications: P(x) = a₀ + x(a₁ + x(a₂ + ···x(aₙ₋₁ + xaₙ)···)). Starting from the innermost bracket and working outward, each step is one multiply and one add. This requires exactly n multiplications and n additions total, the provably minimum number of operations (Ostrowski, 1954). Direct evaluation of each term aₖxᵏ requires O(n²) multiplications because each power must be computed separately. Beyond speed, Horner's method is more numerically stable because it avoids computing large intermediate values like x¹⁰ that might cause overflow or catastrophic cancellation.
- ›Degree 10 direct: 55 multiplications; Horner: 10 multiplications, 5.5× fewer operations
- ›Degree 20 direct: 210 multiplications; Horner: 20, 10.5× fewer
- ›Numerically: avoids x^10 which could be 10^20 for x=10, causing precision loss in floating point
- ›Also used in synthetic division: the intermediate values are the coefficients of the quotient P(x)/(x−r)
Why might Newton's method miss some roots?
Newton's method is a local search, it finds the root nearest to the starting point but can miss roots in other regions. This calculator uses 15 starting points spread from −50 to +50, which catches most roots of typical polynomials, but several failure modes exist. Understanding them helps you recognise when the reported roots may be incomplete.
- ›Complex roots: Newton's method (with real arithmetic) only finds real roots, complex pairs are invisible
- ›Roots outside [−50, 50]: the 15 starting points do not reach extreme roots, try evaluating at those values manually
- ›Double/repeated roots: convergence degrades to linear speed and the tolerance check may fail to recognise the root
- ›Flat regions (P′(x) ≈ 0): division by near-zero sends the iterate to infinity, the method diverges
- ›Guarantee: for complete root finding, Sturm sequences + bisection finds all real roots in any interval
How is the derivative P′(x) computed?
The power rule applies term by term: if P(x) = Σ aₖxᵏ, then P′(x) = Σ k·aₖxᵏ⁻¹. In terms of the coefficient array [aₙ, aₙ₋₁, ..., a₁, a₀], the derivative coefficients are [n·aₙ, (n−1)·aₙ₋₁, ..., 1·a₁], drop the constant term and multiply each remaining coefficient by its corresponding degree. P′(x) is then evaluated at the same x value using Horner's method for accuracy and efficiency.
What is synthetic division and how does it relate?
Synthetic division is Horner's method applied to dividing P(x) by the linear factor (x − r). The intermediate values generated during Horner's evaluation are exactly the coefficients of the quotient polynomial Q(x), where P(x) = (x − r)·Q(x) + P(r). This means evaluating P at x = r simultaneously performs polynomial long division, giving both the remainder P(r) and the fully factored quotient. This is why Horner's method is sometimes called "evaluation by synthetic division" in algebra textbooks.
- ›If P(r) = 0, then r is a root and (x−r) is an exact factor, Q(x) = P(x)/(x−r)
- ›Repeated synthetic division peels off one root at a time to find all factors
- ›The method is particularly efficient when testing many candidate rational roots (rational root theorem)
- ›Deflation: after finding one root r, continue root-finding on Q(x) (degree reduced by 1)
How do I find all roots of a cubic or quartic?
For cubics (degree 3), Cardano's formula (1545) gives exact closed-form roots, but the expressions involve cube roots of complex numbers even when the roots are real, the so-called "casus irreducibilis". For quartics, Ferrari's method (also 1545) reduces the quartic to a cubic. For degree ≥ 5, Abel's impossibility theorem (1824) proves no general formula using radicals exists, numerical methods are necessary. This calculator uses Newton–Raphson from 15 starting points, which works well for degrees up to about 12.
- ›Degree 2 (quadratic): quadratic formula x = (−b ± √(b²−4ac)) / 2a, exact, always works
- ›Degree 3 (cubic): Cardano's formula, exact but algebraically complex
- ›Degree 4 (quartic): Ferrari's method, exact but very tedious by hand
- ›Degree ≥ 5: no general algebraic formula, use Newton-Raphson, Durand-Kerner, or Jenkins-Traub
What is the Fundamental Theorem of Algebra?
Every non-constant polynomial of degree n with complex coefficients has exactly n roots in the complex numbers, counted with multiplicity. This means a degree-n polynomial can always be factored as P(x) = aₙ(x − r₁)(x − r₂)···(x − rₙ). For polynomials with real coefficients, complex roots always come in conjugate pairs a ± bi. Consequently, a degree-n real polynomial has at most n real roots, and its complex roots count comes in even numbers.
- ›Degree 1: always exactly 1 real root
- ›Degree 2: 0, 1, or 2 real roots (2 complex if discriminant < 0)
- ›Degree 3: always at least 1 real root (complex roots come in pairs)
- ›Degree 5: 1, 3, or 5 real roots, the remaining 4, 2, or 0 are complex conjugate pairs
- ›This is why Newton's method (real arithmetic) may find fewer roots than the polynomial's degree
Can I evaluate polynomials at complex numbers?
This calculator evaluates at real values of x only. Evaluating at a complex x = a + bi requires tracking real and imaginary parts separately through each step of Horner's algorithm. Each multiplication (a+bi)(c+di) = (ac−bd) + (ad+bc)i involves both real and imaginary arithmetic. The algorithm structure is identical, it is just the arithmetic that becomes 2D. For complex evaluation, Python's NumPy handles this natively, accepting complex inputs directly.
- ›Python: import numpy as np; np.polyval([2, -5, 3, -1], 1+2j)
- ›NumPy: np.roots([2, -5, 3, -1]) finds all roots including complex ones
- ›Wolfram Alpha: type "2x^3 - 5x^2 + 3x - 1 at x = 1+2i" for instant complex evaluation
- ›Complex evaluation is essential when checking whether a polynomial has the expected complex roots