ChebyshevPolynomialOfFirstKindFunction 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] = getOne(); } else if (i == 1) { polynomials[i] = getX(); } else { polynomials[i] = polynomials[i - 1].multiply(getX()).multiply(2).subtract(polynomials[i - 2]); } } return polynomials; }  @Override DoubleFunction1D[] getPolynomials(final int n); @Override Pair<DoubleFunction1D, DoubleFunction1D>[] getPolynomialsAndFirstDerivative(final int n);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testBadN() { CHEBYSHEV.getPolynomials(-3); }
@Test(expectedExceptions = NotImplementedException.class) public void testGetPolynomials() { CHEBYSHEV.getPolynomialsAndFirstDerivative(3); }
@Test public void test() { DoubleFunction1D[] t = CHEBYSHEV.getPolynomials(0); assertEquals(t.length, 1); final double x = 1.23; assertEquals(t[0].evaluate(x), 1, EPS); t = CHEBYSHEV.getPolynomials(1); assertEquals(t.length, 2); assertEquals(t[1].evaluate(x), x, EPS); for (int i = 0; i < 10; i++) { t = CHEBYSHEV.getPolynomials(i); for (int j = 0; j <= i; j++) { assertEquals(T[j].evaluate(x), t[j].evaluate(x), EPS); } } }