Polynoms.PolyFit Method

Overload List

#SignatureDescription
1procedure PolyFit(XValues: TVec; YValues: TVec; Degree: Integer; Coeff: TVec; R: TMtx; out DegFreedom: Integer; out L2R: Double; Weights: TVec);Fits a polynomial to data.
2procedure PolyFit(XValues: TVec; YValues: TVec; Degree: Integer; Coeff: TVec; Weights: TVec);Fits a polynomial to data.

Overload 1: procedure PolyFit(XValues: TVec; YValues: TVec; Degree: Integer; Coeff: TVec; R: TMtx; out DegFreedom: Integer; out L2R: Double; Weights: TVec);

Fits a polynomial to data.

#NameDescription
1XValuesDefines x values in p=p(x).
2YValuesDefines polynomial, evaluated at x i.e p(x).
3DegreeDefines polynomial degree.
4WeightsIf not nil, defines fitting weights.
5CoeffReturns the coeficients of fitted polynomial.
6RReturns the Cholesky factor of the Vandermonde matrix.
7DegFreedomReturns the degree of freedom.
8L2RReturns the L2 norm of the residuals.

Result: stored in self (calling object)

Remarks:

The PolyFit procedure uses the least-squares method to find the fitted polynomial coefficients.

Examples
uses MtxExpr, Math387, MtxVec, MtxVecTee, Polynoms;

procedure TForm1.Button1Click(Sender: TObject);
var X,Y,YCalc,Delta,Coeff: Vector;
R: Matrix;
DegF: Integer;
L2R : double;
begin
    X.Size(100,false);
    Y.Size(X);
    X.Ramp;
    Y.RandGauss(2,3);
    PolyFit(X,Y,3,Coeff,R,DegF,L2R); //Fit
    PolyEval(X,Coeff,R,DegF,L2R,YCalc,Delta); //  evaluate
    DrawIt([Y,YCalc],['Original','Polyfit']);
end;

Overload 2: procedure PolyFit(XValues: TVec; YValues: TVec; Degree: Integer; Coeff: TVec; Weights: TVec);

Fits a polynomial to data.

#NameTypeDescription
1XValuesTVecsource TVec
2YValuesTVecsource TVec
3DegreeInteger
4CoeffTVecsource TVec
5WeightsTVecsource TVec

Result: stored in self (calling object)

Remarks:

This overload does not return additional statistical parameters like Cholesky matrix or degrees of freedom.