Class Simpson
- java.lang.Object
-
- dev.nm.analysis.integration.univariate.riemann.newtoncotes.Simpson
-
- All Implemented Interfaces:
Integrator,IterativeIntegrator
public class Simpson extends Object implements IterativeIntegrator
Simpson's rule can be thought of as a special case of Romberg's method. It is the weighted average (or extrapolation) of two successive iterations of theTrapezoidalrule. Simpson's rule is often an accurate integration rule. Simpson's is expected to improve on the trapezoidal rule for functions which are twice continuously differentiable. However for rougher functions the trapezoidal rule is likely to be more preferable.
-
-
Constructor Summary
Constructors Constructor Description Simpson(double precision, int maxIterations)Construct an integrator that implements Simpson's rule.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaxIterations()Get the maximum number of iterations for this iterative procedure.doublegetPrecision()Get the convergence threshold.doubleh()Get the discretization size for the current iteration.doubleintegrate(UnivariateRealFunction f, double a, double b)Integrate function f from a to b, \[ \int_a^b\! f(x)\, dx \]doublenext(int iteration, UnivariateRealFunction f, double a, double b, double sum)Compute a refined sum for the integral.
-
-
-
Method Detail
-
integrate
public double integrate(UnivariateRealFunction f, double a, double b)
Description copied from interface:IntegratorIntegrate function f from a to b, \[ \int_a^b\! f(x)\, dx \]- Specified by:
integratein interfaceIntegrator- Parameters:
f- a univariate functiona- the lower limitb- the upper limit- Returns:
- \(\int_a^b\! f(x)\, dx\)
-
next
public double next(int iteration, UnivariateRealFunction f, double a, double b, double sum)Description copied from interface:IterativeIntegratorCompute a refined sum for the integral.- Specified by:
nextin interfaceIterativeIntegrator- Parameters:
iteration- the index/count for the current iteration, counting from 1f- the integranda- the lower limitb- the upper limitsum- the last sum- Returns:
- a refined sum
-
h
public double h()
Description copied from interface:IterativeIntegratorGet the discretization size for the current iteration.- Specified by:
hin interfaceIterativeIntegrator- Returns:
- the discretization size
-
getMaxIterations
public int getMaxIterations()
Description copied from interface:IterativeIntegratorGet the maximum number of iterations for this iterative procedure. For those integrals that do not converge, we need to put a bound on the number of iterations to avoid infinite looping.- Specified by:
getMaxIterationsin interfaceIterativeIntegrator- Returns:
- the maximum number of iterations
-
getPrecision
public double getPrecision()
Description copied from interface:IntegratorGet the convergence threshold. The usage depends on the specific integrator. For example, for anIterativeIntegrator, the integral is considered converged if the relative error of two successive sums is less than the threshold.- Specified by:
getPrecisionin interfaceIntegrator- Returns:
- the precision
-
-