smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
Enumerations | Functions
basis.hpp File Reference

Compile-time polynomial manipulation. More...

#include <cassert>
#include <limits>
#include "static_matrix.hpp"
Include dependency graph for basis.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum class  PolynomialBasis {
  Bernstein , Bspline , Chebyshev1st , Chebyshev2nd , Hermite , Laguerre ,
  Legendre , Monomial
}
 Polynomial basis types. More...
 

Functions

template<std::size_t K, typename Scalar >
SMOOTH_BEGIN_NAMESPACE constexpr StaticMatrix< Scalar, 1, K+1 > monomial_derivative (Scalar u, std::size_t p=0)
 Monomial derivative (compile-time version).
 
template<std::size_t K, std::size_t P, typename Scalar >
constexpr StaticMatrix< Scalar, P+1, K+1 > monomial_derivatives (Scalar u)
 Monomial derivatives up to order.
 
template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::bspline_basis ()
 Bspline basis coefficient matrix.
 
template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::bernstein_basis ()
 Bernstein basis coefficient matrix.
 
template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::hermite_basis ()
 Hermite basis coefficient matrix.
 
template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::laguerre_basis ()
 Laguerre basis coefficient matrix.
 
template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::jacobi_basis (double alpha, double beta)
 Jacobi basis coefficient matrix.
 
template<PolynomialBasis Basis, std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > polynomial_basis ()
 Compile-time coefficient matrix for given basis.
 
template<std::size_t K, std::ranges::random_access_range R, typename Scalar = std::ranges::range_value_t<R>>
constexpr StaticMatrix< Scalar, K+1, K+1 > lagrange_basis (const R &ts)
 Lagrange polynomial basis coefficients.
 
template<std::size_t K, std::size_t N, typename Scalar , std::ranges::sized_range R>
constexpr StaticMatrix< Scalar, K+1, N > polynomial_basis_derivatives (const StaticMatrix< Scalar, K+1, K+1 > &B, const R &ts)
 Polynomial basis derivative coefficients.
 
template<PolynomialBasis Basis, std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > polynomial_cumulative_basis ()
 Cumulative coefficient matrix for given basis.
 
template<std::size_t K, std::size_t P, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > monomial_integral ()
 Calculate integral over matrix of squared monomial P-derivatives.
 
constexpr double integrate_absolute_polynomial (double t0, double t1, double A, double B, double C)
 Integrate the absolute value of a quadratic 1D polynomial.
 

Detailed Description

Compile-time polynomial manipulation.

Definition in file basis.hpp.

Enumeration Type Documentation

◆ PolynomialBasis

enum class PolynomialBasis
strong

Polynomial basis types.

Enumerator
Bernstein 

Basis on [0, 1] with left to right ordering.

Bspline 

Basis on [0, 1] with left to right ordering.

Chebyshev1st 

Orthogonal basis on [-1, 1] w.r.t the weight 1 / sqrt(1-x^2)

Chebyshev2nd 

Orthogonal basis on [-1, 1] w.r.t the weight sqrt(1-x^2)

Hermite 

Orthogonal basis on [-inf, inf] w.r.t the weight exp(-x^2)

Laguerre 

Orthogonal basis on [0, inf] w.r.t the weight exp(-x)

Legendre 

Orthogonal basis on [-1, 1].

Monomial 

The standard monomial basis (1, x, x^2, ...)

Definition at line 229 of file basis.hpp.

Function Documentation

◆ bernstein_basis()

template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::bernstein_basis ( )
constexpr

Bernstein basis coefficient matrix.

Template Parameters
Kpolynomial degree

Definition at line 110 of file basis.hpp.

◆ bspline_basis()

template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::bspline_basis ( )
constexpr

Bspline basis coefficient matrix.

Template Parameters
Kpolynomial degree

Definition at line 75 of file basis.hpp.

◆ hermite_basis()

template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::hermite_basis ( )
constexpr

Hermite basis coefficient matrix.

Template Parameters
Kpolynomial degree

Definition at line 144 of file basis.hpp.

◆ integrate_absolute_polynomial()

constexpr double integrate_absolute_polynomial ( double  t0,
double  t1,
double  A,
double  B,
double  C 
)
inlineconstexpr

Integrate the absolute value of a quadratic 1D polynomial.

Evaluates the integral

\[ \int_{t_0}^{t_1} \left| At^2 + Bt + C \right| \mathrm{d} t. \]

Definition at line 427 of file basis.hpp.

◆ jacobi_basis()

template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::jacobi_basis ( double  alpha,
double  beta 
)
constexpr

Jacobi basis coefficient matrix.

Template Parameters
Kpolynomial degree
Parameters
alphafirst Jacobi parameter
betasecond Jacobi parameter
Note
The Legebdre polynomials correspond to \( \alpha = \beta = 0 \).
The Chebyshev polynomials of the first kind correspond to \( \alpha = \beta = -1/2 \).
The Chebyshev polynomials of the second kind correspond to \( \alpha = \beta = 1/2 \).

Definition at line 199 of file basis.hpp.

◆ lagrange_basis()

template<std::size_t K, std::ranges::random_access_range R, typename Scalar = std::ranges::range_value_t<R>>
constexpr StaticMatrix< Scalar, K+1, K+1 > lagrange_basis ( const R &  ts)
constexpr

Lagrange polynomial basis coefficients.

Template Parameters
Kpolynomial degree
Parameters
tscontrol points (must be of size K + 1)

K + 1 control points define a degree K polynomial K which has K + 1 basis functions p_0 ... p_K.

Computes a matrix B s.t.

\[ \begin{bmatrix} p_0(t) & p_1(t) & \ldots & p_K(t) \end{bmatrix} = \begin{bmatrix} 1 & t & t^2 & \ldots & t^K \end{bmatrix} B \]

where the Lagrange polynomials are

\[ p_i(t) = \prod_{j \in [0,K], j \neq i} \frac{t - t_j}{t_i - t_j}. \]

Definition at line 313 of file basis.hpp.

◆ laguerre_basis()

template<std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > detail::laguerre_basis ( )
constexpr

Laguerre basis coefficient matrix.

Template Parameters
Kpolynomial degree

Definition at line 165 of file basis.hpp.

◆ monomial_derivative()

template<std::size_t K, typename Scalar >
SMOOTH_BEGIN_NAMESPACE constexpr StaticMatrix< Scalar, 1, K+1 > monomial_derivative ( Scalar  u,
std::size_t  p = 0 
)
constexpr

Monomial derivative (compile-time version).

Template Parameters
Scalarscalar type
Kmaximal monomial degree
Parameters
umonomial parameter
pdifferentiation order
Returns
row vector U of size K+1 s.t. \( U_k = \frac{\mathrm{d}^p}{\mathrm{d}u^p} u^k \)

Definition at line 27 of file basis.hpp.

◆ monomial_derivatives()

template<std::size_t K, std::size_t P, typename Scalar >
constexpr StaticMatrix< Scalar, P+1, K+1 > monomial_derivatives ( Scalar  u)
constexpr

Monomial derivatives up to order.

Calculates a row-major \((P+1) \times (K+1)\) matrix U s.t. \( U_{p, k} = \frac{\mathrm{d}^p}{\mathrm{d}u^p} u^k \)

Template Parameters
Scalarscalar type
Kmaximal monomial degree
Pmaximal differentiation order
Parameters
umonomial parameter
Returns
matrix

Definition at line 61 of file basis.hpp.

◆ monomial_integral()

template<std::size_t K, std::size_t P, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > monomial_integral ( )
constexpr

Calculate integral over matrix of squared monomial P-derivatives.

Template Parameters
Scalarscalar type
Kmaximal monomial degree
Pdifferentiation order
Returns
K+1 x K+1 matrix M s.t. M(i, j) = ∫ (d^P/du^P) u^i * (d^P/dx^P) u^j) du, u: 0 -> 1

Definition at line 400 of file basis.hpp.

◆ polynomial_basis()

template<PolynomialBasis Basis, std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > polynomial_basis ( )
constexpr

Compile-time coefficient matrix for given basis.

Returns a row-major matrix B s.t. a polynomial

\[ p(x) = \sum_{\nu=0}^K \beta_\nu b_{\nu, K}(x) \]

can be evaluated as

\[ p(x) = \begin{bmatrix} 1 & x & \cdots & x^K \end{bmatrix} B \begin{bmatrix} \beta_0 \\ \vdots \\ \beta_K \end{bmatrix}. \]

Definition at line 264 of file basis.hpp.

◆ polynomial_basis_derivatives()

template<std::size_t K, std::size_t N, typename Scalar , std::ranges::sized_range R>
constexpr StaticMatrix< Scalar, K+1, N > polynomial_basis_derivatives ( const StaticMatrix< Scalar, K+1, K+1 > &  B,
const R &  ts 
)
constexpr

Polynomial basis derivative coefficients.

Template Parameters
Kpolynomial degree
Nnumber of points
Parameters
Bpolonomial basis
tspoints to evaluate derivative coefficients at (must be of size N)

Computes a matrix D s.t. \( D_{i,j} = \frac{\mathrm{d}}{\mathrm{d}t} p_i(t_j) \) where \( p_i \) are basis polynomials defined by B.

Definition at line 347 of file basis.hpp.

◆ polynomial_cumulative_basis()

template<PolynomialBasis Basis, std::size_t K, typename Scalar = double>
constexpr StaticMatrix< Scalar, K+1, K+1 > polynomial_cumulative_basis ( )
constexpr

Cumulative coefficient matrix for given basis.

Template Parameters
Bpolonomial basis
Kpolynomial degree

Returns a row-major matrix \( \tilde B \) s.t. a cumulative polynomial

\[ p(x) = \sum_{\nu=0}^K \tilde \beta_\nu \tilde b_{\nu, K}(x) \]

can be evaluated as

\[ p(x) = \begin{bmatrix} 1 & x & \ldots & x^K \end{bmatrix} B \begin{bmatrix} \tilde \beta_0 \\ \vdots \\ \tilde \beta_K \end{bmatrix} \]

Definition at line 382 of file basis.hpp.