|Description||The input data are used to determine the coefficients ai of a polynomial of degree deg.
Pi = a0 + a1Xi + a2Xi2 ... anXin
A has deg+1 elements.
The polynomial has only even terms,
Pi = a0 + a2Xi2 ... a2nXi2n
A has deg/2+1 elements, as the zero coefficients are not stored.
The polynomial has only odd terms,
Pi = a1Xi + a3Xi3 ... a2n+1Xi2n+1
A has (deg+1)/2 elements, as the zero coefficients are not stored.
The coefficients are determined so as to minimize the deviation between the "theoretical" Pi values, calculated by the polynomial, and the actual Yi values. To be more precise, the figure-of-merit chi-square,
c2 = sum( 1/si2 * (Pi - Yi)2 );
is minimized. In the weighted variants, VF_polyfitwW etc., 1/si2 has to be provided as the vector InvVar. In the non-weighted variant, all si are assumed as 1.0.
|A||vector of size deg+1; returns the coefficients|
|Covar||matrix of dimensions [deg+1, deg+1]; returns the covariances of the coefficients.|
If the covariances are not needed, one may call the function with Covar=NULL / nil.
|deg||the degree of the fitting polynomial|
|X, Y, InvVar||vectors of size sizex, holding the input data|
If possible, the X axis should include the zero point. Fitting far off the zero-point may lead to poor matching of the polynomial and your data, given the typical form of a polynomial (which has only deg-1 "turns"). In such a case, you should calculate the polynomial not for the original X, but for a shifted X' axis. If, e.g., you have to find a polynomial matching data for x ranging from 9 to 10, you would best shift your X axis by -9.5, in order to have x'=0 in the middle of the range. Shifting by -9.0 for x'=0 at the beginning of the range would also be fine.
In the rare case of failure, this function returns 1 (TRUE) and sets all A[i] = 0.