polynomial_eval

polynomial_eval(coefficients, x, variant='standard', n=None)

Evaluate a polynomial.

Mirrors the C# Evaluate class’s three polynomial evaluators (Horner’s method), vectorized over x against one shared coefficients array: variant="standard" calls Evaluate.Polynomial (coefficients in ASCENDING order, coefficients[0] the constant term); "reverse" calls Evaluate.PolynomialRev (coefficients in DESCENDING order, coefficients[0] the highest-order term), optionally truncated to order n + 1 via n; "reverse_unit" calls Evaluate.PolynomialRev_1 (DESCENDING order with an implicit leading coefficient of 1).

Parameters

Name Type Description Default
coefficients array_like Polynomial coefficients. required
x array_like Points at which to evaluate. required
variant ('standard', 'reverse', 'reverse_unit') "standard"
n int Redefines the polynomial’s order to n + 1. Only valid with variant="reverse". None

Returns

Name Type Description
numpy.ndarray

Examples

>>> from corehydropy import polynomial_eval
>>> polynomial_eval([3, 5, 7], 4)
array([135.])
>>> polynomial_eval([3, 5, 7], 4, variant="reverse")
array([75.])
>>> polynomial_eval([3, 5, 7], 4, variant="reverse", n=1)
array([17.])