FunctionUtils { public static UnivariateFunction combine(final BivariateFunction combiner, final UnivariateFunction f, final UnivariateFunction g) { return new UnivariateFunction() { public double value(double x) { return combiner.value(f.value(x), g.value(x)); } }; } 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 public void testCombine() { BivariateFunction bi = new Add(); UnivariateFunction id = new Identity(); UnivariateFunction m = new Minus(); UnivariateFunction c = FunctionUtils.combine(bi, id, m); Assert.assertEquals(0, c.value(2.3456), EPS); bi = new Multiply(); UnivariateFunction inv = new Inverse(); c = FunctionUtils.combine(bi, id, inv); Assert.assertEquals(1, c.value(2.3456), EPS); }
@Test public void testSinc() { BivariateFunction div = new Divide(); UnivariateFunction sin = new Sin(); UnivariateFunction id = new Identity(); UnivariateFunction sinc1 = FunctionUtils.combine(div, sin, id); UnivariateFunction sinc2 = new Sinc(); for (int i = 0; i < 10; i++) { double x = FastMath.random(); Assert.assertEquals(sinc1.value(x), sinc2.value(x), EPS); } }