public class Simpson extends Object implements IterativeIntegrator
Trapezoidal rule.
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 and Description |
|---|
Simpson(double precision,
int maxIterations)
Construct an integrator that implements Simpson's rule.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getMaxIterations()
Get the maximum number of iterations for this iterative procedure.
|
double |
getPrecision()
Get the convergence threshold.
|
double |
h()
Get the discretization size for the current iteration.
|
double |
integrate(UnivariateRealFunction f,
double a,
double b)
Integrate function f from a to b,
\[
\int_a^b\! f(x)\, dx
\]
|
double |
next(int iteration,
UnivariateRealFunction f,
double a,
double b,
double sum)
Compute a refined sum for the integral.
|
public Simpson(double precision,
int maxIterations)
precision - the convergence thresholdmaxIterations - the maximum number of iterationspublic double integrate(UnivariateRealFunction f, double a, double b)
Integratorintegrate in interface Integratorf - a univariate functiona - the lower limitb - the upper limitpublic double next(int iteration,
UnivariateRealFunction f,
double a,
double b,
double sum)
IterativeIntegratornext in interface IterativeIntegratoriteration - the index/count for the current iteration, counting from 1f - the integranda - the lower limitb - the upper limitsum - the last sumpublic double h()
IterativeIntegratorh in interface IterativeIntegratorpublic int getMaxIterations()
IterativeIntegratorgetMaxIterations in interface IterativeIntegratorpublic double getPrecision()
IntegratorIterativeIntegrator,
the integral is considered converged if the relative error of two successive sums is less than the threshold.getPrecision in interface IntegratorCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.