Updating for adding offset
This commit is contained in:
19
python-driver/level_testing.py
Normal file
19
python-driver/level_testing.py
Normal file
@@ -0,0 +1,19 @@
|
||||
eq = "-7.5553x^5 + 274.72x^4 - 3764.6x^3 + 24542x^2 - 27573x + 8080.8"
|
||||
coeffs = [-7.5553, 274.72, -3764.6, 24542.0, -27573.0, 8080.8]
|
||||
|
||||
|
||||
def calc_polynomial(coefficient_list, x):
|
||||
"""Calculate a polynomial value given the coefficients and x-value."""
|
||||
poly_val = 0.0
|
||||
new_eq = ""
|
||||
for i in range(0, len(coefficient_list)):
|
||||
pow_level = len(coefficient_list) - (i + 1)
|
||||
poly_val += coefficient_list[i] * pow(x, pow_level)
|
||||
new_eq += " + {}x^{}".format(coefficient_list[i], pow_level)
|
||||
print(new_eq[2:])
|
||||
return poly_val
|
||||
|
||||
|
||||
test_x = 10.0
|
||||
print(calc_polynomial(coeffs, test_x))
|
||||
print(-7.5553 * test_x ** 5 + 274.72 * test_x ** 4 - 3764.6 * test_x ** 3 + 24542.0 * test_x ** 2 - 27573.0 * test_x + 8080.8)
|
||||
Reference in New Issue
Block a user