Reputation: 1980
I want print a polynomial equation for the given data. I am using this line of code, however I am not sure this the correct way to get the polynomial equation for the given data
fit2 = numpy.polyfit(temp[0][0],temp[0][1],deg=2)
y1=numpy.poly1d(fit2)
Please advise
Upvotes: 1
Views: 2543
Reputation: 18638
Sympy has some nice features do that simply:
from sympy import Symbol,expand
fit2 = numpy.polyfit(temp[0][0],temp[0][1],deg=2)
y1=numpy.poly1d(fit2)
x=Symbol('x')
print(expand(y1(x)))
for:
-2.6666666666668*x**3 + 41.0000000000018*x**2 - 195.333333333342*x + 323.000000000013
Upvotes: 1