DerivativeStructure implements RealFieldElement<DerivativeStructure>, Serializable { public DerivativeStructure compose(final double ... f) throws DimensionMismatchException { if (f.length != getOrder() + 1) { throw new DimensionMismatchException(f.length, getOrder() + 1); } final DerivativeStructure result = new DerivativeStructure(compiler); compiler.compose(data, 0, f, result.data, 0); return result; } private  DerivativeStructure(final DSCompiler compiler);  DerivativeStructure(final int parameters, final int order);  DerivativeStructure(final int parameters, final int order, final double value);  DerivativeStructure(final int parameters, final int order,
                               final int index, final double value);  DerivativeStructure(final double a1, final DerivativeStructure ds1,
                               final double a2, final DerivativeStructure ds2);  DerivativeStructure(final double a1, final DerivativeStructure ds1,
                               final double a2, final DerivativeStructure ds2,
                               final double a3, final DerivativeStructure ds3);  DerivativeStructure(final double a1, final DerivativeStructure ds1,
                               final double a2, final DerivativeStructure ds2,
                               final double a3, final DerivativeStructure ds3,
                               final double a4, final DerivativeStructure ds4);  DerivativeStructure(final int parameters, final int order, final double ... derivatives); private  DerivativeStructure(final DerivativeStructure ds); int getFreeParameters(); int getOrder(); DerivativeStructure createConstant(final double c); double getReal(); double getValue(); double getPartialDerivative(final int ... orders); double[] getAllDerivatives(); DerivativeStructure add(final double a); DerivativeStructure add(final DerivativeStructure a); DerivativeStructure subtract(final double a); DerivativeStructure subtract(final DerivativeStructure a); DerivativeStructure multiply(final int n); DerivativeStructure multiply(final double a); DerivativeStructure multiply(final DerivativeStructure a); DerivativeStructure divide(final double a); DerivativeStructure divide(final DerivativeStructure a); DerivativeStructure remainder(final double a); DerivativeStructure remainder(final DerivativeStructure a); DerivativeStructure negate(); DerivativeStructure abs(); DerivativeStructure ceil(); DerivativeStructure floor(); DerivativeStructure rint(); long round(); DerivativeStructure signum(); DerivativeStructure copySign(final DerivativeStructure sign); DerivativeStructure copySign(final double sign); int getExponent(); DerivativeStructure scalb(final int n); DerivativeStructure hypot(final DerivativeStructure y); static DerivativeStructure hypot(final DerivativeStructure x, final DerivativeStructure y); DerivativeStructure compose(final double ... f); DerivativeStructure reciprocal(); DerivativeStructure sqrt(); DerivativeStructure cbrt(); DerivativeStructure rootN(final int n); Field<DerivativeStructure> getField(); static DerivativeStructure pow(final double a, final DerivativeStructure x); DerivativeStructure pow(final double p); DerivativeStructure pow(final int n); DerivativeStructure pow(final DerivativeStructure e); DerivativeStructure exp(); DerivativeStructure expm1(); DerivativeStructure log(); DerivativeStructure log1p(); DerivativeStructure log10(); DerivativeStructure cos(); DerivativeStructure sin(); DerivativeStructure tan(); DerivativeStructure acos(); DerivativeStructure asin(); DerivativeStructure atan(); DerivativeStructure atan2(final DerivativeStructure x); static DerivativeStructure atan2(final DerivativeStructure y, final DerivativeStructure x); DerivativeStructure cosh(); DerivativeStructure sinh(); DerivativeStructure tanh(); DerivativeStructure acosh(); DerivativeStructure asinh(); DerivativeStructure atanh(); DerivativeStructure toDegrees(); DerivativeStructure toRadians(); double taylor(final double ... delta); DerivativeStructure linearCombination(final DerivativeStructure[] a, final DerivativeStructure[] b); DerivativeStructure linearCombination(final double[] a, final DerivativeStructure[] b); DerivativeStructure linearCombination(final DerivativeStructure a1, final DerivativeStructure b1,
                                                 final DerivativeStructure a2, final DerivativeStructure b2); DerivativeStructure linearCombination(final double a1, final DerivativeStructure b1,
                                                 final double a2, final DerivativeStructure b2); DerivativeStructure linearCombination(final DerivativeStructure a1, final DerivativeStructure b1,
                                                 final DerivativeStructure a2, final DerivativeStructure b2,
                                                 final DerivativeStructure a3, final DerivativeStructure b3); DerivativeStructure linearCombination(final double a1, final DerivativeStructure b1,
                                                 final double a2, final DerivativeStructure b2,
                                                 final double a3, final DerivativeStructure b3); DerivativeStructure linearCombination(final DerivativeStructure a1, final DerivativeStructure b1,
                                                 final DerivativeStructure a2, final DerivativeStructure b2,
                                                 final DerivativeStructure a3, final DerivativeStructure b3,
                                                 final DerivativeStructure a4, final DerivativeStructure b4); DerivativeStructure linearCombination(final double a1, final DerivativeStructure b1,
                                                 final double a2, final DerivativeStructure b2,
                                                 final double a3, final DerivativeStructure b3,
                                                 final double a4, final DerivativeStructure b4); @Override boolean equals(Object other); @Override int hashCode();  }
@Test(expected=DimensionMismatchException.class) public void testComposeMismatchedDimensions() { new DerivativeStructure(1, 3, 0, 1.2).compose(new double[3]); }
@Test public void testCompose() { double[] epsilon = new double[] { 1.0e-20, 5.0e-14, 2.0e-13, 3.0e-13, 2.0e-13, 1.0e-20 }; PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (int maxOrder = 0; maxOrder < 6; ++maxOrder) { PolynomialFunction[] p = new PolynomialFunction[maxOrder + 1]; p[0] = poly; for (int i = 1; i <= maxOrder; ++i) { p[i] = p[i - 1].polynomialDerivative(); } for (double x = 0.1; x < 1.2; x += 0.001) { DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x); DerivativeStructure dsY1 = dsX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { dsY1 = dsY1.multiply(dsX).add(poly.getCoefficients()[i]); } double[] f = new double[maxOrder + 1]; for (int i = 0; i < f.length; ++i) { f[i] = p[i].value(x); } DerivativeStructure dsY2 = dsX.compose(f); DerivativeStructure zero = dsY1.subtract(dsY2); for (int n = 0; n <= maxOrder; ++n) { Assert.assertEquals(0.0, zero.getPartialDerivative(n), epsilon[n]); } } } }