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.
|
| 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.
|
Polynomial fitting using the least squares method (Gauss-Newton for linear models) and evaluating polynomial function.
- Author
- Izadori
Definition in file polyfit.h.
◆ 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
-
| x | The x-coordinates of the data points. |
| y | The y-coordinates of the data points. |
| polyorder | The order of the polynomial to fit. |
- Returns
- The coefficients of the fitted polynomial (from lowest to highest order).
- Exceptions
-
| std::invalid_argument | If 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
-
| V | The Vandermonde matrix. |
| y | The target vector of data points. |
- Returns
- The coefficients of the fitted polynomial.
- Exceptions
-
| std::invalid_argument | If 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
-
| coeff | The coefficients of the polynomial. |
| x | The 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
-
| coeff | The coefficients of the polynomial. |
| V | The Vandermonde matrix. |
- Returns
- The evaluated values.
- Exceptions
-
| std::invalid_argument | If 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
-
| coeff | The coefficients of the polynomial. |
| x | The x-coordinate where the polynomial will be evaluated. |
- Returns
- The evaluated value.
- Exceptions
-
| std::invalid_argument | If 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
-
| x | The input vector of data points. |
| polyorder | The order of the polynomial (columns in the matrix will be polyorder + 1). |
- Returns
- The generated Vandermonde matrix.
- Exceptions
-
| std::invalid_argument | If the length of x is zero or polyorder is zero. |
Definition at line 25 of file polyfit.h.