The net.sf.doodleproject.numerics4j.integration.TrapezoidalIntegrator class provides an implementation of the extended trapezoidal rule.
Evaluating definite integrals using the trapezoidal rule involves
creating a TrapezoidalIntegrator 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);
}
};
TrapezoidalIntegrator integrator = new TrapezoidalIntegrator(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);