6#ifndef THEORETICA_INTERP_POLYNOMIAL_H
7#define THEORETICA_INTERP_POLYNOMIAL_H
30 typename Vector1,
typename Vector2,
31 enable_vector<Vector1> =
true,
32 enable_vector<Vector2> =
true,
33 typename Type = vector_element_t<Vector2>
42 if(x.size() != y.size()) {
48 for (
unsigned int i = 0; i < x.size() - 1; ++i) {
59 for (
unsigned int j = 0; j < x.size(); ++j) {
64 for (
unsigned int m = 0; m < x.size(); ++m) {
77 for (
size_t i = 0; i < l_j.
size(); ++i)
78 term[i] = y[j] * l_j[i];
95 template<
typename Vector = vec<real>>
101 real m = (b + a) / 2.0;
102 real c = (b - a) / 2.0;
104 for (
unsigned int i = 1; i < n + 1; ++i)
105 nodes[i - 1] = m + c *
cos(
real(2 * i - 1) /
real(2 * n) *
PI);
120 typename RealFunction,
121 typename Type = return_type_t<RealFunction>
129 for (
unsigned int i = 0; i < order + 1; ++i) {
130 x[i] = (b - a) /
real(order) *
real(i) + a;
151 typename RealFunction,
152 typename Type = return_type_t<RealFunction>
160 for (
unsigned int i = 0; i < order + 1; ++i)
175 typename RealFunction,
176 typename Type = return_type_t<RealFunction>
A polynomial of arbitrary order with coefficients of a specified type.
Definition polynomial.h:28
void resize(size_t sz)
Change the number of coefficients of the polynomial.
Definition polynomial.h:168
size_t size() const
Get the number of coefficients.
Definition polynomial.h:162
A statically allocated N-dimensional vector with elements of the given type.
Definition vec.h:92
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compilation op...
Definition error.h:219
Mathematical function pointers.
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:242
Vector chebyshev_nodes(real a, real b, unsigned int n)
Compute the n Chebyshev nodes on a given interval.
Definition polynomial.h:96
double real
A real number, defined as a floating point type.
Definition constants.h:207
Vector make_error(unsigned int n)
Create a vector representing an error state, with all NaN values and a fixed size.
Definition algebra.h:85
polynomial< Type > interpolate_grid(RealFunction f, real a, real b, unsigned int order)
Compute the interpolating polynomial of a real function on an equidistant grid.
Definition polynomial.h:123
polynomial< Type > lagrange(const Vector1 &x, const Vector2 &y)
Compute the Lagrange interpolating polynomial of a set of points.
Definition polynomial.h:35
polynomial< Type > interpolate(RealFunction f, real a, real b, unsigned int order)
Use the best available method to compute the interpolating polynomial of a real function.
Definition polynomial.h:178
dual2 cos(dual2 x)
Compute the cosine of a second order dual number.
Definition dual2_functions.h:86
@ InvalidArgument
Invalid argument.
Definition error.h:32
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition constants.h:216
polynomial< Type > interpolate_chebyshev(RealFunction f, real a, real b, unsigned int order)
Compute the interpolating polynomial of a real function using Chebyshev nodes as sampling points.
Definition polynomial.h:154
constexpr real PI
The Pi mathematical constant.
Definition constants.h:225
Polynomial storage and manipulation.