Example usage for org.apache.commons.math3.analysis.integration RombergIntegrator integrate

List of usage examples for org.apache.commons.math3.analysis.integration RombergIntegrator integrate

Introduction

In this page you can find the example usage for org.apache.commons.math3.analysis.integration RombergIntegrator integrate.

Prototype

public double integrate(final int maxEval, final UnivariateFunction f, final double lower, final double upper)
        throws TooManyEvaluationsException, MaxCountExceededException, MathIllegalArgumentException,
        NullArgumentException 

Source Link

Usage

From source file:org.apache.solr.client.solrj.io.eval.IntegrateEvaluator.java

@Override
public Object doWork(Object... values) throws IOException {

    if (values.length != 3) {
        throw new IOException("The integrate function requires 3 parameters");
    }//  w w w . ja  v a2s .com

    if (!(values[0] instanceof VectorFunction)) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the first value, expecting a FunctionVector",
                toExpression(constructingFactory), values[0].getClass().getSimpleName()));
    }

    VectorFunction vectorFunction = (VectorFunction) values[0];
    if (!(vectorFunction.getFunction() instanceof UnivariateFunction)) {
        throw new IOException("Cannot evaluate integral from parameter.");
    }

    Number min = null;
    Number max = null;

    if (values[1] instanceof Number) {
        min = (Number) values[1];
    } else {
        throw new IOException("The second parameter of the integrate function must be a number");
    }

    if (values[2] instanceof Number) {
        max = (Number) values[2];
    } else {
        throw new IOException("The third parameter of the integrate function must be a number");
    }

    UnivariateFunction func = (UnivariateFunction) vectorFunction.getFunction();

    RombergIntegrator rombergIntegrator = new RombergIntegrator();
    return rombergIntegrator.integrate(5000, func, min.doubleValue(), max.doubleValue());
}