Fit a polynomial equation to XY vectors and return the coefficients and statistical results.
Fit a polynomial equation to a curve and return the coefficients and statistical results.
Fit a polynomial equation to a curve or curve segment.
Fit a polynomial equation to a curve or curve segment and return the parameter coefficients.
bool fitpoly( vector & vX, vector & vY, int nOrder, vector & pCoeff = NULL, vector & pError = NULL, RegStats * psRegStats = NULL )
bool fitpoly( Curve & cv, int nOrder, vector & pCoeff = NULL, vector & pError = NULL, RegStats * psRegStats = NULL, int iBeg = 0, int iEnd = -1, double * pxmin = NULL, double * pxmax = NULL )
BOOL fitpoly( Curve & crv, int ipolyorder, double * coeff, int inumer = 0, int idenom = 0 )
int fitpoly( int nOrder, double * pX, double * pY, int nSize, vector & vCoeff, vector & vError = NULL, RegStats * psRegStats = NULL, bool * pbXNorm = NULL, LROptions* pstLROptions = NULL )
Returns TRUE on success and FALSE on failure.
Returns TRUE on success and FALSE on failure.
Returns TRUE on success and FALSE on failure.
Returns STATS_NO_ERROR or positive on successful exit and a negative STATS error code on failure.
LARGE_X_NORMALIZED(1): the independent data have large value and small range, so are normalized first.
Error Codes:
STATS_INPUT_NULL_POINTER(-156): pX and pY must not be empty.
STATS_ERROR_TOO_FEW_DATA_PTS(-165): nSize must not be less than 2
STATS_ERROR_SETTING(-151): nOrder must not be less than 1
STATS_ERROR_SVD_FAIL(-179): The singular value decomposition is failed
STATS_ERROR_RANK_DEFICIENT(-180): The pX is not full rank.
STATS_ERROR_BAD_WEIGHT(-108): Some data of the weight are less than zero
EX1
void fitpoly_ex1() { vector vX = {1, 2, 3, 4, 5}; vector vY = {5.5, 43.1, 128, 290.7, 498.4}; int nOrder = 3; vector vCoeff; vCoeff.SetSize(nOrder+1); fitpoly(vX, vY, nOrder, vCoeff); for (int i = 0; i <= nOrder; i++) printf("%g\n", vCoeff[i]); }
EX2
void fitpoly_ex2(Curve& crv) { int nOrder = 3; vector vCoeff; vCoeff.SetSize(nOrder+1); vector vError(nOrder+1); fitpoly(crv, nOrder, vCoeff, vError); for (int i = 0; i <= nOrder; i++) printf("%d: Coeff = %g, Error = %g\n", i+1, vCoeff[i], vError[i]); } void run_fitpoly_ex2() { Worksheet wks = Project.ActiveLayer(); if( wks && wks.GetNumCols() >= 2 ) { Curve crv(wks, 0, 1); fitpoly_ex2( crv ); } }
EX3
void fitpoly_ex3(Curve& crv) { int nOrder = 3; vector vCoeffs(nOrder+1); if( fitpoly(crv, nOrder, vCoeffs)) { for (int i = 0; i <= nOrder; i++) printf("%g\n", vCoeffs[i]); } } void run_fitpoly_ex3() { Worksheet wks = Project.ActiveLayer(); if( wks && wks.GetNumCols() >= 2 ) { Curve crv(wks, 0, 1); fitpoly_ex3( crv ); } }
EX4
void fitpoly_ex4() { vector vX = {1, 2, 3, 4, 5}; vector vY = {5.5, 43.1, 128, 290.7, 498.4}; int nOrder = 3; int nSize = vX.GetSize(); vector vCoeff; vCoeff.SetSize(nOrder+1); fitpoly(nOrder, vX, vY, nSize, vCoeff); for (int i = 0; i <= nOrder; i++) printf("%g\n", vCoeff[i]); }
The function used for fitting function parameter initialization.
Fit a polynomial equation to a curve or curve segment and return the parameter coefficients. If specified, only the Nth segment of M equal curve segments is fit.
origin.h