This set of Libpolycomp routines allows to compute the least squares best fit between a set of floating-point numbers (with ) and a polynomial, through the points . It is used internally by the polynomial compression functions (Polynomial compression functions), but the API is exposed to the library user.
Free an instance of the pcomp_poly_fit_data_t that has been allocated via a call to pcomp_init_poly_fit.
- Parameters
-
[in] | poly_fit | Pointer to the structure to be freed |
Definition at line 210 of file poly.c.
Return the number of coefficients of the least-squares fitting polynomial.
- Parameters
-
[in] | poly_fit | Pointer to the structure detailing the fit |
- Returns
- The number of coefficients for the fitting polynomial (one plus the polynomial degree)
Definition at line 253 of file poly.c.
Return the number of samples to be used in a polynomial fit.
- Parameters
-
[in] | poly_fit | Pointer to the structure detailing the fit |
- Returns
- The number of samples that should be passed to a call to pcomp_run_poly_fit.
Definition at line 234 of file poly.c.
Calculates a polynomial least-squares fit.
Compute a least-squares fit between the numbers (with ) and the polynomial through the points . The coefficients of are saved in coeffs, from the least to the greatest degree.
Here is an example of the usage of this function:
double points[] = { 1.0, 3.0, 5.0 };
double coeffs[2];
const size_t num_of_points = sizeof(points) / sizeof(points[0]);
const size_t num_of_coeffs = sizeof(coeffs) / sizeof(coeffs[0]);
printf("The data are fitted by the polynomial y = %f + %f x\n",
coeffs[0], coeffs[1]);
- Parameters
-
[in] | poly_fit | Pointer to a pcomp_poly_fit_data_t structure, created using the pcomp_init_poly_fit function. |
[out] | coeffs | Pointer to an array where the coefficients of the polynomial will be stored on exit. The array must have room for a number of elements greater or equal than the value returned by pcomp_poly_fit_num_of_coeffs. |
[in] | points | Array of numbers to use in the fit. The number of elements considered in the fit is equal to the return value of pcomp_poly_fit_num_of_samples. |
- Returns
- PCOMP_STAT_SUCCESS if the fit was computed successfully, PCOMP_STAT_INVALID_FIT if the data are incorrect (e.g., there are fewer samples than unknowns).
Definition at line 301 of file poly.c.