Search in sources :

Example 1 with RombergIntegrator

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);
}
Also used : SimpsonIntegrator(org.hipparchus.analysis.integration.SimpsonIntegrator) UnaryNumerical(org.matheclipse.core.generic.UnaryNumerical) ISymbol(org.matheclipse.core.interfaces.ISymbol) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) UnivariateIntegrator(org.hipparchus.analysis.integration.UnivariateIntegrator) RombergIntegrator(org.hipparchus.analysis.integration.RombergIntegrator) EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr) GaussIntegratorFactory(org.hipparchus.analysis.integration.gauss.GaussIntegratorFactory) TrapezoidIntegrator(org.hipparchus.analysis.integration.TrapezoidIntegrator) GaussIntegrator(org.hipparchus.analysis.integration.gauss.GaussIntegrator)

Aggregations

UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)1 RombergIntegrator (org.hipparchus.analysis.integration.RombergIntegrator)1 SimpsonIntegrator (org.hipparchus.analysis.integration.SimpsonIntegrator)1 TrapezoidIntegrator (org.hipparchus.analysis.integration.TrapezoidIntegrator)1 UnivariateIntegrator (org.hipparchus.analysis.integration.UnivariateIntegrator)1 GaussIntegrator (org.hipparchus.analysis.integration.gauss.GaussIntegrator)1 GaussIntegratorFactory (org.hipparchus.analysis.integration.gauss.GaussIntegratorFactory)1 EvalEngine (org.matheclipse.core.eval.EvalEngine)1 UnaryNumerical (org.matheclipse.core.generic.UnaryNumerical)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1