58 numIterations_(numIterations),
59 weight_(numIterations + 1),
60 root_(numIterations + 1)
62 calculateWeightAndRoot();
71 [[nodiscard]]
const std::vector<double>&
getWeight() const noexcept
82 [[nodiscard]]
const std::vector<double>&
getRoot() const noexcept
95 double derivative{ 0. };
104 Result(
const double val,
const double deriv) noexcept :
115 void calculateWeightAndRoot() noexcept
117 const auto numIterationsDouble =
static_cast<double>(numIterations_);
118 for (
uint32 step = 0; step <= numIterations_; ++step)
121 std::cos(
constants::pi * (
static_cast<double>(step) - 0.25) / (numIterationsDouble + 0.5));
122 Result result = calculatePolynomialValueAndDerivative(root);
124 double newtonRaphsonRatio;
127 newtonRaphsonRatio = result.value / result.derivative;
128 root -= newtonRaphsonRatio;
129 result = calculatePolynomialValueAndDerivative(root);
130 }
while (std::fabs(newtonRaphsonRatio) > EPSILON);
133 weight_[step] = 2. / ((1. -
utils::sqr(root)) * result.derivative * result.derivative);
144 Result calculatePolynomialValueAndDerivative(
const double x)
noexcept
146 Result result(x, 0.);
148 double value_minus_1 = 1.;
150 for (
uint32 step = 2; step <= numIterations_; ++step)
152 const auto stepDouble =
static_cast<double>(step);
154 ((2. * stepDouble - 1.) * x * result.value - (stepDouble - 1.) * value_minus_1) / stepDouble;
155 result.derivative = stepDouble *
f * (x * value - result.value);
157 value_minus_1 = result.value;
158 result.value = value;
165 const double EPSILON{ 1
e-15 };
167 const uint32 numIterations_{};
168 std::vector<double> weight_{};
169 std::vector<double> root_{};