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

public abstract Class BaseAbstractUnivariateIntegrator

extends Object
implements UnivariateIntegrator
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.analysis.integration.UnivariateIntegrator
Known Direct Subclasses
org.apache.commons.math3.analysis.integration.IterativeLegendreGaussIntegrator, org.apache.commons.math3.analysis.integration.LegendreGaussIntegrator, org.apache.commons.math3.analysis.integration.MidPointIntegrator, org.apache.commons.math3.analysis.integration.RombergIntegrator, org.apache.commons.math3.analysis.integration.SimpsonIntegrator, org.apache.commons.math3.analysis.integration.TrapezoidIntegrator
Imports
org.apache.commons.math3.analysis.UnivariateFunction, org.apache.commons.math3.analysis.solvers.UnivariateSolverUtils, org.apache.commons.math3.exception.MathIllegalArgumentException, .MaxCountExceededException, .NotStrictlyPositiveException, .NullArgumentException, .NumberIsTooSmallException, .TooManyEvaluationsException, org.apache.commons.math3.util.IntegerSequence, .MathUtils

Provide a default implementation for several generic functions.
Since
1.2

Field Summary

Modifier and TypeField and Description
private final double
absoluteAccuracy

Maximum absolute error.

private IntegerSequence.Incrementor
count

The iteration count.

public static final double
DEFAULT_ABSOLUTE_ACCURACY

Default absolute accuracy.

public static final int
DEFAULT_MAX_ITERATIONS_COUNT

Default maximal iteration count.

public static final int
DEFAULT_MIN_ITERATIONS_COUNT

Default minimal iteration count.

public static final double
DEFAULT_RELATIVE_ACCURACY

Default relative accuracy.

private IntegerSequence.Incrementor
evaluations

The functions evaluation count.

private UnivariateFunction
function

Function to integrate.

protected Incrementor
iterations

Deprecated as of 3.6, this field has been replaced with incrementCount()
The iteration count.
private double
max

Upper bound for the interval.

private double
min

Lower bound for the interval.

private final int
minimalIterationCount

minimum number of iterations

private final double
relativeAccuracy

Maximum relative error.

Constructor Summary

AccessConstructor and Description
protected
BaseAbstractUnivariateIntegrator(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
maximalIterationCount
)

Construct an integrator with given accuracies and iteration counts.

protected
BaseAbstractUnivariateIntegrator(final double
relative accuracy of the result
relativeAccuracy
,
final double
absolute accuracy of the result
absoluteAccuracy
)

Construct an integrator with given accuracies.

protected
BaseAbstractUnivariateIntegrator(final int
minimum number of iterations
minimalIterationCount
,
final int
maximum number of iterations
maximalIterationCount
)

Construct an integrator with given iteration counts.

Method Summary

Modifier and TypeMethod and Description
protected double

Returns:

the objective function value at specified point.
computeObjectiveValue
(final double
Point at which the objective function must be evaluated.
point
)

Compute the objective function value.

protected abstract double

Returns:

the root.
doIntegrate
()

Method for implementing actual integration algorithms in derived classes.

public double
public int
getEvaluations()

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getEvaluations.

Get the number of function evaluations of the last run of the integrator.

public int
getIterations()

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getIterations.

Get the number of iterations of the last run of the integrator.

protected double

Returns:

the upper bound.
getMax
()

public int
protected double

Returns:

the lower bound.
getMin
()

public int
public double
protected void
incrementCount()

Increment the number of iterations.

public double
integrate(final int
Maximum number of evaluations.
maxEval
,
final UnivariateFunction
the integrand function
f
,
final double
the lower bound for the interval
lower
,
final double
the upper bound for the interval
upper
)

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.integrate.

Integrate the function in the given interval.

protected void
setup(final int
Maximum number of evaluations.
maxEval
,
final UnivariateFunction
the integrand function
f
,
final double
the min bound for the interval
lower
,
final double
the upper bound for the interval
upper
)

Prepare for computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

absoluteAccuracyback to summary
private final double absoluteAccuracy

Maximum absolute error.

countback to summary
private IntegerSequence.Incrementor count

The iteration count.

DEFAULT_ABSOLUTE_ACCURACYback to summary
public static final double DEFAULT_ABSOLUTE_ACCURACY

Default absolute accuracy.

DEFAULT_MAX_ITERATIONS_COUNTback to summary
public static final int DEFAULT_MAX_ITERATIONS_COUNT

Default maximal iteration count.

DEFAULT_MIN_ITERATIONS_COUNTback to summary
public static final int DEFAULT_MIN_ITERATIONS_COUNT

Default minimal iteration count.

DEFAULT_RELATIVE_ACCURACYback to summary
public static final double DEFAULT_RELATIVE_ACCURACY

Default relative accuracy.

evaluationsback to summary
private IntegerSequence.Incrementor evaluations

The functions evaluation count.

functionback to summary
private UnivariateFunction function

Function to integrate.

iterationsback to summary
protected Incrementor iterations

Deprecated

as of 3.6, this field has been replaced with incrementCount()

The iteration count.

Annotations
@Deprecated
maxback to summary
private double max

Upper bound for the interval.

minback to summary
private double min

Lower bound for the interval.

minimalIterationCountback to summary
private final int minimalIterationCount

minimum number of iterations

relativeAccuracyback to summary
private final double relativeAccuracy

Maximum relative error.

Constructor Detail

BaseAbstractUnivariateIntegratorback to summary
protected BaseAbstractUnivariateIntegrator(final double relativeAccuracy, final double absoluteAccuracy, final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException

Construct an integrator with given accuracies and iteration counts.

The meanings of the various parameters are:

  • relative accuracy: this is used to stop iterations if the absolute accuracy can't be achieved due to large values or short mantissa length. If this should be the primary criterion for convergence rather then a safety measure, set the absolute accuracy to a ridiculously small value, like Precision.SAFE_MIN.
  • absolute accuracy: The default is usually chosen so that results in the interval -10..-0.1 and +0.1..+10 can be found with a reasonable accuracy. If the expected absolute value of your results is of much smaller magnitude, set this to a smaller value.
  • minimum number of iterations: minimal iteration is needed to avoid false early convergence, e.g. the sample points happen to be zeroes of the function. Users can use the default value or choose one that they see as appropriate.
  • maximum number of iterations: usually a high iteration count indicates convergence problems. However, the "reasonable value" varies widely for different algorithms. Users are advised to use the default value supplied by the algorithm.
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

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
BaseAbstractUnivariateIntegratorback to summary
protected BaseAbstractUnivariateIntegrator(final double relativeAccuracy, final double absoluteAccuracy)

Construct an integrator with given accuracies.

Parameters
relativeAccuracy:double

relative accuracy of the result

absoluteAccuracy:double

absolute accuracy of the result

BaseAbstractUnivariateIntegratorback to summary
protected BaseAbstractUnivariateIntegrator(final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException

Construct an integrator with given iteration counts.

Parameters
minimalIterationCount:int

minimum number of iterations

maximalIterationCount:int

maximum number of iterations

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

Method Detail

computeObjectiveValueback to summary
protected double computeObjectiveValue(final double point) throws TooManyEvaluationsException

Compute the objective function value.

Parameters
point:double

Point at which the objective function must be evaluated.

Returns:double

the objective function value at specified point.

Exceptions
TooManyEvaluationsException:
if the maximal number of function evaluations is exceeded.
doIntegrateback to summary
protected abstract double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException

Method for implementing actual integration algorithms in derived classes.

Returns:double

the root.

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
getAbsoluteAccuracyback to summary
public double getAbsoluteAccuracy()

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getAbsoluteAccuracy.

Doc from org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getAbsoluteAccuracy.

Get the absolute accuracy.

Returns:double

the accuracy

getEvaluationsback to summary
public int getEvaluations()

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getEvaluations.

Doc from org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getEvaluations.

Get the number of function evaluations of the last run of the integrator.

Returns:int

number of function evaluations

getIterationsback to summary
public int getIterations()

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getIterations.

Doc from org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getIterations.

Get the number of iterations of the last run of the integrator.

Returns:int

number of iterations

getMaxback to summary
protected double getMax()
Returns:double

the upper bound.

getMaximalIterationCountback to summary
public int getMaximalIterationCount()

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getMaximalIterationCount.

Doc from org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getMaximalIterationCount.

Get the upper limit for the number of iterations.

Returns:int

the actual upper limit

getMinback to summary
protected double getMin()
Returns:double

the lower bound.

getMinimalIterationCountback to summary
public int getMinimalIterationCount()

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getMinimalIterationCount.

Doc from org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getMinimalIterationCount.

Get the min limit for the number of iterations.

Returns:int

the actual min limit

getRelativeAccuracyback to summary
public double getRelativeAccuracy()

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getRelativeAccuracy.

Doc from org.apache.commons.math3.analysis.integration.UnivariateIntegrator.getRelativeAccuracy.

Get the relative accuracy.

Returns:double

the accuracy

incrementCountback to summary
protected void incrementCount() throws MaxCountExceededException

Increment the number of iterations.

Exceptions
MaxCountExceededException:
if the number of iterations exceeds the allowed maximum number
integrateback to summary
public double integrate(final int maxEval, final UnivariateFunction f, final double lower, final double upper) throws TooManyEvaluationsException, MaxCountExceededException, MathIllegalArgumentException, NullArgumentException

Implements org.apache.commons.math3.analysis.integration.UnivariateIntegrator.integrate.

Doc from org.apache.commons.math3.analysis.integration.UnivariateIntegrator.integrate.

Integrate the function in the given interval.

Parameters
maxEval:int

Maximum number of evaluations.

f:UnivariateFunction

the integrand function

lower:double

the lower bound for the interval

upper:double

the upper bound for the interval

Returns:double

the value of integral

Exceptions
TooManyEvaluationsException:
if the maximum number of function evaluations is exceeded
MaxCountExceededException:
if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MathIllegalArgumentException:
if min > max or the endpoints do not satisfy the requirements specified by the integrator
NullArgumentException:
if f is null.
setupback to summary
protected void setup(final int maxEval, final UnivariateFunction f, final double lower, final double upper) throws NullArgumentException, MathIllegalArgumentException

Prepare for computation. Subclasses must call this method if they override any of the solve methods.

Parameters
maxEval:int

Maximum number of evaluations.

f:UnivariateFunction

the integrand function

lower:double

the min bound for the interval

upper:double

the upper bound for the interval

Exceptions
NullArgumentException:
if f is null.
MathIllegalArgumentException:
if min >= max.