GaussJacobiWeightAndAbscissaFunction implements QuadratureWeightAndAbscissaFunction { @Override public GaussianQuadratureData generate(final int n) { Validate.isTrue(n > 0, "n > 0"); final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = JACOBI.getPolynomialsAndFirstDerivative(n, _alpha, _beta); final Pair<DoubleFunction1D, DoubleFunction1D> pair = polynomials[n]; final DoubleFunction1D previous = polynomials[n - 1].getFirst(); final DoubleFunction1D function = pair.getFirst(); final DoubleFunction1D derivative = pair.getSecond(); final double[] x = new double[n]; final double[] w = new double[n]; double root = 0; for (int i = 0; i < n; i++) { final double d = 2 * n + _c; root = getInitialRootGuess(root, i, n, x); root = ROOT_FINDER.getRoot(function, derivative, root); x[i] = root; w[i] = GAMMA_FUNCTION.evaluate(_alpha + n) * GAMMA_FUNCTION.evaluate(_beta + n) / MathUtils.factorialDouble(n) / GAMMA_FUNCTION.evaluate(n + _c + 1) * d * Math.pow(2, _c) / (derivative.evaluate(root) * previous.evaluate(root)); } return new GaussianQuadratureData(x, w); } GaussJacobiWeightAndAbscissaFunction();  GaussJacobiWeightAndAbscissaFunction(final double alpha, final double beta); @Override GaussianQuadratureData generate(final int n);  }
@Test public void test() { final int n = 12; final GaussianQuadratureData f1 = GAUSS_LEGENDRE.generate(n); final GaussianQuadratureData f2 = GAUSS_JACOBI_GL_EQUIV.generate(n); final GaussianQuadratureData f3 = GAUSS_JACOBI_CHEBYSHEV_EQUIV.generate(n); final double[] w1 = f1.getWeights(); final double[] w2 = f2.getWeights(); final double[] x1 = f1.getAbscissas(); final double[] x2 = f2.getAbscissas(); assertTrue(w1.length == w2.length); assertTrue(x1.length == x2.length); for (int i = 0; i < n; i++) { assertEquals(w1[i], w2[i], EPS); assertEquals(x1[i], -x2[i], EPS); } final double[] w3 = f3.getWeights(); final double[] x3 = f3.getAbscissas(); final double chebyshevWeight = Math.PI / n; final Function1D<Integer, Double> chebyshevAbscissa = new Function1D<Integer, Double>() { @Override public Double evaluate(final Integer x) { return -Math.cos(Math.PI * (x + 0.5) / n); } }; for (int i = 0; i < n; i++) { assertEquals(chebyshevWeight, w3[i], EPS); assertEquals(chebyshevAbscissa.evaluate(i), -x3[i], EPS); } }