Least-squares polynomial fit. More...
Go to the source code of this file.
Least-squares polynomial fit.
Preconditions the caller must meet: aX and aY have the same length, that length exceeds the requested degree, and **the first and last entry of aX differ**. Both backends scale the abscissa by ( n - 1 ) / ( aX(n-1) - aX(0) ) to improve the conditioning of the fit and then scale the coefficients back, so equal endpoints are a division by zero rather than a diagnostic.
The coefficient vector is resized to degree + 1.
Coefficient order is descending: aCoeffs(0) is the coefficient of the highest power and the last entry is the constant term, so a vector of length n+1 describes a polynomial of degree n. This is the convention Armadillo and MATLAB use, and it is the opposite of the ascending order some other libraries take. Getting it backwards produces a plausible-looking wrong answer rather than an error.