Polynoms.PolyFit Method

Overload List

#SignatureDescription
1void PolyFit(TVec XValues, TVec YValues, Int32 Degree, TVec Coeff, TMtx R, ref Int32 DegFreedom, ref Double L2R, TVec Weights)Fits a polynomial to data.
2void PolyFit(TVec XValues, TVec YValues, Int32 Degree, TVec Coeff, TVec Weights)Fits a polynomial to data.

Overload 1: void PolyFit(TVec XValues, TVec YValues, Int32 Degree, TVec Coeff, TMtx R, ref Int32 DegFreedom, ref Double L2R, TVec Weights)

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
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);
    }
}

Overload 2: void PolyFit(TVec XValues, TVec YValues, Int32 Degree, TVec Coeff, TVec Weights)

Fits a polynomial to data.

#NameTypeDescription
1XValuesTVecsource TVec
2YValuesTVecsource TVec
3DegreeInt32
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.