FunctionUtils { @Deprecated public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) { return new UnivariateDifferentiableFunction() { public double value(final double x) { return f.value(x); } public DerivativeStructure value(final DerivativeStructure t) throws NumberIsTooLargeException { switch (t.getOrder()) { case 0 : return new DerivativeStructure(t.getFreeParameters(), 0, f.value(t.getValue())); case 1 : { final int parameters = t.getFreeParameters(); final double[] derivatives = new double[parameters + 1]; derivatives[0] = f.value(t.getValue()); final double fPrime = f.derivative().value(t.getValue()); int[] orders = new int[parameters]; for (int i = 0; i < parameters; ++i) { orders[i] = 1; derivatives[i + 1] = fPrime * t.getPartialDerivative(orders); orders[i] = 0; } return new DerivativeStructure(parameters, 1, derivatives); } default : throw new NumberIsTooLargeException(t.getOrder(), 1, true); } } }; } private  FunctionUtils(); static UnivariateFunction compose(final UnivariateFunction ... f); static UnivariateDifferentiableFunction compose(final UnivariateDifferentiableFunction ... f); @Deprecated static DifferentiableUnivariateFunction compose(final DifferentiableUnivariateFunction ... f); static UnivariateFunction add(final UnivariateFunction ... f); static UnivariateDifferentiableFunction add(final UnivariateDifferentiableFunction ... f); @Deprecated static DifferentiableUnivariateFunction add(final DifferentiableUnivariateFunction ... f); static UnivariateFunction multiply(final UnivariateFunction ... f); static UnivariateDifferentiableFunction multiply(final UnivariateDifferentiableFunction ... f); @Deprecated static DifferentiableUnivariateFunction multiply(final DifferentiableUnivariateFunction ... f); static UnivariateFunction combine(final BivariateFunction combiner,
                                             final UnivariateFunction f,
                                             final UnivariateFunction g); static MultivariateFunction collector(final BivariateFunction combiner,
                                                 final UnivariateFunction f,
                                                 final double initialValue); static MultivariateFunction collector(final BivariateFunction combiner,
                                                 final double initialValue); static UnivariateFunction fix1stArgument(final BivariateFunction f,
                                                    final double fixed); static UnivariateFunction fix2ndArgument(final BivariateFunction f,
                                                    final double fixed); static double[] sample(UnivariateFunction f, double min, double max, int n); @Deprecated static DifferentiableUnivariateFunction toDifferentiableUnivariateFunction(final UnivariateDifferentiableFunction f); @Deprecated static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f); @Deprecated static DifferentiableMultivariateFunction toDifferentiableMultivariateFunction(final MultivariateDifferentiableFunction f); @Deprecated static MultivariateDifferentiableFunction toMultivariateDifferentiableFunction(final DifferentiableMultivariateFunction f); @Deprecated static DifferentiableMultivariateVectorFunction toDifferentiableMultivariateVectorFunction(final MultivariateDifferentiableVectorFunction f); @Deprecated static MultivariateDifferentiableVectorFunction toMultivariateDifferentiableVectorFunction(final DifferentiableMultivariateVectorFunction f);  }
@Test @Deprecated public void testToUnivariateDifferential() { Sin sin = new Sin(); UnivariateDifferentiableFunction converted = FunctionUtils.toUnivariateDifferential(sin); for (double x = 0.1; x < 0.5; x += 0.01) { DerivativeStructure t = new DerivativeStructure(2, 1, x, 1.0, 2.0); Assert.assertEquals(sin.value(t).getValue(), converted.value(t).getValue(), 1.0e-10); Assert.assertEquals(sin.value(t).getPartialDerivative(1, 0), converted.value(t).getPartialDerivative(1, 0), 1.0e-10); Assert.assertEquals(sin.value(t).getPartialDerivative(0, 1), converted.value(t).getPartialDerivative(0, 1), 1.0e-10); } }