public Pair<DoubleFunction1D, DoubleFunction1D>[] getPolynomialsAndFirstDerivative(final int n, final double alpha, final double beta) {
Validate.isTrue(n >= 0);
@SuppressWarnings("unchecked")
final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = new Pair[n + 1];
DoubleFunction1D p, dp, p1, p2;
for (int i = 0; i <= n; i++) {
if (i == 0) {
polynomials[i] = Pair.of(getOne(), getZero());
} else if (i == 1) {
final double a1 = (alpha + beta + 2) / 2;
polynomials[i] = Pair.of((DoubleFunction1D) new RealPolynomialFunction1D(new double[] {(alpha - beta) / 2, a1}), (DoubleFunction1D) new RealPolynomialFunction1D(new double[] {a1}));
} else {
final int j = i - 1;
p1 = polynomials[j].getFirst();
p2 = polynomials[j - 1].getFirst();
final DoubleFunction1D temp1 = p1.multiply(getB(alpha, beta, j));
final DoubleFunction1D temp2 = p1.multiply(getX()).multiply(getC(alpha, beta, j));
final DoubleFunction1D temp3 = p2.multiply(getD(alpha, beta, j));
p = (temp1.add(temp2).add(temp3)).divide(getA(alpha, beta, j));
dp = p.derivative();
polynomials[i] = Pair.of(p, dp);
}
}