VF_polyfit VD_polyfit VE_polyfit
VF_polyfitwW VD_polyfitwW VE_polyfitwW
Functionfitting of one X-Y data set to a polynomial
Syntax C/C++#include <MFstd.h>
int VF_polyfit( fVector A, unsigned deg, fVector X, fVector Y, ui sizex );
int VF_polyfitwW( fVector A, fMatrix Covar, unsigned deg, fVector X, fVector Y, fVector InvVar, ui sizex );
C++ MatObj#include <OptiVec.h>
int vector<T>::polyfit( const vector<T>& X, const vector<T>& Y );
int vector<T>::polyfitwW( matrix<T> Covar, const vector<T>& X, const vector<T>& Y, const vector<T>& InvVar );
int vector<T>::polyfitwW( matrix<T>* Covar, const vector<T>& X, const vector<T>& Y, const vector<T>& InvVar );
Pascal/Delphiuses MFstd;
function VF_polyfit( A:fVector; deg:UInt; X, Y:fVector; sizex:UIntSize ): IntBool;
function VF_polyfitwW( A:fVector; Covar:fMatrix; deg:UInt, X, Y, InvVar:fVector; sizex:UIntSize ): IntBool;
DescriptionThe input data are used to determine the coefficients ai of a polynomial
Pi = a0 + a1Xi + a2Xi2 ... anXin
so as to minimize the deviation between the "theoretical" Pi values, calculated by the polynomial, and the actual Yi values. To be more precise, the figure-of-merit chi-square,
c2 = sum( 1/si2 * (Pi - Yi)2 )
is minimized. In the weighted variant, VF_polyfitwW, 1/si2 has to be provided as the vector InvVar. In the non-weighted variant, all si are assumed as 1.0.

Avector of size deg+1; returns the coefficients
Covarmatrix of dimensions [deg+1, deg+1]; returns the covariances of the coefficients
degthe degree of the fitting polynomial
X, Y, InvVarvectors of size sizex, holding the input data

If possible, the X axis should include the zero point. Fitting far off the zero-point may lead to poor matching of the polynomial and your data, given the typical form of a polynomial (which has only deg-1 "turns"). In such a case, you should calculate the polynomial not for the original X, but for a shifted X' axis. If, e.g., you have to find a polynomial matching data for x ranging from 9 to 10, you would best shift your X axis by -9, in order to have x'=0 at the beginning of the range. Shifting by -9.5 for x'=0 in the middle of the range would also be fine.

In the rare case of failure, this function returns 1 (TRUE) and sets all A[i] = 0.

Return valueFALSE (0), if no error occurred, otherwise TRUE (non-zero).
See alsoVF_linregress,   VF_linfit,   VF_chi2,   chapter 13

MatrixLib Table of Contents  OptiVec home