use of org.hipparchus.analysis.integration.RombergIntegrator in project symja_android_library by axkr.
the class NIntegrate method integrate.
/**
* Integrate a function numerically.
*
* @param method
* the following methods are possible: LegendreGauss, Simpson,
* Romberg, Trapezoid
* @param list
* a list of the form <code>{x, lowerBound, upperBound}</code>,
* where <code>lowerBound</code> and <code>upperBound</code> are
* numbers which could be converted to a Java double value.
* @param min
* Lower bound of the integration interval.
* @param max
* Upper bound of the integration interval.
* @param function
* the function which should be integrated.
* @param maxPoints
* maximum number of points
* @param maxIterations
* maximum number of iterations
* @return
* @throws MathIllegalStateException
*/
public static double integrate(String method, IAST list, double min, double max, IExpr function, int maxPoints, int maxIterations) throws MathIllegalStateException {
GaussIntegratorFactory factory = new GaussIntegratorFactory();
ISymbol xVar = (ISymbol) list.arg1();
final EvalEngine engine = EvalEngine.get();
IExpr tempFunction = F.eval(function);
UnivariateFunction f = new UnaryNumerical(tempFunction, xVar, engine);
UnivariateIntegrator integrator;
if ("Simpson".equalsIgnoreCase(method)) {
integrator = new SimpsonIntegrator();
} else if ("Romberg".equalsIgnoreCase(method)) {
integrator = new RombergIntegrator();
} else if ("Trapezoid".equalsIgnoreCase(method)) {
integrator = new TrapezoidIntegrator();
} else {
// default: LegendreGauss
GaussIntegrator integ = factory.legendre(maxPoints, min, max);
return integ.integrate(f);
}
return integrator.integrate(maxIterations, f, min, max);
}
Aggregations