PolynomialFunction implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction, Serializable { public PolynomialFunction multiply(final PolynomialFunction p) { double[] newCoefficients = new double[coefficients.length + p.coefficients.length - 1]; for (int i = 0; i < newCoefficients.length; ++i) { newCoefficients[i] = 0.0; for (int j = FastMath.max(0, i + 1 - p.coefficients.length); j < FastMath.min(coefficients.length, i + 1); ++j) { newCoefficients[i] += coefficients[j] * p.coefficients[i-j]; } } return new PolynomialFunction(newCoefficients); } PolynomialFunction(double c[]); double value(double x); int degree(); double[] getCoefficients(); DerivativeStructure value(final DerivativeStructure t); PolynomialFunction add(final PolynomialFunction p); PolynomialFunction subtract(final PolynomialFunction p); PolynomialFunction negate(); PolynomialFunction multiply(final PolynomialFunction p); PolynomialFunction polynomialDerivative(); UnivariateFunction derivative(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testMultiplication() { PolynomialFunction p1 = new PolynomialFunction(new double[] { -3, 2 }); PolynomialFunction p2 = new PolynomialFunction(new double[] { 3, 2, 1 }); checkPolynomial(p1.multiply(p2), "-9 + x^2 + 2 x^3"); p1 = new PolynomialFunction(new double[] { 0, 1 }); p2 = p1; for (int i = 2; i < 10; ++i) { p2 = p2.multiply(p1); checkPolynomial(p2, "x^" + i); } }