Numerical methods
Polynomial evaluation
num.polynomialAlso called polynomial, polyval, horner, evaluate polynomial
Value at x of the polynomial with coefficients a0 … an−1 in increasing order of degree, the order numpy.polynomial.polynomial.polyval uses. numpy.polyval takes them in decreasing order, so coefficients written for one evaluate the reversed polynomial in the other.
Notation
coefficients, constant term first
a ∈ ℝn
the point
x ∈ ℝ
number of coefficients
Size, at least 1
Result: the polynomial's value
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
Given
Result
Given
Result
≈ -3.5
Given
Result
Common mistakes
Coefficients in decreasing order of degree
The coefficients are read highest degree first, as numpy.polyval expects.
Fix: Reverse the coefficient array, or use numpy.polynomial.polynomial.polyval.
Powers start at x1
Coefficient ak multiplies xk+1 instead of xk.
Fix: Start the powers at x0 = 1.
Source
Knuth 1997
Knuth, Donald E. The Art of Computer Programming, Volume 2: Seminumerical Algorithms. 3rd ed. Addison-Wesley, 1997.