MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / evaluate_poly

Function evaluate_poly

maths/polynomial_evaluation.py:4–15  ·  view source on GitHub ↗

Evaluate a polynomial f(x) at specified point x and return the value. Arguments: poly -- the coefficients of a polynomial as an iterable in order of ascending degree x -- the point at which to evaluate the polynomial >>> evaluate_poly((0.0, 0.0, 5.0, 9.3, 7.0), 10.0)

(poly: Sequence[float], x: float)

Source from the content-addressed store, hash-verified

2
3
4def evaluate_poly(poly: Sequence[float], x: float) -> float:
5 """Evaluate a polynomial f(x) at specified point x and return the value.
6
7 Arguments:
8 poly -- the coefficients of a polynomial as an iterable in order of
9 ascending degree
10 x -- the point at which to evaluate the polynomial
11
12 >>> evaluate_poly((0.0, 0.0, 5.0, 9.3, 7.0), 10.0)
13 79800.0
14 """
15 return sum(c * (x**i) for i, c in enumerate(poly))
16
17
18def horner(poly: Sequence[float], x: float) -> float:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected