PolynomialsUtils { public static PolynomialFunction createJacobiPolynomial(final int degree, final int v, final int w) { final JacobiKey key = new JacobiKey(v, w); if (!JACOBI_COEFFICIENTS.containsKey(key)) { final List<BigFraction> list = new ArrayList<BigFraction>(); JACOBI_COEFFICIENTS.put(key, list); list.add(BigFraction.ONE); list.add(new BigFraction(v - w, 2)); list.add(new BigFraction(2 + v + w, 2)); } return buildPolynomial(degree, JACOBI_COEFFICIENTS.get(key), new RecurrenceCoefficientsGenerator() { public BigFraction[] generate(int k) { k++; final int kvw = k + v + w; final int twoKvw = kvw + k; final int twoKvwM1 = twoKvw - 1; final int twoKvwM2 = twoKvw - 2; final int den = 2 * k * kvw * twoKvwM2; return new BigFraction[] { new BigFraction(twoKvwM1 * (v * v - w * w), den), new BigFraction(twoKvwM1 * twoKvw * twoKvwM2, den), new BigFraction(2 * (k + v - 1) * (k + w - 1) * twoKvw, den) }; } }); } private  PolynomialsUtils(); static PolynomialFunction createChebyshevPolynomial(final int degree); static PolynomialFunction createHermitePolynomial(final int degree); static PolynomialFunction createLaguerrePolynomial(final int degree); static PolynomialFunction createLegendrePolynomial(final int degree); static PolynomialFunction createJacobiPolynomial(final int degree, final int v, final int w); static double[] shift(final double[] coefficients,
                                 final double shift);  }
@Test public void testJacobiEvaluationAt1() { for (int v = 0; v < 10; ++v) { for (int w = 0; w < 10; ++w) { for (int i = 0; i < 10; ++i) { PolynomialFunction jacobi = PolynomialsUtils.createJacobiPolynomial(i, v, w); double binomial = CombinatoricsUtils.binomialCoefficient(v + i, i); Assert.assertTrue(Precision.equals(binomial, jacobi.value(1.0), 1)); } } } }
@Test public void testJacobiOrthogonality() { for (int v = 0; v < 5; ++v) { for (int w = v; w < 5; ++w) { final int vv = v; final int ww = w; UnivariateFunction weight = new UnivariateFunction() { public double value(double x) { return FastMath.pow(1 - x, vv) * FastMath.pow(1 + x, ww); } }; for (int i = 0; i < 10; ++i) { PolynomialFunction pi = PolynomialsUtils.createJacobiPolynomial(i, v, w); for (int j = 0; j <= i; ++j) { PolynomialFunction pj = PolynomialsUtils.createJacobiPolynomial(j, v, w); checkOrthogonality(pi, pj, weight, -1, 1, 0.1, 1.0e-12); } } } } }