17 template<
typename CoeffT>
22 template<
typename CoeffT>
28 template<
typename CoeffT>
34 template<
typename CoeffT>
38 for (
size_t j = 1; j < c.size(); j++) {
44 template<
typename CoeffT>
48 for (
size_t j = 0; j < c.size(); j++) {
49 p[j + 1] = c[j] / (j + 1);
54 template<
typename CoeffT>
58 for (
size_t j = 0; j < c.size(); j++) {
59 p[j] = c[j] / c.back();
69 template<
typename CoeffT>
72 assert(c.size() >= 1);
73 size_t n = c.size() - 1;
76 vector<complex<CoeffT>> z0(n);
77 for (
size_t j = 0; j < n; j++) {
78 z0[j] = pow(complex<double>(0.4, 0.9), j);
83 for (
size_t k = 0; k < num_iterations; k++) {
84 complex<CoeffT> num, den;
85 for (
size_t i = 0; i < n; i++) {
88 for (
size_t j = 0; j < n; j++) {
89 if (j == i) {
continue; }
90 den = den * (z0[i] - z0[j]);
92 z0[i] = z0[i] - num / den;
96 vector<CoeffT> roots(n);
97 for (
size_t j = 0; j < n; j++) {
98 roots[j] = abs(z0[j]) < ztol ? 0.0 : real(z0[j]);
101 sort(roots.begin(), roots.end());
105 template<
typename CoeffT>
122 p0[0] = 1.0; p1[1] = 1.0;
125 for (
size_t m = 1; m < order; m++) {
126 for (
size_t j = 1; j < order + 1; j++) {
127 p2[j] = ((2 * m + 1) * p1[j - 1] - m * p0[j]) / (m + 1);
129 p2[0] = - int(m) * p0[0] / (m + 1);
131 for (
size_t j = 0; j < order + 1; j++) {
Representation of a polynomial including differentiation, integration and root finding.
Polynomial< CoeffT > normalize() const
Normalizes this polynomial with respect to \( c_0 \).
Polynomial< CoeffT > integrate() const
Integrates this polynomial.
Polynomial< CoeffT > differentiate() const
Differentiate this polynomial.
vector< CoeffT > roots(size_t num_iterations=100, CoeffT ztol=1.0e-20) const
Computes the roots of this polynomial.
static Polynomial< CoeffT > legendre(const size_t order)
Computes the Legendre polynomial of given order.
size_t order() const
Order of this polynomial.
CoeffT & operator[](const size_t i)
Access coefficient i.
xtype evaluate(const xtype x) const
Evaluate polynomial for given value.