Skip to content

Commit b738281

Browse files
msk4862cclauss
authored andcommitted
maths-polynomial_evalutation (#1214)
* maths-polynomial_evalutation * added doctest and removed redundancy
1 parent 189b350 commit b738281

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: maths/polynomial_evaluation.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def evaluate_poly(poly, x):
2+
"""
3+
Objective: Computes the polynomial function for a given value x.
4+
Returns that value.
5+
Input Prams:
6+
poly: tuple of numbers - value of cofficients
7+
x: value for x in f(x)
8+
Return: value of f(x)
9+
10+
>>> evaluate_poly((0.0, 0.0, 5.0, 9.3, 7.0), 10)
11+
79800.0
12+
"""
13+
14+
return sum(c*(x**i) for i, c in enumerate(poly))
15+
16+
17+
if __name__ == "__main__":
18+
"""
19+
Example: poly = (0.0, 0.0, 5.0, 9.3, 7.0) # f(x) = 7.0x^4 + 9.3x^3 + 5.0x^2
20+
x = -13
21+
print (evaluate_poly(poly, x)) # f(-13) = 7.0(-13)^4 + 9.3(-13)^3 + 5.0(-13)^2 = 180339.9
22+
"""
23+
poly = (0.0, 0.0, 5.0, 9.3, 7.0)
24+
x = 10
25+
print(evaluate_poly(poly, x))

0 commit comments

Comments
 (0)