PolynomialsUtils { public static double[] shift(final double[] coefficients, final double shift) { final int dp1 = coefficients.length; final double[] newCoefficients = new double[dp1]; final int[][] coeff = new int[dp1][dp1]; for (int i = 0; i < dp1; i++){ for(int j = 0; j <= i; j++){ coeff[i][j] = (int) CombinatoricsUtils.binomialCoefficient(i, j); } } for (int i = 0; i < dp1; i++){ newCoefficients[0] += coefficients[i] * FastMath.pow(shift, i); } final int d = dp1 - 1; for (int i = 0; i < d; i++) { for (int j = i; j < d; j++){ newCoefficients[i + 1] += coeff[j + 1][j - i] * coefficients[j + 1] * FastMath.pow(shift, j - i); } } return newCoefficients; } 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 testShift() { PolynomialFunction f1x = new PolynomialFunction(new double[] { 1, 1, 2 }); PolynomialFunction f1x1 = new PolynomialFunction(PolynomialsUtils.shift(f1x.getCoefficients(), 1)); checkPolynomial(f1x1, "4 + 5 x + 2 x^2"); PolynomialFunction f1xM1 = new PolynomialFunction(PolynomialsUtils.shift(f1x.getCoefficients(), -1)); checkPolynomial(f1xM1, "2 - 3 x + 2 x^2"); PolynomialFunction f1x3 = new PolynomialFunction(PolynomialsUtils.shift(f1x.getCoefficients(), 3)); checkPolynomial(f1x3, "22 + 13 x + 2 x^2"); PolynomialFunction f2x = new PolynomialFunction(new double[]{2, 0, 3, 8, 0, 121}); PolynomialFunction f2x1 = new PolynomialFunction(PolynomialsUtils.shift(f2x.getCoefficients(), 1)); checkPolynomial(f2x1, "134 + 635 x + 1237 x^2 + 1218 x^3 + 605 x^4 + 121 x^5"); PolynomialFunction f2x3 = new PolynomialFunction(PolynomialsUtils.shift(f2x.getCoefficients(), 3)); checkPolynomial(f2x3, "29648 + 49239 x + 32745 x^2 + 10898 x^3 + 1815 x^4 + 121 x^5"); }