Description | The input data are used to determine the coefficients ai of a polynomial
Pi = a0 + a1Xi + a2Xi2 ... anXin
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 variant, VF_polyfitwW, 1/si2 has to be provided as the vector InvVar. In the non-weighted variant, all si are assumed as 1.0.
Arguments:
A | vector of size deg+1; returns the coefficients |
Covar | matrix of dimensions [deg+1, deg+1]; returns the covariances of the coefficients |
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, in order to have x'=0 at the beginning of the range. Shifting by -9.5 for x'=0 in the middle of the range would also be fine.
In the rare case of failure, this function returns 1 (TRUE) and sets all A[i] = 0. |