UnivariateIntegrator integrator = new RombergIntegrator(); for (int i = 0; i < xs.length - 1; i++) { double delta = integrator.integrate(1000000, new UnivariateFunction() {
/** * Compute the area of a sine intensity by using numerical approximation. The * range for which the area is computed is defined by a lower bound of * <code>0</code> and an upper bound of <code>length</code>. * @param s The intensity function to integrate. * @param lb The lower bound of the range. * @param ub The upper bound of the range. * @return The area. */ public static double areaByIntegration(IntensityFunction s, double lb, double ub) { final UnivariateIntegrator ri = new RombergIntegrator(16, 32); final double val = ri.integrate(10000000, asUnivariateFunction(s), lb, ub); return val; }
RombergIntegrator rombergIntegrator = new RombergIntegrator(); return rombergIntegrator.integrate(5000, func, min.doubleValue(), max.doubleValue());
final UnivariateIntegrator uniIntegrator; if (integrator != null && integrator.toLowerCase().contains("romberg")) uniIntegrator = new RombergIntegrator(); else uniIntegrator = new SimpsonIntegrator();
private double integrate(String method, IAST list, IExpr function) throws ConvergenceException { ISymbol xVar = (ISymbol) list.get(1); ISignedNumber min = (ISignedNumber) list.get(2); ISignedNumber max = (ISignedNumber) list.get(3); final EvalEngine engine = EvalEngine.get(); function = F.eval(function); DifferentiableUnivariateFunction f = new UnaryNumerical(function, xVar, engine); UnivariateIntegrator integrator = new TrapezoidIntegrator(); if (method.equals("Simpson")) { integrator = new SimpsonIntegrator(); } else if (method.equals("LegendreGauss")) { integrator = new LegendreGaussIntegrator(3, BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY, BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY, BaseAbstractUnivariateIntegrator.DEFAULT_MIN_ITERATIONS_COUNT, 64); } else if (method.equals("Romberg")) { integrator = new RombergIntegrator(); } else { // default: TrapezoidIntegrator } return integrator.integrate(10000, f, min.doubleValue(), max.doubleValue()); }