org.apache.commons.math3.analysis.integration

## Class TrapezoidIntegrator

- java.lang.Object
- - org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
  - - org.apache.commons.math3.analysis.integration.TrapezoidIntegrator

All Implemented Interfaces:
  UnivariateIntegrator

    public class TrapezoidIntegrator
    extends BaseAbstractUnivariateIntegrator

Implements the Trapezoid 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:
  $Id: TrapezoidIntegrator.java 1364387 2012-07-22 18:14:11Z tn $

### Field Summary

Fields
`private double` `s` Intermediate result.
`static int` `TRAPEZOID_MAX_ITERATIONS_COUNT` Maximum number of iterations for trapezoid.

### Fields inherited from class org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator

`DEFAULT_ABSOLUTE_ACCURACY, DEFAULT_MAX_ITERATIONS_COUNT, DEFAULT_MIN_ITERATIONS_COUNT, DEFAULT_RELATIVE_ACCURACY, iterations`

### Constructor Summary

Constructors
Constructor and Description
`TrapezoidIntegrator()` Construct a trapezoid integrator with default settings.
`TrapezoidIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount)` Build a trapezoid integrator with given accuracies and iterations counts.
`TrapezoidIntegrator(int minimalIterationCount, int maximalIterationCount)` Build a trapezoid integrator with given iteration counts.

### Method Summary

Methods
`protected double` `doIntegrate()` Method for implementing actual integration algorithms in derived classes.
`(package private) double` `stage(BaseAbstractUnivariateIntegrator baseIntegrator, int n)` Compute the n-th stage integral of trapezoid rule.

### Methods inherited from class org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator

`computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getIterations, getMax, getMaximalIterationCount, getMin, getMinimalIterationCount, getRelativeAccuracy, integrate, setup`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### TRAPEZOID_MAX_ITERATIONS_COUNT

    public static final int TRAPEZOID_MAX_ITERATIONS_COUNT

Maximum number of iterations for trapezoid.

See Also:
  Constant Field Values

#### s

    private double s

Intermediate result.

### Constructor Detail

#### TrapezoidIntegrator

    public TrapezoidIntegrator(double relativeAccuracy,
                       double absoluteAccuracy,
                       int minimalIterationCount,
                       int maximalIterationCount)
                        throws NotStrictlyPositiveException,
                               NumberIsTooSmallException,
                               NumberIsTooLargeException

Build a trapezoid integrator with given accuracies and iterations counts.

Parameters:
  `relativeAccuracy` - relative accuracy of the result
  `absoluteAccuracy` - absolute accuracy of the result
  `minimalIterationCount` - minimum number of iterations
  `maximalIterationCount` - maximum number of iterations (must be less than or equal to `TRAPEZOID_MAX_ITERATIONS_COUNT`
Throws:
  `NotStrictlyPositiveException` - if minimal number of iterations is not strictly positive
  `NumberIsTooSmallException` - if maximal number of iterations is lesser than or equal to the minimal number of iterations
  `NumberIsTooLargeException` - if maximal number of iterations is greater than `TRAPEZOID_MAX_ITERATIONS_COUNT`

#### TrapezoidIntegrator

    public TrapezoidIntegrator(int minimalIterationCount,
                       int maximalIterationCount)
                        throws NotStrictlyPositiveException,
                               NumberIsTooSmallException,
                               NumberIsTooLargeException

Build a trapezoid integrator with given iteration counts.

Parameters:
  `minimalIterationCount` - minimum number of iterations
  `maximalIterationCount` - maximum number of iterations (must be less than or equal to `TRAPEZOID_MAX_ITERATIONS_COUNT`
Throws:
  `NotStrictlyPositiveException` - if minimal number of iterations is not strictly positive
  `NumberIsTooSmallException` - if maximal number of iterations is lesser than or equal to the minimal number of iterations
  `NumberIsTooLargeException` - if maximal number of iterations is greater than `TRAPEZOID_MAX_ITERATIONS_COUNT`

#### TrapezoidIntegrator

    public TrapezoidIntegrator()

Construct a trapezoid integrator with default settings. (max iteration count set to `TRAPEZOID_MAX_ITERATIONS_COUNT`)

### Method Detail

#### stage

    double stage(BaseAbstractUnivariateIntegrator baseIntegrator,
               int n)
           throws TooManyEvaluationsException

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 already computed values.

Parameters:
  `baseIntegrator` - integrator holding integration parameters
  `n` - the stage of 1/2 refinement, n = 0 is no refinement
Returns:
  the value of n-th stage integral
Throws:
  `TooManyEvaluationsException` - if the maximal number of evaluations is exceeded.

#### doIntegrate

    protected double doIntegrate()
                          throws TooManyEvaluationsException,
                                 MaxCountExceededException

Method for implementing actual integration algorithms in derived classes.

Specified by:
  `doIntegrate` in class `BaseAbstractUnivariateIntegrator`
Returns:
  the root.
Throws:
  `TooManyEvaluationsException` - if the maximal number of evaluations is exceeded.
  `MaxCountExceededException` - if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise