I’m looking for a general Polynomial Fitting function in MKL, which is similar to Polyfit function from Matlab, OptiVec and Armadillo. This function uses two set of input data X and Y to determine the coefficients ai of a polynomial:
Pi = a0 + a1Xi + a2Xi2 ... anXin
χ2 = sum( 1/σi2 * (Pi - Yi)2 );
I have searched MKL Data Fitting Library and found that all of routines are Spline-based. In MKL LAPACK library, I found some routines the Least Squares ones.
I understand that,
- as the order of the polynomial increases, Spline-based methods are preferable over polynomial interpolation because its interpolation error increases
- when the number of points of X and Y > (1 + the degree) of the polynomial to be used, the Least Squares fit will be used
However, what I’m looking for is a general Polynomial Fitting function described above. Is there such function in MKL? Where can I find it in MKL (or IPP)?
The Matlab polyfit routine is restricted to fitting with uniform weighting, i.e., σi is the same for all i. This capability is available in Lapack, in the subroutine ?GELS.
There is no ready-to-use-routine for the non-uniform weights case in MKL, as far as I know, but you should be able to put one together using the matrix manipulation routines that are available in BLAS/Lapack.
Thank you for your advice, mecej4!
According to the MKL Reference, the function ?gels
Uses QR or LQ factorization to solve a overdetermined or underdetermined linear system with full rank matrix.
The uniform weighting is ok for our application. In addition to the Least Squares fit, however, we are looking for Polynomial Fitting function that determine the coefficients of a polynomial for:
Number of input points = (1 + degree) of the polynomial to be used
Is there such Polynomial Fitting function in MKL (or IPP)? In other words, we need to calculate the coefficients of a polynomial that neither overdetermined nor underdetermined.
The interpolating polynomial can be obtained in the Lagrange form explicitly, without any matrix algebra. See https://en.wikipedia.org/wiki/Lagrange_polynomial .
If the coefficients are desired, rather than interpolants, you may use the Lapack routine ?GESV, which is available in MKL.
Ok，let me fill and close this question.Here comes the code.I registerd this account just for posting this.