Class MidPointIntegrator
- java.lang.Object
-
- org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
-
- org.apache.commons.math3.analysis.integration.MidPointIntegrator
-
- All Implemented Interfaces:
UnivariateIntegrator
public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator
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
Fields Modifier and Type Field Description static int
MIDPOINT_MAX_ITERATIONS_COUNT
Maximum number of iterations for midpoint.-
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 Description MidPointIntegrator()
Construct a midpoint integrator with default settings.MidPointIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount)
Build a midpoint integrator with given accuracies and iterations counts.MidPointIntegrator(int minimalIterationCount, int maximalIterationCount)
Build a midpoint integrator with given iteration counts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
doIntegrate()
Method for implementing actual integration algorithms in derived classes.private double
stage(int n, double previousStageResult, double min, double diffMaxMin)
Compute the n-th stage integral of midpoint rule.-
Methods inherited from class org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getIterations, getMax, getMaximalIterationCount, getMin, getMinimalIterationCount, getRelativeAccuracy, incrementCount, integrate, setup
-
-
-
-
Field Detail
-
MIDPOINT_MAX_ITERATIONS_COUNT
public static final int MIDPOINT_MAX_ITERATIONS_COUNT
Maximum number of iterations for midpoint.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MidPointIntegrator
public MidPointIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException
Build a midpoint integrator with given accuracies and iterations counts.- Parameters:
relativeAccuracy
- relative accuracy of the resultabsoluteAccuracy
- absolute accuracy of the resultminimalIterationCount
- minimum number of iterationsmaximalIterationCount
- maximum number of iterations (must be less than or equal toMIDPOINT_MAX_ITERATIONS_COUNT
- Throws:
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positiveNumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterationsNumberIsTooLargeException
- if maximal number of iterations is greater thanMIDPOINT_MAX_ITERATIONS_COUNT
-
MidPointIntegrator
public MidPointIntegrator(int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException
Build a midpoint integrator with given iteration counts.- Parameters:
minimalIterationCount
- minimum number of iterationsmaximalIterationCount
- maximum number of iterations (must be less than or equal toMIDPOINT_MAX_ITERATIONS_COUNT
- Throws:
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positiveNumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterationsNumberIsTooLargeException
- if maximal number of iterations is greater thanMIDPOINT_MAX_ITERATIONS_COUNT
-
MidPointIntegrator
public MidPointIntegrator()
Construct a midpoint integrator with default settings. (max iteration count set toMIDPOINT_MAX_ITERATIONS_COUNT
)
-
-
Method Detail
-
stage
private double stage(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 APIintegrate()
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
- the stage of 1/2 refinement. Must be larger than 0.previousStageResult
- Result from the previous call to thestage
method.min
- Lower bound of the integration interval.diffMaxMin
- Difference between the lower bound and upper bound of the integration interval.- Returns:
- the value of n-th stage integral
- Throws:
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.
-
doIntegrate
protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException
Method for implementing actual integration algorithms in derived classes.- Specified by:
doIntegrate
in classBaseAbstractUnivariateIntegrator
- 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 otherwiseMathIllegalArgumentException
-
-