You are here: Symbol Reference > Dew Namespace > Dew.Math Namespace > Dew.Math.Units Namespace > Classes > Polynoms Class > Polynoms Methods > PolyFit Method > Polynoms.PolyFit Method (TVec, TVec, int, TVec, TMtx, out int, out double, TVec)
Dew Math for .NET
ContentsIndexHome
PreviousUpNext
Polynoms.PolyFit Method (TVec, TVec, int, TVec, TMtx, out int, out double, TVec)

Fits a polynomial to data.

Syntax
C#
Visual Basic
public static void PolyFit(TVec XValues, TVec YValues, int Degree, TVec Coeff, TMtx R, out int DegFreedom, out double L2R, TVec Weights);
Parameters 
Description 
TVec XValues 
Defines x values in p=p(x)
TVec YValues 
Defines polynomial, evaluated at x i.e p(x)
int Degree 
Defines polynomial degree. 
TVec Coeff 
Returns the coeficients of fitted polynomial. 
TMtx R 
Returns the Cholesky factor of the Vandermonde matrix. 
out int DegFreedom 
Returns the degree of freedom. 
out double L2R 
Returns the L2 norm of the residuals. 
TVec Weights 
If not nil, defines fitting weights. 

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

using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example() { Vector X = new Vector(0); Vector Y = new Vector(0); Vector YCalc = new Vector(0); Vector Delta = new Vector(0); Vector Coeff = new Vector(0); Matrix R = new Matrix(0,0); int degF; double L2R; X.Ramp(100); y.Size(X); Y.RandomGauss(2.0,3.0); Polynoms.PolyFit(X,Y,3,Coeff,R, out degF, out L2R, null); //Fit Polynoms.PolyEval(X,Coeff,degF,L2R,YCalc,Delta); // Evaluate MtxVecTee.DrawIt(new Vector[] {Y,YCalc}, new string[] {"Original","Fit"},"Fit results",false); } }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!