diff --git a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialsUtils.java b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialsUtils.java
index ce2f6ae52..6d8071bc2 100644
--- a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialsUtils.java
+++ b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialsUtils.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
import org.apache.commons.math.fraction.BigFraction;
import org.apache.commons.math.util.FastMath;
+import org.apache.commons.math.util.MathUtils;
/**
* A collection of static methods that operate on or return polynomials.
@@ -184,6 +185,61 @@ public class PolynomialsUtils {
});
}
+ /**
+ * Compute the coefficients of the polynomial Ps(x)
+ * whose values at point {@code x} will be the same as the those from the
+ * original polynomial P(x)
when computed at {@code x + shift}.
+ * Thus, if P(x) = Σi ai xi
,
+ * then
+ *
+ *
Ps(x) |
+ * = Σi bi xi | + *
+ * | = Σi ai (x + shift)i | + *
bi
of the shifted
+ * polynomial.
+ */
+ public static double[] shift(final double[] coefficients,
+ final double shift) {
+ final int dp1 = coefficients.length;
+ final double[] newCoefficients = new double[dp1];
+
+ // Pascal triangle.
+ 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) MathUtils.binomialCoefficient(i, j);
+ }
+ }
+
+ // First polynomial coefficient.
+ for (int i = 0; i < dp1; i++){
+ newCoefficients[0] += coefficients[i] * FastMath.pow(shift, i);
+ }
+
+ // Superior order.
+ 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;
+ }
+
+
/** Get the coefficients array for a given degree.
* @param degree degree of the polynomial
* @param coefficients list where the computed coefficients are stored
diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml
index a1e8e04f6..22fb79695 100644
--- a/src/site/xdoc/changes.xml
+++ b/src/site/xdoc/changes.xml
@@ -52,6 +52,11 @@ The