Top Description Fields Constructors Methods
org.apache.commons.math3.analysis.integration

public Class MidPointIntegrator

extends BaseAbstractUnivariateIntegrator
Class Inheritance
Imports
org.apache.commons.math3.exception.MathIllegalArgumentException, .MaxCountExceededException, .NotStrictlyPositiveException, .NumberIsTooLargeException, .NumberIsTooSmallException, .TooManyEvaluationsException, org.apache.commons.math3.util.FastMath

Implements the Midpoint Rule for integration of real univariate functions. For reference, see Numerical Mathematics, ISBN 0387989595, chapter 9.2.

The function should be integrable.

Since
3.3

Field Summary

Modifier and TypeField and Description
public static final int
MIDPOINT_MAX_ITERATIONS_COUNT

Maximum number of iterations for midpoint.

Inherited from org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator:
DEFAULT_ABSOLUTE_ACCURACYDEFAULT_MAX_ITERATIONS_COUNTDEFAULT_MIN_ITERATIONS_COUNTDEFAULT_RELATIVE_ACCURACYiterations

Constructor Summary

AccessConstructor and Description
public
MidPointIntegrator(final double
relative accuracy of the result
relativeAccuracy
,
final double
absolute accuracy of the result
absoluteAccuracy
,
final int
minimum number of iterations
minimalIterationCount
,
final int
maximum number of iterations (must be less than or equal to MIDPOINT_MAX_ITERATIONS_COUNT
maximalIterationCount
)

Build a midpoint integrator with given accuracies and iterations counts.

public
MidPointIntegrator(final int
minimum number of iterations
minimalIterationCount
,
final int
maximum number of iterations (must be less than or equal to MIDPOINT_MAX_ITERATIONS_COUNT
maximalIterationCount
)

Build a midpoint integrator with given iteration counts.

public
MidPointIntegrator()

Construct a midpoint integrator with default settings.

Method Summary

Modifier and TypeMethod and Description
protected double
doIntegrate()

Implements abstract org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator.doIntegrate.

Method for implementing actual integration algorithms in derived classes.

private double

Returns:

the value of n-th stage integral
stage
(final int
the stage of 1/2 refinement. Must be larger than 0.
n
,
double
Result from the previous call to the stage method.
previousStageResult
,
double
Lower bound of the integration interval.
min
,
double
Difference between the lower bound and upper bound of the integration interval.
diffMaxMin
)

Compute the n-th stage integral of midpoint rule.

Inherited from org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator:
computeObjectiveValuegetAbsoluteAccuracygetEvaluationsgetIterationsgetMaxgetMaximalIterationCountgetMingetMinimalIterationCountgetRelativeAccuracyincrementCountintegratesetup

Field Detail

MIDPOINT_MAX_ITERATIONS_COUNTback to summary
public static final int MIDPOINT_MAX_ITERATIONS_COUNT

Maximum number of iterations for midpoint.

Constructor Detail

MidPointIntegratorback to summary
public MidPointIntegrator(final double relativeAccuracy, final double absoluteAccuracy, final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException

Build a midpoint integrator with given accuracies and iterations counts.

Parameters
relativeAccuracy:double

relative accuracy of the result

absoluteAccuracy:double

absolute accuracy of the result

minimalIterationCount:int

minimum number of iterations

maximalIterationCount:int

maximum number of iterations (must be less than or equal to MIDPOINT_MAX_ITERATIONS_COUNT

Exceptions
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 MIDPOINT_MAX_ITERATIONS_COUNT
MidPointIntegratorback to summary
public MidPointIntegrator(final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException

Build a midpoint integrator with given iteration counts.

Parameters
minimalIterationCount:int

minimum number of iterations

maximalIterationCount:int

maximum number of iterations (must be less than or equal to MIDPOINT_MAX_ITERATIONS_COUNT

Exceptions
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 MIDPOINT_MAX_ITERATIONS_COUNT
MidPointIntegratorback to summary
public MidPointIntegrator()

Construct a midpoint integrator with default settings. (max iteration count set to MIDPOINT_MAX_ITERATIONS_COUNT)

Method Detail

doIntegrateback to summary
protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException

Implements abstract org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator.doIntegrate.

Doc from org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator.doIntegrate.

Method for implementing actual integration algorithms in derived classes.

Returns:double

the root.

Annotations
@Override
Exceptions
TooManyEvaluationsException:
if the maximal number of evaluations is exceeded.
MaxCountExceededException:
if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
stageback to summary
private double stage(final int n, double previousStageResult, double min, double diffMaxMin) throws TooManyEvaluationsException

Compute the n-th stage integral of midpoint 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
n:int

the stage of 1/2 refinement. Must be larger than 0.

previousStageResult:double

Result from the previous call to the stage method.

min:double

Lower bound of the integration interval.

diffMaxMin:double

Difference between the lower bound and upper bound of the integration interval.

Returns:double

the value of n-th stage integral

Exceptions
TooManyEvaluationsException:
if the maximal number of evaluations is exceeded.