Using Numpy.polyfit
I have plotted a curve over some data using numpy.polyfit and am trying to find where the curve intersects a different line. However, I seem to be misunderstanding how the function
Solution 1:
import matplotlib.pyplot as plt
import numpy
import warnings
warnings.simplefilter('ignore', numpy.RankWarning)
JD = [2458880.2995,2458880.3046,2458880.3566,2458880.3585,2458880.7,2458880.7549]
mag=[1.595,1.62,1.609,1.599,1.667,1.571]
x = JD
y = mag
coeffs = numpy.polyfit(x,y,2)
poly = numpy.poly1d(coeffs)
new_x = numpy.linspace(x[0], 2458940)
new_y = poly(new_x)
plt.plot(x,y,'x', new_x,new_y)
a,b,c = coeffs
# y = ax^2 + bx + c
xa = 2458880.2995
ya = a*(xa**2) + b*(xa) + c
print(ya)
i have added
import warnings
warnings.simplefilter('ignore', numpy.RankWarning)
as i was getting rankwarning error which caused the issue , now the output is 1.6
"Rank warning means that the rank of the coefficient matrix in the least-squares fit is deficient. The warning is only raised if full = False." numpy.ployfit in the last Rank Warning is mentioned
Post a Comment for "Using Numpy.polyfit"