PolynomialsUtils { public static PolynomialFunction createLaguerrePolynomial(final int degree) { return buildPolynomial(degree, LAGUERRE_COEFFICIENTS, new RecurrenceCoefficientsGenerator() { public BigFraction[] generate(int k) { final int kP1 = k + 1; return new BigFraction[] { new BigFraction(2 * k + 1, kP1), new BigFraction(-1, kP1), new BigFraction(k, kP1)}; } }); } 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 testFirstLaguerrePolynomials() { checkPolynomial(PolynomialsUtils.createLaguerrePolynomial(3), 6l, "6 - 18 x + 9 x^2 - x^3"); checkPolynomial(PolynomialsUtils.createLaguerrePolynomial(2), 2l, "2 - 4 x + x^2"); checkPolynomial(PolynomialsUtils.createLaguerrePolynomial(1), 1l, "1 - x"); checkPolynomial(PolynomialsUtils.createLaguerrePolynomial(0), 1l, "1"); checkPolynomial(PolynomialsUtils.createLaguerrePolynomial(7), 5040l, "5040 - 35280 x + 52920 x^2 - 29400 x^3" + " + 7350 x^4 - 882 x^5 + 49 x^6 - x^7"); checkPolynomial(PolynomialsUtils.createLaguerrePolynomial(6), 720l, "720 - 4320 x + 5400 x^2 - 2400 x^3 + 450 x^4" + " - 36 x^5 + x^6"); checkPolynomial(PolynomialsUtils.createLaguerrePolynomial(5), 120l, "120 - 600 x + 600 x^2 - 200 x^3 + 25 x^4 - x^5"); checkPolynomial(PolynomialsUtils.createLaguerrePolynomial(4), 24l, "24 - 96 x + 72 x^2 - 16 x^3 + x^4"); }
@Test public void testLaguerreDifferentials() { for (int k = 0; k < 12; ++k) { PolynomialFunction Lk0 = PolynomialsUtils.createLaguerrePolynomial(k); PolynomialFunction Lk1 = Lk0.polynomialDerivative(); PolynomialFunction Lk2 = Lk1.polynomialDerivative(); PolynomialFunction g0 = new PolynomialFunction(new double[] { k }); PolynomialFunction g1 = new PolynomialFunction(new double[] { 1, -1 }); PolynomialFunction g2 = new PolynomialFunction(new double[] { 0, 1 }); PolynomialFunction Lk0g0 = Lk0.multiply(g0); PolynomialFunction Lk1g1 = Lk1.multiply(g1); PolynomialFunction Lk2g2 = Lk2.multiply(g2); checkNullPolynomial(Lk0g0.add(Lk1g1.add(Lk2g2))); } }
@Test public void testLaguerreOrthogonality() { UnivariateFunction weight = new UnivariateFunction() { public double value(double x) { return FastMath.exp(-x); } }; for (int i = 0; i < 10; ++i) { PolynomialFunction pi = PolynomialsUtils.createLaguerrePolynomial(i); for (int j = 0; j <= i; ++j) { PolynomialFunction pj = PolynomialsUtils.createLaguerrePolynomial(j); checkOrthogonality(pi, pj, weight, 0.0, 100.0, 0.99999, 1.0e-13); } } }