You are here: Symbol Reference > Polynoms Namespace > Functions > Polynoms.PolyFit Function
MtxVec VCL
ContentsIndex
PreviousUpNext
Polynoms.PolyFit Function

Fits a polynomial to data.

Pascal
procedure PolyFit(XValues: TVec; YValues: TVec; Degree: Integer; Coeff: TVec; R: TMtx; out DegFreedom: Integer; out L2R: double; Weights: TVec = nil); overload;
Parameters 
Description 
XValues 
Defines x values in p=p(x)
YValues 
Defines polynomial, evaluated at x i.e p(x)
Degree 
Defines polynomial degree. 
Coeff 
Returns the coeficients of fitted polynomial. 
Returns the Cholesky factor of the Vandermonde matrix. 
DegFreedom 
Returns the degree of freedom. 
L2R 
Returns the L2 norm of the residuals. 
Weights 
If not nil, defines fitting weights. 

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

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;
#include "MtxExpr.hpp" #include "Polynoms.hpp" #include "MtxVecTee.hpp" void __fastcall TForm1::BitBtn1Click(TObject *Sender) { Vector X,Y,YCalc,Delta,Coeff; Matrix R; int DegF; double L2R; X = Ramp(100); Y.Size(100); Y.RandGauss(2,3); PolyFit(X,Y,3,Coeff,R,DegF,L2R); //Fit PolyEval(X,Coeff,R,DegF,L2R,YCalc,Delta); // evaluate DrawIt(OPENARRAY(TVec*,(Y,YCalc)),OPENARRAY(AnsiString,("Original","Polyfit"))); }
Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!