org.apache.commons.math.analysis
Class TrapezoidIntegrator

java.lang.Object
  extended by org.apache.commons.math.analysis.UnivariateRealIntegratorImpl
      extended by org.apache.commons.math.analysis.TrapezoidIntegrator
All Implemented Interfaces:
java.io.Serializable, UnivariateRealIntegrator

public class TrapezoidIntegrator
extends UnivariateRealIntegratorImpl

Implements the Trapezoidal Rule for integration of real univariate functions. For reference, see Introduction to Numerical Analysis, ISBN 038795452X, chapter 3.

The function should be integrable.

Since:
1.2
Version:
$Revision: 620312 $ $Date: 2008-02-10 12:28:59 -0700 (Sun, 10 Feb 2008) $
See Also:
Serialized Form

Field Summary
private  double s
          intermediate result
private static long serialVersionUID
          serializable version identifier
 
Fields inherited from class org.apache.commons.math.analysis.UnivariateRealIntegratorImpl
defaultMaximalIterationCount, defaultMinimalIterationCount, defaultRelativeAccuracy, f, iterationCount, maximalIterationCount, minimalIterationCount, relativeAccuracy, result, resultComputed
 
Constructor Summary
TrapezoidIntegrator(UnivariateRealFunction f)
          Construct an integrator for the given function.
 
Method Summary
 double integrate(double min, double max)
          Integrate the function in the given interval.
(package private)  double stage(double min, double max, int n)
          Compute the n-th stage integral of trapezoid rule.
protected  void verifyIterationCount()
          Verifies that the iteration limits are valid and within the range.
 
Methods inherited from class org.apache.commons.math.analysis.UnivariateRealIntegratorImpl
clearResult, getIterationCount, getMaximalIterationCount, getMinimalIterationCount, getRelativeAccuracy, getResult, isSequence, resetMaximalIterationCount, resetMinimalIterationCount, resetRelativeAccuracy, setMaximalIterationCount, setMinimalIterationCount, setRelativeAccuracy, setResult, verifyInterval
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
serializable version identifier

See Also:
Constant Field Values

s

private double s
intermediate result

Constructor Detail

TrapezoidIntegrator

public TrapezoidIntegrator(UnivariateRealFunction f)
Construct an integrator for the given function.

Parameters:
f - function to integrate
Method Detail

stage

double stage(double min,
             double max,
             int n)
       throws FunctionEvaluationException
Compute the n-th stage integral of trapezoid rule. This function should only be called by API integrate() in the package. To save time it does not verify arguments - caller does.

The interval is divided equally into 2^n sections rather than an arbitrary m sections because this configuration can best utilize the alrealy computed values.

Parameters:
min - the lower bound for the interval
max - the upper bound for the interval
n - the stage of 1/2 refinement, n = 0 is no refinement
Returns:
the value of n-th stage integral
Throws:
FunctionEvaluationException - if an error occurs evaluating the function

integrate

public double integrate(double min,
                        double max)
                 throws MaxIterationsExceededException,
                        FunctionEvaluationException,
                        java.lang.IllegalArgumentException
Integrate the function in the given interval.

Parameters:
min - the lower bound for the interval
max - the upper bound for the interval
Returns:
the value of integral
Throws:
MaxIterationsExceededException - if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
FunctionEvaluationException - if an error occurs evaluating the function
java.lang.IllegalArgumentException - if any parameters are invalid

verifyIterationCount

protected void verifyIterationCount()
                             throws java.lang.IllegalArgumentException
Verifies that the iteration limits are valid and within the range.

Overrides:
verifyIterationCount in class UnivariateRealIntegratorImpl
Throws:
java.lang.IllegalArgumentException - if not