The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information.... ## CalcPolyFit

 Unit: SDL_math2 Class: Declaration:  function CalcPolyFit (const nOrder: integer; var kArray: TDoubleArray; var FitQual: double; var NearSingular: boolean): boolean;  function CalcPolyFit (const nOrder: integer; var kArray: TDoubleArray; var alpha: TDoubleArray; var FitQual: double; var NearSingular: boolean): boolean;

The method CalcPolyFit calculates the best fit for a polynomial of order nOrder. The order of the polynomial is restricted to values between 1 and MaxPolyFitOrder. The variable array parameter kArray returns the polynomial coefficients, the variable parameter FitQual returns the goodness of fit. Version  of CalcPolyFit additionally calculates the p-values of the coefficients and returns them in the variable array alpha.

The function CalcPolyFit returns a TRUE value if the fit has been calculated successfully, and the returned parameters are valid. Numerical instabilities which may arise from near-singular equations are indicated by returning a TRUE value in the variable parameter NearSingular. In this case the calculated polynomial coefficients should not be used.

 Hint 1: The number of data used for the polynomial fit has to exceed the order of the polynomial at least by one.

 Hint 2: The open array parameter kArray has to be resized to nOrder+1 before calling CalcPolyFit.

 Hint 3: The algorithm for calculating the polynomial fit has been changed with release 9.0 of the SDL Component Suite. This change results in a radical improvement of results for ill-conditioned problems (i.e. when x values are not centered around zero). Thus you should always use release 9.0, or higher, for high order polynomials. Furthermore, it is recommended to use the method CalcCenteredPolyFit whenever possible, since this routine is designed to solve even the most difficult regression problems.

Last Update: 2020-Aug-04