@Override
public Double integrate(Function<Double, Double> f, Double lower, Double upper) {
ArgChecker.notNull(lower, "lower");
ArgChecker.notNull(upper, "upper");
if (Double.isNaN(lower) || Double.isInfinite(lower) || Double.isInfinite(upper) || Double.isNaN(upper)) {
throw new IllegalArgumentException("lower or upper was NaN or Inf");
}
double h = (upper - lower) / _minSteps;
double f1, f2, f3, x;
x = lower;
f1 = f.apply(x);
if (Double.isNaN(f1) || Double.isInfinite(f1)) {
throw new IllegalArgumentException("function evaluation returned NaN or Inf");
}
double result = 0.0;
for (int i = 0; i < _minSteps; i++) {
f2 = f.apply(x + h / 2.0);
if (Double.isNaN(f2) || Double.isInfinite(f2)) {
throw new IllegalArgumentException("function evaluation returned NaN or Inf");
}
f3 = f.apply(x + h);
if (Double.isNaN(f3) || Double.isInfinite(f3)) {
throw new IllegalArgumentException("function evaluation returned NaN or Inf");
}
result += calculateRungeKuttaFourthOrder(f, x, h, f1, f2, f3);
f1 = f3;
x += h;
}
return result;
}