6 #ifndef THEORETICA_POLYN_ORTHOGONAL_H
7 #define THEORETICA_POLYN_ORTHOGONAL_H
10 #include "../optimization/roots.h"
42 for (
unsigned int l = 2; l <= n; ++l) {
79 return sqrt((2 * n + 1) / 2.0);
84 inline std::function<
real(
real)> assoc_legendre_polynomial(
unsigned int l,
int m) {
95 for (
int i = 0; i < m; ++i)
102 return pow(1 - x * x, m / 2) * L(x) / K;
108 return sqrt(
pow(1 - x * x, m)) * L(x) / K;
115 inline polynomial<real> assoc_legendre_polynomial_even(
unsigned int l,
int m) {
118 TH_MATH_ERROR(
"assoc_legendre_polynomial_even", m, IMPOSSIBLE_OPERATION);
128 polynomial<real> P =
ipow(polynomial<real>({1, 0, -1}), m / 2);
130 for (
int i = 0; i < m; ++i)
176 {1}, {1 + alpha, -1},
258 std::vector<real>
roots;
261 for (
unsigned int i = 1; i <= n; ++i) {
276 const unsigned int n =
roots.size();
279 std::vector<real> weights;
282 for (
unsigned int i = 0; i < n; ++i) {
297 const unsigned int n =
roots.size();
300 std::vector<real> weights;
303 for (
unsigned int i = 0; i < n; ++i) {
318 const unsigned int n =
roots.size();
321 std::vector<real> weights;
324 for (
unsigned int i = 0; i < n; ++i) {
A polynomial of arbitrary order.
Definition: polynomial.h:25
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compiling opti...
Definition: error.h:219
Main namespace of the library which contains all functions and objects.
Definition: algebra.h:27
double real
A real number, defined as a floating point type.
Definition: constants.h:188
polynomial< real > legendre_polyn_recurr(polynomial< real > P0, polynomial< real > P1, unsigned int l)
Recursion formula for Legendre polynomials.
Definition: orthogonal.h:58
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition: dual2_functions.h:54
polynomial< real > chebyshev_polyn_recurr(polynomial< real > T0, polynomial< real > T1, unsigned int i)
Recursion formula for Chebyshev polynomials The formula is the same for first and second kind polynom...
Definition: orthogonal.h:217
std::vector< real > hermite_weights(const std::vector< real > &roots)
Hermite weights for Gauss-Hermite quadrature of n-th order.
Definition: orthogonal.h:316
polynomial< real > legendre_polynomial(unsigned int n)
Compute the nth Legendre polynomial.
Definition: orthogonal.h:67
polynomial< real > laguerre_polyn_recurr(polynomial< real > L0, polynomial< real > L1, unsigned int i)
Recursion formula for Laguerre polynomials.
Definition: orthogonal.h:141
constexpr real SQRTPI
The square root of Pi.
Definition: constants.h:224
polynomial< real > hermite_polynomial(unsigned int n)
Compute the nth Hermite polynomial.
Definition: orthogonal.h:196
TH_CONSTEXPR T ipow(T x, unsigned int n, T neutral_element=T(1))
Compute the n-th positive power of x (where n is natural)
Definition: real_analysis.h:644
polynomial< real > general_laguerre_polynomial(real alpha, unsigned int n)
Compute the nth Laguerre polynomial.
Definition: orthogonal.h:170
std::vector< real > legendre_weights(const std::vector< real > &roots)
Legendre weights for Gauss-Legendre quadrature of n-th order.
Definition: orthogonal.h:274
polynomial< real > gen_polyn_recurr(polynomial< real > P0, polynomial< real > P1, polyn_recurr_formula f, unsigned int n)
Generate a polynomial basis using a recursion formula.
Definition: orthogonal.h:29
real hermite_polyn_normalization(unsigned int n)
Normalization constant for the nth Hermite polynomial.
Definition: orthogonal.h:206
TH_CONSTEXPR IntType fact(unsigned int n)
Compute the factorial of n.
Definition: real_analysis.h:671
polynomial< real > general_laguerre_polyn_recurr(polynomial< real > L0, polynomial< real > L1, real alpha, unsigned int i)
Recursion formula for Generalized Laguerre polynomials.
Definition: orthogonal.h:162
std::vector< real > roots(RealFunction f, real a, real b, real tolerance=OPTIMIZATION_TOL, real steps=10)
Find the roots of a function inside a given interval.
Definition: roots.h:462
real root_newton(RealFunction f, RealFunction Df, real guess=0)
Approximate a root of an arbitrary function using Newton's method.
Definition: roots.h:100
polynomial< real > chebyshev2_polynomial(unsigned int n)
Compute the nth Chebyshev polynomial of the second kind.
Definition: orthogonal.h:237
std::vector< real > legendre_roots(unsigned int n)
Roots of the n-th Legendre polynomial.
Definition: orthogonal.h:249
polynomial< real > hermite_polyn_recurr(polynomial< real > H0, polynomial< real > H1, unsigned int i)
Recursion formula for Hermite polynomials.
Definition: orthogonal.h:187
real legendre_polyn_normalization(unsigned int n)
Normalization constant for the nth Legendre polynomial.
Definition: orthogonal.h:77
polynomial< Field > deriv(const polynomial< Field > &p)
Compute the exact derivative of a polynomial function.
Definition: deriv.h:21
polynomial< real > laguerre_polynomial(unsigned int n)
Compute the nth Laguerre polynomial.
Definition: orthogonal.h:149
std::function< polynomial< real >(polynomial< real >, polynomial< real >, unsigned int)> polyn_recurr_formula
Polynomial sequence recurrence formula type Used for computing orthogonal polynomial basis elements.
Definition: orthogonal.h:20
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition: dual2_functions.h:23
std::vector< real > laguerre_weights(const std::vector< real > &roots)
Laguerre weights for Gauss-Laguerre quadrature of n-th order.
Definition: orthogonal.h:295
polynomial< real > chebyshev1_polynomial(unsigned int n)
Compute the nth Chebyshev polynomial of the first kind.
Definition: orthogonal.h:226
dual2 pow(dual2 x, int n)
Compute the n-th power of a second order dual number.
Definition: dual2_functions.h:41
Polynomial storage and manipulation.