Simpson's Integrator

The net.sf.doodleproject.numerics4j.integration.SimpsonsIntegrator class provides an implementation of the extended trapezoidal rule.

Evaluating definite integrals using Simpson's rule involves creating a SimpsonsIntegrator object for a particular net.sf.doodleproject.numerics4j.function.Function object. Once, the integrator is created, definite integrals can be evaluated by calling the integrate method providing the limits of integration. Here is an example of evaluating integrals for sine:

Function sine = new Function() {
    public double evaluate(double x) {
        return Math.sin(x);
    }
};

SimpsonsIntegrator integrator = new SimpsonsIntegrator(sine);

// integrate sine from 0 to Pi.
double two = integrator.integrate(0.0, Math.PI);

// integrate sine from Pi/2 to 2 Pi.
double one = integrator.integrate(Math.PI / 2.0, Math.PI);