Numerical Integration

numerics4j provides the means to evaluate definite integrals through the use of common numerical methods. The following routines are available for numerical integration:

Method Description
Adaptive Integrator An implementation of Adaptive Quadrature.
Romberg Integrator An implementation of Romberg integration.
Simpson's Integrator An implementation of the extended Simpson's rule.
Trapezoidal Integrator An implementation of the extended trapezoidal rule.

Adaptive Integrator

The AdaptiveIntegrator class provides an implementation of Adaptive Quadrature.

Evaluating definite integrals using adaptive quadrature involves creating a AdaptiveIntegrator instance providing a Function delegate. 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);
    }
};

AdaptiveIntegrator integrator = new AdaptiveIntegrator(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);

Romberg Integrator

The RombergIntegrator class provides an implementation of Romberg Integration.

Evaluating definite integrals using Romberg integration involves creating a RombergIntegrator instance providing a net/sf/doodleproject/numerics4j/function/Function delegate. 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);
    }
};

RombergIntegrator integrator = new RombergIntegrator(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);

Simpson's Integrator

The SimpsonsIntegrator class provides an implementation of the extended Simpson's rule.

Evaluating definite integrals using Simpson's rule involves creating a SimpsonsIntegrator instance providing a Function delegate. 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);

Trapezoidal Integrator

The TrapezoidalIntegrator class provides an implementation of the extended trapezoidal rule.

Evaluating definite integrals using the trapezoidal rule involves creating a TrapezoidalIntegrator instance providing a Function delegate. 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);