OrthonormalHermitePolynomialFunction extends OrthogonalPolynomialFunctionGenerator { @Override public DoubleFunction1D[] getPolynomials(final int n) { Validate.isTrue(n >= 0); final DoubleFunction1D[] polynomials = new DoubleFunction1D[n + 1]; for (int i = 0; i <= n; i++) { if (i == 0) { polynomials[i] = F0; } else if (i == 1) { polynomials[i] = polynomials[0].multiply(Math.sqrt(2)).multiply(getX()); } else { polynomials[i] = polynomials[i - 1].multiply(getX()).multiply(Math.sqrt(2. / i)).subtract(polynomials[i - 2].multiply(Math.sqrt((i - 1.) / i))); } } return polynomials; }  @Override DoubleFunction1D[] getPolynomials(final int n); @Override Pair<DoubleFunction1D, DoubleFunction1D>[] getPolynomialsAndFirstDerivative(final int n);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testBadN() { ORTHONORMAL.getPolynomials(-3); }
@Test public void test() { final int n = 15; final DoubleFunction1D[] f1 = HERMITE.getPolynomials(n); final DoubleFunction1D[] f2 = ORTHONORMAL.getPolynomials(n); final double x = 3.4; for (int i = 0; i < f1.length; i++) { assertEquals(f1[i].evaluate(x) / Math.sqrt(MathUtils.factorialDouble(i) * Math.pow(2, i) * Math.sqrt(Math.PI)), f2[i].evaluate(x), EPS); } }