Overload List
| # | Signature | Description |
|---|---|---|
| 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. |
| 2 | void 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.
| # | Name | Description |
|---|---|---|
| 1 | XValues | Defines x values in p=p(x). |
| 2 | YValues | Defines polynomial, evaluated at x i.e p(x). |
| 3 | Degree | Defines polynomial degree. |
| 4 | Weights | If not nil, defines fitting weights. |
| 5 | Coeff | Returns the coeficients of fitted polynomial. |
| 6 | R | Returns the Cholesky factor of the Vandermonde matrix. |
| 7 | DegFreedom | Returns the degree of freedom. |
| 8 | L2R | Returns 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.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | XValues | TVec | source TVec |
| 2 | YValues | TVec | source TVec |
| 3 | Degree | Int32 | |
| 4 | Coeff | TVec | source TVec |
| 5 | Weights | TVec | source TVec |
Result: stored in self (calling object)
Remarks:
This overload does not return additional statistical parameters like Cholesky matrix or degrees of freedom.