75 #ifndef SLIP_POLYNOMIAL_ALGO_HPP
76 #define SLIP_POLYNOMIAL_ALGO_HPP
131 template <
typename Poly,
typename Poly1,
typename Poly2,
typename Poly3>
135 typedef typename Poly::mapped_type T;
137 return ((((Poly(x) * Poly(Pk))* T(2 * k + 1)) - (Poly(Pkm1)* T(k))) / T(k + 1));
170 template <
typename Poly,
typename Poly1,
typename Poly2,
typename Poly3>
174 typedef typename Poly::value_type T;
176 return ((((Poly(x) * Poly(Pk))* T(2 * k + 1)) - (Poly(Pkm1)* T(k))) / T(k + 1));
239 template <
typename Poly,
246 typedef typename Poly::value_type T;
248 return ((Poly(x) * Poly(Pk))* T(2)) - Poly(Pkm1);
293 template <
typename Poly,
typename Poly1,
typename Poly2,
typename Poly3>
297 typedef typename Poly::mapped_type T;
299 return ((Poly(x) * Poly(Pk))* T(2)) - Poly(Pkm1);
329 template<
typename T,
typename RandomAccessIterator>
333 RandomAccessIterator first, RandomAccessIterator last)
335 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(n + 1));
353 for (std::size_t j = 2; j <= n; ++j)
355 first[j] = (twox * first[j-1]) - first[j-2];
389 template<
typename T,
typename RandomAccessIterator>
393 RandomAccessIterator first, RandomAccessIterator last)
395 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(n + 1));
396 T N =
static_cast<T
>(last-first);
404 first[1] = T(2)*x - N + T(1);
409 T twox = T(2)*x - N + T(1);
414 for (std::size_t j = 2; j <= n; ++j)
416 T jf =
static_cast<T
>(j);
417 T jf_m_1 = jf -
static_cast<T
>(1);
418 T alpha = (jf_m_1 + jf_m_1 +
static_cast<T
>(1)) / jf;
419 T jf_m_12 =
static_cast<T
>(jf_m_1 * jf_m_1);
420 T beta = (
static_cast<T
>(jf_m_1)*(N2-jf_m_12))/jf;
422 first[j] = alpha*(twox * first[j-1]) - beta*first[j-2];
471 template <
typename Poly,
478 typedef typename Poly::value_type T;
480 return ((Poly(x) * Poly(Pk))* T(2)) - Poly(Pkm1)* T(2*k);
524 template <
typename Poly,
typename Poly1,
typename Poly2,
typename Poly3>
528 typedef typename Poly::mapped_type T;
530 return ((Poly(x) * Poly(Pk))* T(2)) - Poly(Pkm1)* T(2*k);
560 template<
typename T,
typename RandomAccessIterator>
564 RandomAccessIterator first, RandomAccessIterator last)
566 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(n + 1));
584 for (std::size_t j = 2; j <= n; ++j)
586 first[j] = (twox * first[j-1]) - T(2*j-2)*first[j-2];
644 template <
typename Poly,
651 typedef typename Poly::value_type T;
653 return (((T(2*k+1) - Poly(x)) * Poly(Pk)) - Poly(Pkm1)* T(k))/T(k+1);
699 template <
typename Poly,
typename Poly1,
typename Poly2,
typename Poly3>
703 typedef typename Poly::mapped_type T;
705 return (((T(2*k+1) - Poly(x)) * Poly(Pk)) - Poly(Pkm1)* T(k))/T(k+1);
736 template<
typename T,
typename RandomAccessIterator>
740 RandomAccessIterator first, RandomAccessIterator last)
742 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(n + 1));
750 first[1] = -x + T(1);
756 first[1] = -x + T(1);
759 for (std::size_t j = 2; j <= n; ++j)
761 first[j] = -(((x - T(2*j-1))* first[j-1]) + T(j-1)*first[j-2])/T(j);
785 template<
typename T,
typename RandomAccessIterator>
787 T
eval_horner(RandomAccessIterator first, RandomAccessIterator last,
790 assert(last != first);
798 s = std::accumulate(first,last,T(0));
802 typedef typename std::iterator_traits<RandomAccessIterator>::difference_type _Distance;
803 _Distance size = (last - first);
805 for(_Distance i = 1; i < size; ++i)
819 typedef typename std::iterator_traits<RandomAccessIterator>::difference_type _Distance;
821 _Distance size = last - first;
823 for(_Distance i = (size - 2); i >= 0; --i)
825 s = first[i] + x * s;
847 template<
typename T,
typename RandomAccessIterator>
851 RandomAccessIterator first, RandomAccessIterator last)
853 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(n + 1));
869 std::fill(first,last,T(0));
873 std::fill(first,last,T(1));
880 while(++first != last)
898 while(++first != last)
924 template<
typename T,
typename RandomAccessIterator>
928 RandomAccessIterator first, RandomAccessIterator last)
930 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(n + 1));
950 for (std::size_t j = 2; j <= n; ++j)
954 first[j] = (f2 * first[j-1] - f1 * first[j-2]) / d;
977 template<
typename T,
typename RandomAccessIterator>
981 RandomAccessIterator first, RandomAccessIterator last)
983 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(n + 1));
999 for (std::size_t j = 2; j <= n; ++j)
1001 first[j] = (twox * first[j-1]) - first[j-2];
1026 template<
class Vector,
typename RandomAccessIterator>
1029 const std::size_t n,
1030 RandomAccessIterator first, RandomAccessIterator last)
1032 assert(x.
size() == 2);
1033 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(((n + 1)*(n+2))/2));
1036 for(std::size_t i = 0; i < Eval.rows(); ++i)
1041 for(std::size_t i = 0; i < (n+1); ++i)
1043 for(std::size_t j = 0; j < ((n+1) - i); ++j)
1045 *first++ = Eval[0][j] * Eval[1][i];
1071 template<
class Vector,
typename RandomAccessIterator>
1074 const std::size_t order,
1075 RandomAccessIterator first, RandomAccessIterator last)
1077 std::size_t dim = x.
size();
1080 std::size_t result_size = (std::accumulate(V.
begin()+order,V.
end(),1,std::multiplies<int>()))/(std::accumulate(V.
begin(),V.
begin()+dim,1,std::multiplies<int>()));
1082 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(result_size));
1087 for(std::size_t d = 0; d < powers.
dim2(); ++d)
1090 for(std::size_t ord = 0, ord2 = 0; ord <= (powers.
dim1() - step); ord+=step,++ord2)
1092 std::size_t tmp = ord2%(order+1);
1093 for(std::size_t k = 0; k < step; ++k)
1095 powers[ord+k][d] = tmp;
1101 typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;
1104 for(std::size_t i = 0; i < Eval.rows(); ++i)
1110 for(std::size_t ord = 0; ord < powers.
dim1(); ++ord)
1113 if(std::accumulate(powers.
row_begin(ord),powers.
row_end(ord),
static_cast<std::size_t
>(0)) <= order)
1116 value_type res = value_type(1);
1117 for(std::size_t d = 0; d < dim; ++d)
1119 res = res * Eval[d][powers[ord][d]];
1176 template<
typename MultivariatePolynomial,
1177 typename RandomAccessIterator>
1180 const std::size_t n,
1181 RandomAccessIterator first,
1182 RandomAccessIterator last)
1184 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(n + 1));
1201 while(++first != last)
1253 template<
class Vector,
typename RandomAccessIterator>
1256 const std::size_t order,
1257 RandomAccessIterator first, RandomAccessIterator last)
1259 std::size_t dim = x.
size();
1262 std::size_t result_size = (std::accumulate(V.
begin()+order,V.
end(),1,std::multiplies<int>()))/(std::accumulate(V.
begin(),V.
begin()+dim,1,std::multiplies<int>()));
1264 assert((last - first) ==
typename std::iterator_traits<RandomAccessIterator>::difference_type(result_size));
1269 for(std::size_t d = 0; d < powers.
dim2(); ++d)
1272 for(std::size_t ord = 0, ord2 = 0; ord <= (powers.
dim1() - step); ord+=step,++ord2)
1274 std::size_t tmp = ord2%(order+1);
1275 for(std::size_t k = 0; k < step; ++k)
1277 powers[ord+k][d] = tmp;
1283 typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;
1286 for(std::size_t i = 0; i < Eval.rows(); ++i)
1292 for(std::size_t ord = 0; ord < powers.
dim1(); ++ord)
1294 if(std::accumulate(powers.
row_begin(ord),powers.
row_end(ord),
static_cast<std::size_t
>(0)) <= order)
1297 value_type res = value_type(0);
1298 for(std::size_t d = 0; d < dim; ++d)
1300 res = res * Eval[d][powers[ord][d]];
1311 template<
typename T,
typename RandomAccessIterator>
1315 const std::size_t n,
1316 RandomAccessIterator first,
1317 RandomAccessIterator last )
const = 0;
1322 template<
typename T,
typename RandomAccessIterator>
1326 const std::size_t n,
1327 RandomAccessIterator first,
1328 RandomAccessIterator last )
const
1335 template<
typename T,
typename RandomAccessIterator>
1339 const std::size_t n,
1340 RandomAccessIterator first,
1341 RandomAccessIterator last )
const
1347 template<
typename T,
typename RandomAccessIterator>
1351 const std::size_t n,
1352 RandomAccessIterator first,
1353 RandomAccessIterator last )
const
1359 template<
typename T,
typename RandomAccessIterator>
1363 const std::size_t n,
1364 RandomAccessIterator first,
1365 RandomAccessIterator last )
const
1372 template<
typename T,
typename RandomAccessIterator>
1377 const std::size_t n,
1378 RandomAccessIterator first,
1379 RandomAccessIterator last )
const
1391 #endif //SLIP_POLYNOMIAL_ALGO_HPP
Provides a class to manipulate 2d dynamic and generic arrays.
void operator()(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last) const
void operator()(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last) const
void eval_power_2d_basis(const Vector &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluation of the powers of X = (x1,x2) such that with and the power of x1 and x2...
T power(T x, Integer N)
function to compute.
void eval_chebyshev_basis(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluations of x until order n to the range [first,last) using the Chebyshev scheme...
void eval_chebyshevII_basis(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluations of x until order n to the range [first,last) using the ChebyshevII scheme...
iterator begin()
Returns a read/write iterator that points to the first element in the Array. Iteration is done in ord...
void operator()(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last) const
Poly legendre_next(std::size_t k, Poly1 x, Poly2 Pk, Poly3 Pkm1)
Implements the three term recurrence relation for the Legendre polynomials, this function can be used...
Poly legendre_nd_next(std::size_t k, Poly1 x, Poly2 Pk, Poly3 Pkm1)
Implements the three term recurrence relation for the Legendre multivariate polynomials, this function can be used to create a sequence of orthogonal polynomial, and for rising k. This recurrence relation holds for Legendre Polynomials of both the first and second kinds: .
void iota(ForwardIterator first, ForwardIterator last, T value, T step=T(1))
Iota assigns sequential increasing values based on a predefined step to a range. That is...
void operator()(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last) const
Poly chebyshev_next(std::size_t k, Poly1 x, Poly2 Pk, Poly3 Pkm1)
Implements the three term recurrence relation for the Chebyshev polynomials, this function can be use...
Poly laguerre_nd_next(std::size_t k, Poly1 x, Poly2 Pk, Poly3 Pkm1)
Implements the three term recurrence relation for the Laguerre multivariate polynomials, this function can be used to create a sequence of orthogonal polynomial, and for rising k. This recurrence relation holds for Laguere Polynomials: .
void eval_laguerre_basis(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluations of x until order n to the range [first,last) using the Laguerre scheme...
Numerical MultivariatePolynomial class.
void eval_power_basis(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluation of the power of x until order n to the range [first,last) using the horner sch...
void eval_multi_poly_power_basis(const MultivariatePolynomial &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluation of the power of a slip::MultivariatePolynomial<T,DIM> P until order n to the r...
iterator end()
Returns a read/write iterator that points one past the last element in the Array. Iteration is done i...
Provides some statistics algorithms.
size_type size() const
Returns the number of elements in the Vector.
void eval_discrete_chebyshev_basis(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluations of x until order n to the range [first,last) using the Discrete Chebyshev sch...
size_type dim2() const
Returns the number of columns (second dimension size) in the Array2d.
Numerical Vector class. This container statisfies the RandomAccessContainer concepts of the Standard ...
T eval_horner(RandomAccessIterator first, RandomAccessIterator last, const T &x)
Returns the evaluation of the polynomial given throw the range [first,last) at x using the horner sch...
Provides some algorithms to computes arithmetical operations on ranges.
row_iterator row_begin(const size_type row)
Returns a read/write iterator that points to the first element of the row row in the Array2d...
Poly hermite_nd_next(std::size_t k, Poly1 x, Poly2 Pk, Poly3 Pkm1)
Implements the three term recurrence relation for the Hermite multivariate polynomials, this function can be used to create a sequence of orthogonal polynomial, and for rising k. This recurrence relation holds for Hermite Polynomials: .
Poly hermite_next(std::size_t k, Poly1 x, Poly2 Pk, Poly3 Pkm1)
Implements the three term recurrence relation for the Hermite polynomials, this function can be used ...
Poly laguerre_next(std::size_t k, Poly1 x, Poly2 Pk, Poly3 Pkm1)
Implements the three term recurrence relation for the Laguerre polynomials, this function can be used...
void eval_power_nd_basis(const Vector &x, const std::size_t order, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluation of the powers of such that with the power of the xk to the range [first...
void eval_multi_poly_power_nd_basis(const Vector &x, const std::size_t order, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluation of the powers of slip::MultivariatePolynomial<T,DIM> such that with the pow...
row_iterator row_end(const size_type row)
Returns a read/write iterator that points one past the end element of the row row in the Array2d...
virtual void operator()(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last) const =0
void eval_hermite_basis(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluations of x until order n to the range [first,last) using the Hermite scheme...
void operator()(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last) const
This is a two-dimensional dynamic and generic container. This container statisfies the Bidirectionnal...
Poly chebyshev_nd_next(std::size_t k, Poly1 x, Poly2 Pk, Poly3 Pkm1)
Implements the three term recurrence relation for the Chebyshev multivariate polynomials, this function can be used to create a sequence of orthogonal polynomial, and for rising k. This recurrence relation holds for Chebychev Polynomials of both the first and second kinds: .
void eval_legendre_basis(const T &x, const std::size_t n, RandomAccessIterator first, RandomAccessIterator last)
Returns the evaluations of x until order n to the range [first,last) using the legendre scheme...
size_type dim1() const
Returns the number of rows (first dimension size) in the Array2d.