use of org.hipparchus.analysis.integration.SimpsonIntegrator in project symja_android_library by axkr.
the class NIntegrate method integrate.
// public final static ISymbol LegendreGauss = F
// .initFinalSymbol(Config.PARSER_USE_LOWERCASE_SYMBOLS ? "legendregauss" : "LegendreGauss");
/**
* 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();
if (!list.arg1().isSymbol()) {
// `1` is not a valid variable.
String str = IOFunctions.getMessage("ivar", F.list(list.arg1()), EvalEngine.get());
throw new ArgumentTypeException(str);
}
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 {
if (maxPoints > 1000) {
// see also https://github.com/Hipparchus-Math/hipparchus/issues/61
throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE, maxPoints, 1000);
}
// default: LegendreGauss
GaussIntegrator integ = factory.legendre(maxPoints, min, max);
return integ.integrate(f);
}
return integrator.integrate(maxIterations, f, min, max);
}
Aggregations