sablib
Loading...
Searching...
No Matches
polyfit.h File Reference

Polynomial fitting using the least squares method (Gauss-Newton for linear models) and evaluating polynomial function. More...

#include <stdexcept>
#include <Eigen/Eigen>

Go to the source code of this file.

Functions

template<typename Derived>
const Eigen::MatrixX< typename Derived::PlainObject::Scalar > sablib::Vandermonde (const Eigen::MatrixBase< Derived > &x, const unsigned int polyorder)
 Generates a Vandermonde matrix for a given vector and polynomial order.
template<typename Derived>
const Derived::PlainObject sablib::PolyFit (const Eigen::MatrixX< typename Derived::PlainObject::Scalar > &V, const Eigen::MatrixBase< Derived > &y)
 Solves the polynomial least squares fitting problem using a pre-calculated Vandermonde matrix.
template<typename Derived>
const Derived::PlainObject sablib::PolyFit (const Eigen::MatrixBase< Derived > &x, const Eigen::MatrixBase< Derived > &y, const unsigned int polyorder)
 Fits a polynomial of a specified order to the given data points.
template<typename Derived>
const Derived::PlainObject sablib::PolyVal (const Eigen::MatrixBase< Derived > &coeff, const Eigen::MatrixX< typename Derived::PlainObject::Scalar > &V)
 Evaluates the polynomial at specified points using a pre-calculated Vandermonde matrix.
template<typename Derived>
const Derived::PlainObject sablib::PolyVal (const Eigen::MatrixBase< Derived > &coeff, const Eigen::MatrixBase< Derived > &x)
 Evaluates the polynomial at specified x-coordinates.
template<typename Derived>
const Derived::PlainObject::Scalar sablib::PolyVal (const Eigen::MatrixBase< Derived > &coeff, const typename Derived::PlainObject::Scalar x)
 Evaluates the polynomial at single specified x-coordinate.

Detailed Description

Polynomial fitting using the least squares method (Gauss-Newton for linear models) and evaluating polynomial function.

Author
Izadori

Definition in file polyfit.h.

Function Documentation

◆ PolyFit() [1/2]

template<typename Derived>
const Derived::PlainObject sablib::PolyFit ( const Eigen::MatrixBase< Derived > & x,
const Eigen::MatrixBase< Derived > & y,
const unsigned int polyorder )

Fits a polynomial of a specified order to the given data points.

This function uses the normal equations, which is the Gauss-Newton method applied to a linear model.

Parameters
xThe x-coordinates of the data points.
yThe y-coordinates of the data points.
polyorderThe order of the polynomial to fit.
Returns
The coefficients of the fitted polynomial (from lowest to highest order).
Exceptions
std::invalid_argumentIf x and y sizes differ or if polyorder is too high for the number of points.

Definition at line 95 of file polyfit.h.

◆ PolyFit() [2/2]

template<typename Derived>
const Derived::PlainObject sablib::PolyFit ( const Eigen::MatrixX< typename Derived::PlainObject::Scalar > & V,
const Eigen::MatrixBase< Derived > & y )

Solves the polynomial least squares fitting problem using a pre-calculated Vandermonde matrix.

Parameters
VThe Vandermonde matrix.
yThe target vector of data points.
Returns
The coefficients of the fitted polynomial.
Exceptions
std::invalid_argumentIf the number of rows in V does not match the size of y.

Definition at line 66 of file polyfit.h.

◆ PolyVal() [1/3]

template<typename Derived>
const Derived::PlainObject sablib::PolyVal ( const Eigen::MatrixBase< Derived > & coeff,
const Eigen::MatrixBase< Derived > & x )

Evaluates the polynomial at specified x-coordinates.

Parameters
coeffThe coefficients of the polynomial.
xThe x-coordinates where the polynomial will be evaluated.
Returns
The evaluated values.

Definition at line 151 of file polyfit.h.

◆ PolyVal() [2/3]

template<typename Derived>
const Derived::PlainObject sablib::PolyVal ( const Eigen::MatrixBase< Derived > & coeff,
const Eigen::MatrixX< typename Derived::PlainObject::Scalar > & V )

Evaluates the polynomial at specified points using a pre-calculated Vandermonde matrix.

Parameters
coeffThe coefficients of the polynomial.
VThe Vandermonde matrix.
Returns
The evaluated values.
Exceptions
std::invalid_argumentIf the length of coeff is zero or the number of columns in V does not match the size of coeff.

Definition at line 122 of file polyfit.h.

◆ PolyVal() [3/3]

template<typename Derived>
const Derived::PlainObject::Scalar sablib::PolyVal ( const Eigen::MatrixBase< Derived > & coeff,
const typename Derived::PlainObject::Scalar x )

Evaluates the polynomial at single specified x-coordinate.

Parameters
coeffThe coefficients of the polynomial.
xThe x-coordinate where the polynomial will be evaluated.
Returns
The evaluated value.
Exceptions
std::invalid_argumentIf the length of coeff is zero.

Definition at line 170 of file polyfit.h.

◆ Vandermonde()

template<typename Derived>
const Eigen::MatrixX< typename Derived::PlainObject::Scalar > sablib::Vandermonde ( const Eigen::MatrixBase< Derived > & x,
const unsigned int polyorder )

Generates a Vandermonde matrix for a given vector and polynomial order.

Parameters
xThe input vector of data points.
polyorderThe order of the polynomial (columns in the matrix will be polyorder + 1).
Returns
The generated Vandermonde matrix.
Exceptions
std::invalid_argumentIf the length of x is zero or polyorder is zero.

Definition at line 25 of file polyfit.h.