Standard Library function thatfits an n-degree polynomial curve through a set of data points using the least-squares method.
y The vector containing the dependent y-coordinates of the data. Must have the same number of elements as x.
deg The degree of the polynomial to be fitted to the data.
ybd (optional) The vector containing the error estimate of each point. (The error estimate is equal to one standard deviation.)
sig (optional) The standard deviation of the function, expressed in the units of the y direction.
mat (optional) The correlation matrix of the coefficients.
POLY_FIT returns a vector with a length of deg + 1. For example, if you had requested a polynomial of degree 3, the fitted curve would have the equation:
parameter is in a format that can be readily displayed as a curve alongside the input curve, thereby allowing you to compare the two curves.
x = FINDGEN(9) y = [5., 4., 3., 2., 2., 3., 5., 6., 7.]
TEK_COLOR
PLOT, x, y, Title='POLY_FIT EXAMPLE'
coeff_1_deg = POLY_FIT(x, y, 1, yfit)
OPLOT, x, yfit, Color=3
coeff_3_deg = POLY_FIT(x, y, 3, yfit)
OPLOT, x, yfit, Color=2
coeff_5_deg = POLY_FIT(x, y, 5, yfit)
OPLOT, x, yfit, Color=6
labels = ['Original data',$ 'Fit with first order polynomial',$ 'Fit with third order polynomial',$ 'Fit with fifth order polynomial'] LEGEND, labels, [255, 3, 2, 6], [0, 0, 0, 0], $ [0, 0, 0, 0], 4., 1.5, .3