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....



CalcCenteredPolyFit


Unit:SDL_math2
Class: TCurveFit
Declaration: function CalcCenteredPolyFit (const nOrder: byte; var kArray: array of double; var XShift: double; var FitQual: double; var NearSingular: boolean): boolean; {Pascal}
bool __fastcall CalcCenteredPolyFit(const Byte nOrder, double * kArray, const int kArray_Size, double &XShift, double &FitQual, bool &NearSingular); {C++}

The method CalcCenteredPolyFit calculates the best fit for a polynomial of order nOrder which is shifted along the x-axis by XShift. If XShift is set to a zero value, the method automatically determines the optimal shift and returns it in XShift; any other value forces CalcCenteredPolyFit to use this value as shift. The regression equation of the shifted polynomial is given by

y = kArray[0] + S(kArray[j](x-XShift) j)

The order of the polynomial is restricted to values between 1 and MaxPolyFitOrder. Higher orders may result in numerical instabilities. The variable array parameter kArray returns the polynomial coefficients, the variable parameter FitQual returns the goodness of fit. The function CalcCenteredPolyFit 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 be resized to nOrder+1 before calling CalcCenteredPolyFit.

Hint 3: The declaration of CalcCenteredPolyFit in C++ slightly differs from the Pascal declaration (note the extra parameter kArray_Size):
bool __fastcall CalcCenteredPolyFit(const Byte nOrder, double * kArray, const int kArray_Size, double &XShift, double &FitQual, bool &NearSingular);

Example: This method is used in the following example program (see http://www.lohninger.com/examples.html for downloading the code): curvefit



Last Update: 2016-Apr-10