19 std::array<double, N> node {};
20 std::array<double, N> weight {};
24 for (
int i = 0; i < N; ++i) {
25 double x = std::cos(std::numbers::pi * (i + 0.75) / (N + 0.5));
26 double derivative = 1.0;
27 for (
int iteration = 0; iteration < 100; ++iteration) {
30 for (
int k = 2; k <= N; ++k) {
31 const double p2 = ((2.0 * k - 1.0) * x * p1 - (k - 1.0) * p0) / k;
35 derivative = N * (x * p1 - p0) / (x * x - 1.0);
36 const double step = p1 / derivative;
38 if (std::abs(step) < 1e-15) {
42 node[
static_cast<std::size_t
>(i)] = x;
43 weight[
static_cast<std::size_t
>(i)] = 2.0 / ((1.0 - x * x) * derivative * derivative);