GaussianQuadratureIntegrator1D extends Integrator1D<Double, Double> { @Override public Double integrate(final Function1D<Double, Double> function, final Double lower, final Double upper) { Validate.notNull(function); Validate.notNull(lower); Validate.notNull(upper); final Function1D<Double, Double> integral = getIntegralFunction(function, lower, upper); return integrateFromPolyFunc(integral); } GaussianQuadratureIntegrator1D(final int n, final QuadratureWeightAndAbscissaFunction generator); @Override Double integrate(final Function1D<Double, Double> function, final Double lower, final Double upper); double integrateFromPolyFunc(final Function1D<Double, Double> polyFunction); abstract Double[] getLimits(); abstract Function1D<Double, Double> getIntegralFunction(final Function1D<Double, Double> function, final Double lower, final Double upper); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void testGaussLegendre() { double upper = 2; double lower = -6; final Integrator1D<Double, Double> integrator = new GaussLegendreQuadratureIntegrator1D(6); assertEquals(F1.evaluate(upper) - F1.evaluate(lower), integrator.integrate(DF1, lower, upper), EPS); lower = -0.56; upper = 1.4; assertEquals(F1.evaluate(upper) - F1.evaluate(lower), integrator.integrate(DF1, lower, upper), EPS); }
@Test public void testGaussLaguerre() { final double upper = Double.POSITIVE_INFINITY; final double lower = 0; final Integrator1D<Double, Double> integrator = new GaussLaguerreQuadratureIntegrator1D(15); assertEquals(0.5, integrator.integrate(DF2, lower, upper), EPS); }
@Test public void testRungeKutta() { final RungeKuttaIntegrator1D integrator = new RungeKuttaIntegrator1D(); final double lower = -1; final double upper = 2; assertEquals(F1.evaluate(upper) - F1.evaluate(lower), integrator.integrate(DF1, lower, upper), EPS); }
@Test public void testGaussJacobi() { final double upper = 12; final double lower = -1; final Integrator1D<Double, Double> integrator = new GaussJacobiQuadratureIntegrator1D(7); assertEquals(F1.evaluate(upper) - F1.evaluate(lower), integrator.integrate(DF1, lower, upper), EPS); }