GaussHermiteWeightAndAbscissaFunction implements QuadratureWeightAndAbscissaFunction { @Override public GaussianQuadratureData generate(final int n) { Validate.isTrue(n > 0); final double[] x = new double[n]; final double[] w = new double[n]; final boolean odd = n % 2 != 0; final int m = (n + 1) / 2 - (odd ? 1 : 0); final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = HERMITE.getPolynomialsAndFirstDerivative(n); final Pair<DoubleFunction1D, DoubleFunction1D> pair = polynomials[n]; final DoubleFunction1D function = pair.getFirst(); final DoubleFunction1D derivative = pair.getSecond(); double root = 0; for (int i = 0; i < m; i++) { root = getInitialRootGuess(root, i, n, x); root = ROOT_FINDER.getRoot(function, derivative, root); final double dp = derivative.evaluate(root); x[i] = -root; x[n - 1 - i] = root; w[i] = 2. / (dp * dp); w[n - 1 - i] = w[i]; } if (odd) { final double dp = derivative.evaluate(0.0); w[m] = 2. / dp / dp; } return new GaussianQuadratureData(x, w); }  @Override GaussianQuadratureData generate(final int n);  }
@Test public void test() { assertResults(F.generate(2), X2, W2); assertResults(F.generate(3), X3, W3); assertResults(F.generate(4), X4, W4); }