Polynoms::PolyFit Function

Overload List

#SignatureDescription
1void PolyFit(TVec *XValues, TVec *YValues, int Degree, TVec *Coeff, TMtx *R, int &DegFreedom, double &L2R, TVec *Weights = null);Fits a polynomial to data.
2void PolyFit(TVec *XValues, TVec *YValues, int Degree, TVec *Coeff, TVec *Weights = null);Fits a polynomial to data.

Overload 1: void PolyFit(TVec *XValues, TVec *YValues, int Degree, TVec *Coeff, TMtx *R, int &DegFreedom, double &L2R, TVec *Weights = null);

Fits a polynomial to data.

#NameTypeDescription
1XValuesTVec *Defines x values in p=p(x).
2YValuesTVec *Defines polynomial, evaluated at x i.e p(x).
3DegreeintDefines polynomial degree.
4CoeffTVec *Returns the coeficients of fitted polynomial.
5RTMtx *Returns the Cholesky factor of the Vandermonde matrix.
6DegFreedomint &Returns the degree of freedom.
7L2Rdouble &Returns the L2 norm of the residuals.
8Weights = nullTVec *If not nil, defines fitting weights.
Remarks:

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

Examples
#include "MtxExpr.h"
#include "Units.Polynoms.h"

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units;

void Example()
{
    Vector X(0);
    Vector Y(0);
    Vector YCalc(0);
    Vector Delta(0);
    Vector Coeff(0);
    Matrix R(0, 0);
    int degF;
    double L2R;

    X.Size(100);
    X.Ramp();
    Y.Size(X);
    Y.RandGauss(2.0, 3.0);
    Polynoms::PolyFit(X, Y, 3, Coeff, R, degF, L2R, null); //Fit
    Polynoms::PolyEval(X, Coeff, R, degF, L2R, YCalc, Delta); // Evaluate
}
Declared in Dew::Math::Units::Polynoms · Dew.Math/Units.Polynoms.h · Cross-compiler

Overload 2: void PolyFit(TVec *XValues, TVec *YValues, int Degree, TVec *Coeff, TVec *Weights = null);

Fits a polynomial to data.

#NameTypeDescription
1XValuesTVec *
2YValuesTVec *
3Degreeint
4CoeffTVec *
5Weights = nullTVec *
Remarks:

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

Declared in Dew::Math::Units::Polynoms · Dew.Math/Units.Polynoms.h · Cross-compiler