SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.integration.univariate.riemann
Class Simpson

java.lang.Object
  extended by com.numericalmethod.suanshu.analysis.integration.univariate.riemann.Simpson
All Implemented Interfaces:
Integrator, IterativeIntegrator

public class Simpson
extends java.lang.Object
implements IterativeIntegrator

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.

This class implements Simpson's rule as a weighted average of two successive steps of the Trapezoidal rule.

See Also:

Field Summary
 int maxIterations
          the maximum number of iterations
 double precision
          the convergence threshold
 
Constructor Summary
Simpson(double precision, int maxIterations)
          Construct an integrator that uses Simpson's rule.
 
Method Summary
 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 maxIterations()
          Get the maximum number of iterations for this iterative procedure.
 double next(int iteration, UnivariateRealFunction f, double a, double b, double sum)
          Compute a refined sum for the integral.
 double precision()
          Get the convergence threshold.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxIterations

public final int maxIterations
the maximum number of iterations


precision

public final double precision
the convergence threshold

Constructor Detail

Simpson

public Simpson(double precision,
               int maxIterations)
Construct an integrator that uses Simpson's rule.

Parameters:
precision - the convergence threshold
maxIterations - the maximum number of iterations
Method Detail

integrate

public double integrate(UnivariateRealFunction f,
                        double a,
                        double b)
Description copied from interface: Integrator
Integrate function f from a to b.
 / b
 |   f(x) dx
 / a
 

Specified by:
integrate in interface Integrator
Parameters:
f - a univariate function
a - lower limit
b - upper limit
Returns:
Σ(f(x))

next

public double next(int iteration,
                   UnivariateRealFunction f,
                   double a,
                   double b,
                   double sum)
Description copied from interface: IterativeIntegrator
Compute a refined sum for the integral.

Specified by:
next in interface IterativeIntegrator
Parameters:
iteration - the index/count for the iterations; it counts from 1
f - the integrand
a - the lower limit
b - the upper limit
sum - the last sum
Returns:
a refined sum

h

public double h()
Description copied from interface: IterativeIntegrator
Get the discretization size for the current iteration.

Specified by:
h in interface IterativeIntegrator
Returns:
the discretization size

maxIterations

public int maxIterations()
Description copied from interface: IterativeIntegrator
Get 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:
maxIterations in interface IterativeIntegrator
Returns:
the maximum number of iterations

precision

public double precision()
Description copied from interface: Integrator
Get the convergence threshold. The usage depends on the specific integrator.

For example, for an IterativeIntegrator, the integral is considered converged if the relative error of two successive sums is less than the threshold.

Specified by:
precision in interface Integrator
Returns:
the precision

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.