RegModels.FracFit Method

void FracFit(TVec B, TVec X, TVec Y, Int32 DegNom, Int32 DegDenom, Boolean Constant, TVec Weights)

Fits rational fraction equation to data.

#NameDescription
1XVector of independent variable.
2YVector of dependent variable.
3DegNomNominator degree.
4DegDenomDenominator degree.
5ConstantIf false, B[0] i.e. constant term in nominator is set to 0.0.
6WeightsWeights (optional). Weights are used only if they are set.
7BReturns regression coefficients for rational function.

Result: stored in self (calling object)

Remarks:

The routine fits equations to data by minimizing the sum of squared residuals. The observed values obey the following equation:

Y=b[0]+b[1]X+b[2]X2++b[n]Xn1+b[n+1]X++b[n+d]XdY = \cfrac{b[0]+b[1]\cdot X + b[2]\cdot X^2 +\cdots + b[n]\cdot X^{n}}{1+b[n+1]\cdot X + \cdots + b[n+d]\cdot X^{d}}

where n and d are nominator and denominator polynomial degrees.

Examples
using Dew.Math;
using Dew.Stats.Units;
namespace Dew.Examples
{
    private void Example(Steema.TeeChart.Styles.Line line1, Steema.TeeChart.Styles.Line line2)
    {
        Vector X = new Vector(100);
        Vector Y = new Vector(100);
        Vector B = new Vector(0);
        Vector YHat = new Vector(0);

        X.Ramp(-5.0, 0.05); // x= -5.0, -4.95, ... -0.05
        Y.RandGauss(3.5, 0.12); // sample data
        // calculate coefficients
        RegModels.FracFit(B,X,Y,2,4,false,null);
        // evaluate y by using calculated coefficients
        RegModels.FracEval(B,X, YHat,2,false);
        MtxVecTee.DrawValues(X,Y,line1,false);
        MtxVecTee.DrawValues(X,YHat,line2,false);
    }
}
See Also: RegModels.FracEval