PolynomialsUtils { public static PolynomialFunction createChebyshevPolynomial(final int degree) { return buildPolynomial(degree, CHEBYSHEV_COEFFICIENTS, new RecurrenceCoefficientsGenerator() { private final BigFraction[] coeffs = { BigFraction.ZERO, BigFraction.TWO, BigFraction.ONE }; public BigFraction[] generate(int k) { return coeffs; } }); } 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 testFirstChebyshevPolynomials() { checkPolynomial(PolynomialsUtils.createChebyshevPolynomial(3), "-3 x + 4 x^3"); checkPolynomial(PolynomialsUtils.createChebyshevPolynomial(2), "-1 + 2 x^2"); checkPolynomial(PolynomialsUtils.createChebyshevPolynomial(1), "x"); checkPolynomial(PolynomialsUtils.createChebyshevPolynomial(0), "1"); checkPolynomial(PolynomialsUtils.createChebyshevPolynomial(7), "-7 x + 56 x^3 - 112 x^5 + 64 x^7"); checkPolynomial(PolynomialsUtils.createChebyshevPolynomial(6), "-1 + 18 x^2 - 48 x^4 + 32 x^6"); checkPolynomial(PolynomialsUtils.createChebyshevPolynomial(5), "5 x - 20 x^3 + 16 x^5"); checkPolynomial(PolynomialsUtils.createChebyshevPolynomial(4), "1 - 8 x^2 + 8 x^4"); }
@Test public void testChebyshevBounds() { for (int k = 0; k < 12; ++k) { PolynomialFunction Tk = PolynomialsUtils.createChebyshevPolynomial(k); for (double x = -1; x <= 1; x += 0.02) { Assert.assertTrue(k + " " + Tk.value(x), FastMath.abs(Tk.value(x)) < (1 + 1e-12)); } } }
@Test public void testChebyshevDifferentials() { for (int k = 0; k < 12; ++k) { PolynomialFunction Tk0 = PolynomialsUtils.createChebyshevPolynomial(k); PolynomialFunction Tk1 = Tk0.polynomialDerivative(); PolynomialFunction Tk2 = Tk1.polynomialDerivative(); PolynomialFunction g0 = new PolynomialFunction(new double[] { k * k }); PolynomialFunction g1 = new PolynomialFunction(new double[] { 0, -1}); PolynomialFunction g2 = new PolynomialFunction(new double[] { 1, 0, -1 }); PolynomialFunction Tk0g0 = Tk0.multiply(g0); PolynomialFunction Tk1g1 = Tk1.multiply(g1); PolynomialFunction Tk2g2 = Tk2.multiply(g2); checkNullPolynomial(Tk0g0.add(Tk1g1.add(Tk2g2))); } }
@Test public void testChebyshevOrthogonality() { UnivariateFunction weight = new UnivariateFunction() { public double value(double x) { return 1 / FastMath.sqrt(1 - x * x); } }; for (int i = 0; i < 10; ++i) { PolynomialFunction pi = PolynomialsUtils.createChebyshevPolynomial(i); for (int j = 0; j <= i; ++j) { PolynomialFunction pj = PolynomialsUtils.createChebyshevPolynomial(j); checkOrthogonality(pi, pj, weight, -0.9999, 0.9999, 1.5, 0.03); } } }