IntegratorRepeated2D extends Integrator2D<Double, Double> { @Override public Double integrate(Function2D<Double, Double> f, Double[] lower, Double[] upper) { return _integrator1D.integrate(innerIntegral(f, lower[0], upper[0]), lower[1], upper[1]); } IntegratorRepeated2D(final Integrator1D<Double, Double> integrator1D); @Override Double integrate(Function2D<Double, Double> f, Double[] lower, Double[] upper);  }
@Test public void integrate() { Function2D<Double, Double> f = new Function2D<Double, Double>() { @Override public Double evaluate(Double x1, Double x2) { return x1 + Math.sin(x2); } }; double absTol = 1.0E-6; double relTol = 1.0E-6; int minSteps = 6; RungeKuttaIntegrator1D integrator1D = new RungeKuttaIntegrator1D(absTol, relTol, minSteps); IntegratorRepeated2D integrator2D = new IntegratorRepeated2D(integrator1D); Double[] lower; Double[] upper; double result, resultExpected; lower = new Double[] {0.0, 1.0}; upper = new Double[] {2.0, 10.0}; result = integrator2D.integrate(f, lower, upper); resultExpected = (upper[0] * upper[0] - lower[0] * lower[0]) / 2.0 * (upper[1] - lower[1]) + (upper[0] - lower[0]) * (-Math.cos(upper[1]) + Math.cos(lower[1])); assertEquals("Integration 2D - repeated 1D", resultExpected, result, 1E-8); lower = new Double[] {0.25, 5.25}; upper = new Double[] {25.25, 35.25}; result = integrator2D.integrate(f, lower, upper); resultExpected = (upper[0] * upper[0] - lower[0] * lower[0]) / 2.0 * (upper[1] - lower[1]) + (upper[0] - lower[0]) * (-Math.cos(upper[1]) + Math.cos(lower[1])); assertEquals("Integration 2D - repeated 1D", resultExpected, result, 1E-6); }