24 static constexpr T
eps = std::numeric_limits<T>::epsilon();
31 inline void laguer(
const std::vector<std::complex<T>>& a, std::complex<T>& x,
int& converged,
int itmax){
33 std::complex<T> dx, x1,
b, d, f, g, h, sq, gp, gm, g2;
37 for (
int iter = 1; iter <= itmax; iter++) {
38 b = std::complex<T>(1.0, 0.0);
40 d = f = std::complex<T>(0.0, 0.0);
43 for (
int j = m - 1;
j >= 0;
j--) {
55 h =
fma(f /
b, -
static_cast<T
>(2), g2);
56 sq = std::sqrt(
static_cast<T
>(m - 1) * (
fma(h,
static_cast<T
>(m), -g2)));
62 gp = abp < abm ? gm : gp;
63 dx = (std::max(abp, abm) >
static_cast<T
>(0.0)) ? (
static_cast<T
>(m) / gp) : std::polar(
static_cast<T
>(1) + abx,
static_cast<T
>(iter));
86 void operator()(std::vector<T>& poly, std::vector<std::complex<T>>& roots, std::vector<int>& conv,
int itmax=80)
override{
87 std::complex<T> x, _b, _c;
88 int m = poly.size() - 1;
90 std::vector<std::complex<T>> ad(m + 1);
93 for (
int i = 0; i <= m; i++)
96 std::vector<std::complex<T>> ad_v;
97 for (
int j = m - 1;
j > 0; --
j) {
99 x = std::complex<T>(0.0, 0.0);
102 ad_v = std::vector<std::complex<T>>(ad.cbegin(), ad.cbegin() +
j + 2);
103 laguer(ad_v, x, conv[
j], itmax);
105 x.imag(std::abs(imag(x)) <= std::abs(real(x)) *
eps ?
static_cast<T
>(0) : x.imag());
108 for (
int jj =
j; jj >= 0; jj--) {
119 std::cout <<
"has complex!\n";
122 for (
int j = 1;
j < m; ++
j) {
124 for (i =
j - 1; i>=0; --i) {
125 if (real(roots[i]) <= real(x))
127 roots[i + 1] = roots[i];
std::vector< double > err(double q, double x)
Definition Laguerre15m.h:96
p2 de j *z j
Definition Laguerre15m_or.h:23
cohn_schur ra local b
Definition Laguerre15m_or.h:3
Definition BaseSolver.h:7
void operator()(std::vector< T > &poly, std::vector< std::complex< T > > &roots, std::vector< int > &conv, int itmax=80) override
Find the roots of a polynomial using Laguerre's method.
Definition Laguerre.h:86
static constexpr T eps
Definition Laguerre.h:24
void laguer(const std::vector< std::complex< T > > &a, std::complex< T > &x, int &converged, int itmax)
Laguerre's method to find a root of a polynomial.
Definition Laguerre.h:31
Original()
Definition Laguerre.h:75
Definition ExtendedFunctions.h:14
complex< number > fma(complex< number > a, complex< number > b, complex< number > c)
Fused multiply-add for complex numbers.
Definition ExtendedFunctions.h:82
bool anycomplex(T &&... t)
Check if at least one complex number has imaginary part.
Definition ExtendedFunctions.h:39