To follow up on a previous question, I would like to extract the polynomial to calculate the result for certain values in a python environment without numpy.
The code :
import numpy as np
import matplotlib.pyplot as plt
from numpy.polynomial import Polynomial
x = [430, 518, 471, 581, 330, 560, 387, 280, 231, 196, 168, 148, 136, 124, 112, 104, 101, 93, 88, 84, 80, 76]
y = [13, 10.5, 11.5, 10, 16.9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90]
plt.figure(figsize=(12,6))
plt.plot(x, y, 'o')
polynomial = Polynomial.fit(x, y, deg=7)
x1 = np.arange(76, 570, 1)
y1 = [polynomial(i) for i in x1]
plt.plot(x1, y1, '-')
print("polynomial result :")
print(polynomial)
print("-------------------")
# test single value of x
x2 = 330
y2_direct = 16.94343988 - 11.3117263*x2 + 17.65987276*x2**2 - 31.01304843*x2**3 - 21.01641368*x2**4 + 46.31228129*x2**5 + 36.3575357*x2**6 - 44.05000699*x2**7
y2_poly = polynomial(x2)
print("y2_direct = ", y2_direct)
print("y2_poly = ", y2_poly)
plt.legend('data deg7'.split())
plt.show()
I get this :
Why the 2 values y2_direct and y2_poly are different?