### Question:
ParameterizedSurface extends ParameterizedFunction<DoublesPair, DoubleArray, Double> { public Function<DoublesPair, DoubleArray> getZParameterSensitivity(DoubleArray params) { return new Function<DoublesPair, DoubleArray>() { @Override public DoubleArray apply(DoublesPair xy) { Function<DoubleArray, Double> f = asFunctionOfParameters(xy); Function<DoubleArray, DoubleArray> g = FIRST_ORDER_DIFF.differentiate(f); return g.apply(params); } }; }  Function<DoublesPair, DoubleArray> getZParameterSensitivity(DoubleArray params);  }### Answer:
@Test public void test() { final ParameterizedSurface testSurface = new ParameterizedSurface() { @Override public Double evaluate(final DoublesPair xy, final DoubleArray parameters) { assertThat(3).isEqualTo(parameters.size()); final double a = parameters.get(0); final double b = parameters.get(1); final double c = parameters.get(2); return a * Math.sin(b * xy.getFirst() + c * xy.getSecond()) + Math.cos(xy.getSecond()); } @Override public int getNumberOfParameters() { return 3; } }; final ParameterizedFunction<DoublesPair, DoubleArray, DoubleArray> parmSense = new ParameterizedFunction<DoublesPair, DoubleArray, DoubleArray>() { @Override public DoubleArray evaluate(final DoublesPair xy, final DoubleArray parameters) { double a = parameters.get(0); double b = parameters.get(1); double c = parameters.get(2); DoubleArray res = DoubleArray.of( Math.sin(b * xy.getFirst() + c * xy.getSecond()), xy.getFirst() * a * Math.cos(b * xy.getFirst() + c * xy.getSecond()), xy.getSecond() * a * Math.cos(b * xy.getFirst() + c * xy.getSecond())); return res; } @Override public int getNumberOfParameters() { return 3; } }; final DoubleArray params = DoubleArray.of(0.7, -0.3, 1.2); final Function<DoublesPair, DoubleArray> paramsSenseFD = testSurface.getZParameterSensitivity(params); final Function<DoublesPair, DoubleArray> paramsSenseAnal = parmSense.asFunctionOfArguments(params); for (int i = 0; i < 20; i++) { final double x = Math.PI * (-0.5 + i / 19.); for (int j = 0; j < 20; j++) { final double y = Math.PI * (-0.5 + j / 19.); final DoublesPair xy = DoublesPair.of(x, y); final DoubleArray s1 = paramsSenseAnal.apply(xy); final DoubleArray s2 = paramsSenseFD.apply(xy); for (int k = 0; k < 3; k++) { assertThat(s1.get(k)).isCloseTo(s2.get(k), offset(1e-10)); } } } }