commons-math3-3.6.1-org.apache.commons.math3.analysis.integration-包下的类-中英对照文档及源码赏析
摘要:中英对照文档、源码赏析、org.apache.commons.math3.analysis.integration、UnivariateIntegrator、BaseAbstractUnivariateIntegrator、IterativeLegendreGaussIntegrator、LegendreGaussIntegrator、MidPointIntegrator、RombergIntegrator、SimpsonIntegrator、TrapezoidIntegrator
完整中文文档、中英对照文档下载请移步:commons-math3-中文文档、中英对照文档-CSDN下载
1. 开源组件说明
jar包名称:commons-math3-3.6.1.jar
Maven 依赖:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
完整中文文档、中英对照文档下载请移步:commons-math3-中文文档、中英对照文档-CSDN下载
程序包 org.apache.commons.math3.analysis.integration
单变量真正函数的数值积分(正交)算法。
See: 说明
-
接口概要 接口 说明 UnivariateIntegrator Interface for univariate real integration algorithms.
单变量真实集成算法的界面。
-
类 Summary 类 说明 BaseAbstractUnivariateIntegrator Provide a default implementation for several generic functions.
提供多个通用功能的默认实现。
IterativeLegendreGaussIntegrator This algorithm divides the integration interval into equally-sized sub-interval and on each of them performs a Legendre-Gauss quadrature.
该算法将集成间隔划分为同等大小的子间隔,并且在它们中的每一个上执行Legendre-Gause正交。
LegendreGaussIntegrator Deprecated As of 3.1 (to be removed in 4.0).
截至3.1(4.0中删除)。
MidPointIntegrator RombergIntegrator Implements the Romberg Algorithm for integration of real univariate functions.
实现romberg算法,以集成真正的单变量函数。
SimpsonIntegrator TrapezoidIntegrator
程序包 org.apache.commons.math3.analysis.integration 的说明
单变量真正函数的数值积分(正交)算法。
2. 类 org.apache.commons.math3.analysis.integration.UnivariateIntegrator
2.1. UnivariateIntegrator
中英对照文档
接口 UnivariateIntegrator
-
-
All Known Implementing Classes:
-
BaseAbstractUnivariateIntegrator,
IterativeLegendreGaussIntegrator,
LegendreGaussIntegrator,
MidPointIntegrator,
RombergIntegrator,
SimpsonIntegrator,
TrapezoidIntegrator
BaseAbstractunigariate integrator,IterativeLegendregaussIntegrator,LegendregaussIntegrator,中点煤矿,rombergintegrator,夏普锰矿,梯形融化器
public interface UnivariateIntegrator
Interface for univariate real integration algorithms.
单变量真实集成算法的界面。
-
从以下版本开始:
-
1.2
1.2
-
BaseAbstractUnivariateIntegrator,
IterativeLegendreGaussIntegrator,
LegendreGaussIntegrator,
MidPointIntegrator,
RombergIntegrator,
SimpsonIntegrator,
TrapezoidIntegrator
-
-
方法概要
Methods 限定符和类型 方法和说明 double
getAbsoluteAccuracy()
Get the absolute accuracy.
获得绝对的准确性。
int
getEvaluations()
Get the number of function evaluations of the last run of the integrator.
获取积分器最后一次运行的函数评估数。
int
getIterations()
Get the number of iterations of the last run of the integrator.
获取积分器最后一次运行的迭代次数。
int
getMaximalIterationCount()
Get the upper limit for the number of iterations.
获取迭代次数的上限。
int
getMinimalIterationCount()
Get the min limit for the number of iterations.
获取迭代次数的最小限制。
double
getRelativeAccuracy()
Get the relative accuracy.
获得相对准确性。
double
integrate(int maxEval, UnivariateFunction f, double min, double max)
Integrate the function in the given interval.
在给定间隔中集成函数。
-
-
-
方法详细说明
-
getRelativeAccuracy
double getRelativeAccuracy()
Get the relative accuracy.
获得相对准确性。
-
返回:
-
the accuracy
准确性
-
the accuracy
-
getAbsoluteAccuracy
double getAbsoluteAccuracy()
Get the absolute accuracy.
获得绝对的准确性。
-
返回:
-
the accuracy
准确性
-
the accuracy
-
getMinimalIterationCount
int getMinimalIterationCount()
Get the min limit for the number of iterations.
获取迭代次数的最小限制。
-
返回:
-
the actual min limit
实际最小限制
-
the actual min limit
-
getMaximalIterationCount
int getMaximalIterationCount()
Get the upper limit for the number of iterations.
获取迭代次数的上限。
-
返回:
-
the actual upper limit
实际上限
-
the actual upper limit
-
integrate
double integrate(int maxEval, UnivariateFunction f, double min, double max) throws TooManyEvaluationsException, MaxCountExceededException, MathIllegalArgumentException, NullArgumentException
Integrate the function in the given interval.
在给定间隔中集成函数。
-
参数:
-
maxEval
- Maximum number of evaluations.
maxeval - 最大评估数。
-
f
- the integrand function
f - Integrand功能
-
min
- the lower bound for the interval
最小 - 间隔的下限
-
max
- the upper bound for the interval
max - 间隔的上限
返回:
-
the value of integral
积分的价值
抛出:
-
TooManyEvaluationsException
- if the maximum number of function evaluations is exceeded
toomanyevaliveSexception - 如果超过了最大函数评估数
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
MathIllegalArgumentException
- ifmin > max
or the endpoints do not satisfy the requirements specified by the integrator
MathilleGalargumentException - 如果min> max或端点不满足积分器指定的要求
-
NullArgumentException
- iff
isnull
.
nullargumentException - 如果f为null。
-
-
getEvaluations
int getEvaluations()
Get the number of function evaluations of the last run of the integrator.
获取积分器最后一次运行的函数评估数。
-
返回:
-
number of function evaluations
功能评估数量
-
number of function evaluations
-
getIterations
int getIterations()
Get the number of iterations of the last run of the integrator.
获取积分器最后一次运行的迭代次数。
-
返回:
-
number of iterations
迭代次数
-
number of iterations
-
-
2.2. UnivariateIntegrator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.integration;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
/**
* Interface for univariate real integration algorithms.
*
* @since 1.2
*/
public interface UnivariateIntegrator {
/**
* Get the relative accuracy.
*
* @return the accuracy
*/
double getRelativeAccuracy();
/**
* Get the absolute accuracy.
*
* @return the accuracy
*/
double getAbsoluteAccuracy();
/**
* Get the min limit for the number of iterations.
*
* @return the actual min limit
*/
int getMinimalIterationCount();
/**
* Get the upper limit for the number of iterations.
*
* @return the actual upper limit
*/
int getMaximalIterationCount();
/**
* Integrate the function in the given interval.
*
* @param maxEval Maximum number of evaluations.
* @param f the integrand function
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @return the value of integral
* @throws TooManyEvaluationsException if the maximum number of function
* evaluations is exceeded
* @throws MaxCountExceededException if the maximum iteration count is exceeded
* or the integrator detects convergence problems otherwise
* @throws MathIllegalArgumentException if {@code min > max} or the endpoints do not
* satisfy the requirements specified by the integrator
* @throws NullArgumentException if {@code f} is {@code null}.
*/
double integrate(int maxEval, UnivariateFunction f, double min,
double max)
throws TooManyEvaluationsException, MaxCountExceededException,
MathIllegalArgumentException, NullArgumentException;
/**
* Get the number of function evaluations of the last run of the integrator.
*
* @return number of function evaluations
*/
int getEvaluations();
/**
* Get the number of iterations of the last run of the integrator.
*
* @return number of iterations
*/
int getIterations();
}
3. 类 org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
3.1. BaseAbstractUnivariateIntegrator
中英对照文档
类 BaseAbstractUnivariateIntegrator
- java.lang.Object
-
- org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
-
-
All Implemented Interfaces:
-
UnivariateIntegrator
单抗体钢结构
-
Direct Known Subclasses:
-
IterativeLegendreGaussIntegrator,
LegendreGaussIntegrator,
MidPointIntegrator,
RombergIntegrator,
SimpsonIntegrator,
TrapezoidIntegrator
IterativeLegendregaussIntegrator,LegendregaussIntegrator,中点煤矿,rombergintegrator,夏天素融化器,梯形钢组
public abstract class BaseAbstractUnivariateIntegrator extends Object implements UnivariateIntegrator
Provide a default implementation for several generic functions.
提供多个通用功能的默认实现。
-
从以下版本开始:
-
1.2
1.2
-
UnivariateIntegrator
-
-
字段概要
字段 限定符和类型 Field and 的说明 static double
DEFAULT_ABSOLUTE_ACCURACY
Default absolute accuracy.
默认绝对准确性。
static int
DEFAULT_MAX_ITERATIONS_COUNT
Default maximal iteration count.
默认最大迭代计数。
static int
DEFAULT_MIN_ITERATIONS_COUNT
Default minimal iteration count.
默认最小迭代计数。
static double
DEFAULT_RELATIVE_ACCURACY
Default relative accuracy.
默认的相对准确性。
protected Incrementor
iterations
Deprecated.as of 3.6, this field has been replaced withincrementCount()
截至3.6,此字段已被替换为incrementCount()
弃用。截至3.6,此字段已被替换为incrementCount()
-
构造器概要
构造器 Modifier 构造器和说明 protected
BaseAbstractUnivariateIntegrator(double relativeAccuracy, double absoluteAccuracy)
Construct an integrator with given accuracies.
构建具有给定精度的积分器。
protected
BaseAbstractUnivariateIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount)
Construct an integrator with given accuracies and iteration counts.
构建具有给定精度和迭代计数的集成器。
protected
BaseAbstractUnivariateIntegrator(int minimalIterationCount, int maximalIterationCount)
Construct an integrator with given iteration counts.
构建具有给定迭代计数的集成器。
-
方法概要
Methods 限定符和类型 方法和说明 protected double
computeObjectiveValue(double point)
Compute the objective function value.
计算目标函数值。
protected abstract double
doIntegrate()
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
double
getAbsoluteAccuracy()
Get the absolute accuracy.
获得绝对的准确性。
int
getEvaluations()
Get the number of function evaluations of the last run of the integrator.
获取积分器最后一次运行的函数评估数。
int
getIterations()
Get the number of iterations of the last run of the integrator.
获取积分器最后一次运行的迭代次数。
protected double
getMax()
int
getMaximalIterationCount()
Get the upper limit for the number of iterations.
获取迭代次数的上限。
protected double
getMin()
int
getMinimalIterationCount()
Get the min limit for the number of iterations.
获取迭代次数的最小限制。
double
getRelativeAccuracy()
Get the relative accuracy.
获得相对准确性。
protected void
incrementCount()
Increment the number of iterations.
递增迭代次数。
double
integrate(int maxEval, UnivariateFunction f, double lower, double upper)
Integrate the function in the given interval.
在给定间隔中集成函数。
protected void
setup(int maxEval, UnivariateFunction f, double lower, double upper)
Prepare for computation.
准备计算。
-
-
-
字段详情:
-
DEFAULT_ABSOLUTE_ACCURACY
public static final double DEFAULT_ABSOLUTE_ACCURACY
Default absolute accuracy.
默认绝对准确性。
-
另请参阅:
-
Constant Field Values
恒定字段值
-
Constant Field Values
-
DEFAULT_RELATIVE_ACCURACY
public static final double DEFAULT_RELATIVE_ACCURACY
Default relative accuracy.
默认的相对准确性。
-
另请参阅:
-
Constant Field Values
恒定字段值
-
Constant Field Values
-
DEFAULT_MIN_ITERATIONS_COUNT
public static final int DEFAULT_MIN_ITERATIONS_COUNT
Default minimal iteration count.
默认最小迭代计数。
-
另请参阅:
-
Constant Field Values
恒定字段值
-
Constant Field Values
-
DEFAULT_MAX_ITERATIONS_COUNT
public static final int DEFAULT_MAX_ITERATIONS_COUNT
Default maximal iteration count.
默认最大迭代计数。
-
另请参阅:
-
Constant Field Values
恒定字段值
-
Constant Field Values
-
iterations
@Deprecated protected Incrementor iterations
Deprecated. as of 3.6, this field has been replaced withincrementCount()
弃用。截至3.6,此字段已被替换为incrementCount()
The iteration count.
迭代计数。
-
-
构造器详细说明
-
BaseAbstractUnivariateIntegrator
protected BaseAbstractUnivariateIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, 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.
构建具有给定精度和迭代计数的集成器。各种参数的含义是:相对精度:如果由于大值或短的尾数长度无法实现绝对精度,则使用该方法来停止迭代。如果这应该是收敛的主要标准,而是安全措施,则将绝对精度设置为易易上小的值,如precision.safe_min。绝对精度:通常选择默认值,以便在间隔-10 ..- 0.1和+0.1。+ 10可以以合理的准确度找到。如果结果的预期绝对值具有更小的幅度,请将其设置为较小的值。最小迭代次数:需要最小的迭代以避免假早期收敛,例如,采样点恰好是该功能的零。用户可以使用默认值或选择它们适当地看到的值。最大迭代次数:通常高迭代计数表示收敛问题。然而,“合理的值”因不同的算法而异。建议用户使用算法提供的默认值。
-
参数:
-
relativeAccuracy
- relative accuracy of the result
相对准确性 - 结果的相对准确性
-
absoluteAccuracy
- absolute accuracy of the result
绝对精度 - 结果绝对准确性
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations
maximalimerationcount - 最大迭代次数
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
- 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
-
BaseAbstractUnivariateIntegrator
protected BaseAbstractUnivariateIntegrator(double relativeAccuracy, double absoluteAccuracy)
Construct an integrator with given accuracies.
构建具有给定精度的积分器。
-
参数:
-
relativeAccuracy
- relative accuracy of the result
相对准确性 - 结果的相对准确性
-
absoluteAccuracy
- absolute accuracy of the result
绝对精度 - 结果绝对准确性
-
-
BaseAbstractUnivariateIntegrator
protected BaseAbstractUnivariateIntegrator(int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException
Construct an integrator with given iteration counts.
构建具有给定迭代计数的集成器。
-
参数:
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations
maximalimerationcount - 最大迭代次数
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
-
-
方法详细说明
-
getRelativeAccuracy
public double getRelativeAccuracy()
Get the relative accuracy.
获得相对准确性。
-
指定者:
-
getRelativeAccuracy
in interfaceUnivariateIntegrator
界面非变量钢结构中的GetrelativeAccuracy
返回:
-
the accuracy
准确性
-
-
getAbsoluteAccuracy
public double getAbsoluteAccuracy()
Get the absolute accuracy.
获得绝对的准确性。
-
指定者:
-
getAbsoluteAccuracy
in interfaceUnivariateIntegrator
在界面单变量钢结构中的GetAbsoluteAccuracy
返回:
-
the accuracy
准确性
-
-
getMinimalIterationCount
public int getMinimalIterationCount()
Get the min limit for the number of iterations.
获取迭代次数的最小限制。
-
指定者:
-
getMinimalIterationCount
in interfaceUnivariateIntegrator
interfaceunimalierationcount在一个单变量钢结构中
返回:
-
the actual min limit
实际最小限制
-
-
getMaximalIterationCount
public int getMaximalIterationCount()
Get the upper limit for the number of iterations.
获取迭代次数的上限。
-
指定者:
-
getMaximalIterationCount
in interfaceUnivariateIntegrator
interfaceunigatiate inegrator中的getMaximalItrationCount
返回:
-
the actual upper limit
实际上限
-
-
getEvaluations
public int getEvaluations()
Get the number of function evaluations of the last run of the integrator.
获取积分器最后一次运行的函数评估数。
-
指定者:
-
getEvaluations
in interfaceUnivariateIntegrator
界面非变量钢结构中的GeteValuation
返回:
-
number of function evaluations
功能评估数量
-
-
getIterations
public int getIterations()
Get the number of iterations of the last run of the integrator.
获取积分器最后一次运行的迭代次数。
-
指定者:
-
getIterations
in interfaceUnivariateIntegrator
界面单因素钢结构中的getTeration
返回:
-
number of iterations
迭代次数
-
-
incrementCount
protected void incrementCount() throws MaxCountExceededException
Increment the number of iterations.
递增迭代次数。
-
抛出:
-
MaxCountExceededException
- if the number of iterations exceeds the allowed maximum number
MaxCountExceedEdException - 如果迭代次数超过允许的最大数量
-
-
getMin
protected double getMin()
-
返回:
-
the lower bound.
下限。
-
the lower bound.
-
getMax
protected double getMax()
-
返回:
-
the upper bound.
上限。
-
the upper bound.
-
computeObjectiveValue
protected double computeObjectiveValue(double point) throws TooManyEvaluationsException
Compute the objective function value.
计算目标函数值。
-
参数:
-
point
- Point at which the objective function must be evaluated.
要评估目标函数的点点。
返回:
-
the objective function value at specified point.
指定点的目标函数值。
抛出:
-
TooManyEvaluationsException
- if the maximal number of function evaluations is exceeded.
toomanyevalionsexception - 如果超出了函数评估的最大数量。
-
-
setup
protected void setup(int maxEval, UnivariateFunction f, double lower, double upper) throws NullArgumentException, MathIllegalArgumentException
Prepare for computation. Subclasses must call this method if they override any of thesolve
methods.
准备计算。如果覆盖任何求解方法,则子类必须调用此方法。
-
参数:
-
maxEval
- Maximum number of evaluations.
maxeval - 最大评估数。
-
f
- the integrand function
f - Integrand功能
-
lower
- the min bound for the interval
降低 - 间隔的最小限制
-
upper
- the upper bound for the interval
上限 - 间隔的上限
抛出:
-
NullArgumentException
- iff
isnull
.
nullargumentException - 如果f为null。
-
MathIllegalArgumentException
- ifmin >= max
.
MathilleGalargumentException - 如果min> = max。
-
-
integrate
public double integrate(int maxEval, UnivariateFunction f, double lower, double upper) throws TooManyEvaluationsException, MaxCountExceededException, MathIllegalArgumentException, NullArgumentException
Integrate the function in the given interval.
在给定间隔中集成函数。
-
指定者:
-
integrate
in interfaceUnivariateIntegrator
集成在UnivariateIngator的界面中
参数:
-
maxEval
- Maximum number of evaluations.
maxeval - 最大评估数。
-
f
- the integrand function
f - Integrand功能
-
lower
- the lower bound for the interval
较低 - 间隔的下限
-
upper
- the upper bound for the interval
上限 - 间隔的上限
返回:
-
the value of integral
积分的价值
抛出:
-
TooManyEvaluationsException
- if the maximum number of function evaluations is exceeded
toomanyevaliveSexception - 如果超过了最大函数评估数
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
MathIllegalArgumentException
- ifmin > max
or the endpoints do not satisfy the requirements specified by the integrator
MathilleGalargumentException - 如果min> max或端点不满足积分器指定的要求
-
NullArgumentException
- iff
isnull
.
nullargumentException - 如果f为null。
-
-
doIntegrate
protected abstract double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
返回:
-
the root.
根。
抛出:
-
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.
toomanyevalionsexception - 如果超出了最大数量的评估。
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
the root.
-
-
3.2. BaseAbstractUnivariateIntegrator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.integration;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.solvers.UnivariateSolverUtils;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.util.IntegerSequence;
import org.apache.commons.math3.util.MathUtils;
/**
* Provide a default implementation for several generic functions.
*
* @since 1.2
*/
public abstract class BaseAbstractUnivariateIntegrator implements UnivariateIntegrator {
/** Default absolute accuracy. */
public static final double DEFAULT_ABSOLUTE_ACCURACY = 1.0e-15;
/** Default relative accuracy. */
public static final double DEFAULT_RELATIVE_ACCURACY = 1.0e-6;
/** Default minimal iteration count. */
public static final int DEFAULT_MIN_ITERATIONS_COUNT = 3;
/** Default maximal iteration count. */
public static final int DEFAULT_MAX_ITERATIONS_COUNT = Integer.MAX_VALUE;
/** The iteration count.
* @deprecated as of 3.6, this field has been replaced with {@link #incrementCount()}
*/
@Deprecated
protected org.apache.commons.math3.util.Incrementor iterations;
/** The iteration count. */
private IntegerSequence.Incrementor count;
/** Maximum absolute error. */
private final double absoluteAccuracy;
/** Maximum relative error. */
private final double relativeAccuracy;
/** minimum number of iterations */
private final int minimalIterationCount;
/** The functions evaluation count. */
private IntegerSequence.Incrementor evaluations;
/** Function to integrate. */
private UnivariateFunction function;
/** Lower bound for the interval. */
private double min;
/** Upper bound for the interval. */
private double max;
/**
* Construct an integrator with given accuracies and iteration counts.
* <p>
* The meanings of the various parameters are:
* <ul>
* <li>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 {@link org.apache.commons.math3.util.Precision#SAFE_MIN Precision.SAFE_MIN}.</li>
* <li>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.</li>
* <li>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.</li>
* <li>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.</li>
* </ul>
*
* @param relativeAccuracy relative accuracy of the result
* @param absoluteAccuracy absolute accuracy of the result
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
*/
protected BaseAbstractUnivariateIntegrator(final double relativeAccuracy,
final double absoluteAccuracy,
final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException {
// accuracy settings
this.relativeAccuracy = relativeAccuracy;
this.absoluteAccuracy = absoluteAccuracy;
// iterations count settings
if (minimalIterationCount <= 0) {
throw new NotStrictlyPositiveException(minimalIterationCount);
}
if (maximalIterationCount <= minimalIterationCount) {
throw new NumberIsTooSmallException(maximalIterationCount, minimalIterationCount, false);
}
this.minimalIterationCount = minimalIterationCount;
this.count = IntegerSequence.Incrementor.create().withMaximalCount(maximalIterationCount);
@SuppressWarnings("deprecation")
org.apache.commons.math3.util.Incrementor wrapped =
org.apache.commons.math3.util.Incrementor.wrap(count);
this.iterations = wrapped;
// prepare evaluations counter, but do not set it yet
evaluations = IntegerSequence.Incrementor.create();
}
/**
* Construct an integrator with given accuracies.
* @param relativeAccuracy relative accuracy of the result
* @param absoluteAccuracy absolute accuracy of the result
*/
protected BaseAbstractUnivariateIntegrator(final double relativeAccuracy,
final double absoluteAccuracy) {
this(relativeAccuracy, absoluteAccuracy,
DEFAULT_MIN_ITERATIONS_COUNT, DEFAULT_MAX_ITERATIONS_COUNT);
}
/**
* Construct an integrator with given iteration counts.
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
*/
protected BaseAbstractUnivariateIntegrator(final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException {
this(DEFAULT_RELATIVE_ACCURACY, DEFAULT_ABSOLUTE_ACCURACY,
minimalIterationCount, maximalIterationCount);
}
/** {@inheritDoc} */
public double getRelativeAccuracy() {
return relativeAccuracy;
}
/** {@inheritDoc} */
public double getAbsoluteAccuracy() {
return absoluteAccuracy;
}
/** {@inheritDoc} */
public int getMinimalIterationCount() {
return minimalIterationCount;
}
/** {@inheritDoc} */
public int getMaximalIterationCount() {
return count.getMaximalCount();
}
/** {@inheritDoc} */
public int getEvaluations() {
return evaluations.getCount();
}
/** {@inheritDoc} */
public int getIterations() {
return count.getCount();
}
/** Increment the number of iterations.
* @exception MaxCountExceededException if the number of iterations
* exceeds the allowed maximum number
*/
protected void incrementCount() throws MaxCountExceededException {
count.increment();
}
/**
* @return the lower bound.
*/
protected double getMin() {
return min;
}
/**
* @return the upper bound.
*/
protected double getMax() {
return max;
}
/**
* Compute the objective function value.
*
* @param point Point at which the objective function must be evaluated.
* @return the objective function value at specified point.
* @throws TooManyEvaluationsException if the maximal number of function
* evaluations is exceeded.
*/
protected double computeObjectiveValue(final double point)
throws TooManyEvaluationsException {
try {
evaluations.increment();
} catch (MaxCountExceededException e) {
throw new TooManyEvaluationsException(e.getMax());
}
return function.value(point);
}
/**
* Prepare for computation.
* Subclasses must call this method if they override any of the
* {@code solve} methods.
*
* @param maxEval Maximum number of evaluations.
* @param f the integrand function
* @param lower the min bound for the interval
* @param upper the upper bound for the interval
* @throws NullArgumentException if {@code f} is {@code null}.
* @throws MathIllegalArgumentException if {@code min >= max}.
*/
protected void setup(final int maxEval,
final UnivariateFunction f,
final double lower, final double upper)
throws NullArgumentException, MathIllegalArgumentException {
// Checks.
MathUtils.checkNotNull(f);
UnivariateSolverUtils.verifyInterval(lower, upper);
// Reset.
min = lower;
max = upper;
function = f;
evaluations = evaluations.withMaximalCount(maxEval).withStart(0);
count = count.withStart(0);
}
/** {@inheritDoc} */
public double integrate(final int maxEval, final UnivariateFunction f,
final double lower, final double upper)
throws TooManyEvaluationsException, MaxCountExceededException,
MathIllegalArgumentException, NullArgumentException {
// Initialization.
setup(maxEval, f, lower, upper);
// Perform computation.
return doIntegrate();
}
/**
* Method for implementing actual integration algorithms in derived
* classes.
*
* @return the root.
* @throws TooManyEvaluationsException if the maximal number of evaluations
* is exceeded.
* @throws MaxCountExceededException if the maximum iteration count is exceeded
* or the integrator detects convergence problems otherwise
*/
protected abstract double doIntegrate()
throws TooManyEvaluationsException, MaxCountExceededException;
}
4. 类 org.apache.commons.math3.analysis.integration.IterativeLegendreGaussIntegrator
4.1. IterativeLegendreGaussIntegrator
中英对照文档
类 IterativeLegendreGaussIntegrator
- java.lang.Object
-
- org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
-
- org.apache.commons.math3.analysis.integration.IterativeLegendreGaussIntegrator
-
-
All Implemented Interfaces:
-
UnivariateIntegrator
单抗体钢结构
public class IterativeLegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator
This algorithm divides the integration interval into equally-sized sub-interval and on each of them performs a Legendre-Gauss quadrature. Because of its non-adaptive nature, this algorithm can converge to a wrong value for the integral (for example, if the function is significantly different from zero toward the ends of the integration interval). In particular, a change of variables aimed at estimating integrals over infinite intervals as proposed here should be avoided when using this class.
该算法将集成间隔划分为同等大小的子间隔,并且在它们中的每一个上执行Legendre-Gause正交。由于其非自适应性,该算法可以收敛到积分的错误值(例如,如果该功能与集成间隔的结束有显着不同)。特别地,在使用此类时,应避免旨在估计估计无限间隔积分的变量。
-
从以下版本开始:
-
3.1
3.1
-
UnivariateIntegrator
-
-
字段概要
-
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
-
-
构造器概要
构造器 构造器和说明 IterativeLegendreGaussIntegrator(int n, double relativeAccuracy, double absoluteAccuracy)
Builds an integrator with given accuracies.
构建具有给定精度的集成商。
IterativeLegendreGaussIntegrator(int n, double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount)
Builds an integrator with given accuracies and iterations counts.
构建具有给定精度和迭代计数的集成商。
IterativeLegendreGaussIntegrator(int n, int minimalIterationCount, int maximalIterationCount)
Builds an integrator with given iteration counts.
构建具有给定迭代计数的集成商。
-
方法概要
Methods 限定符和类型 方法和说明 protected double
doIntegrate()
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
从类继承的方法 org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getIterations, getMax, getMaximalIterationCount, getMin, getMinimalIterationCount, getRelativeAccuracy, incrementCount, integrate, setup
-
-
-
-
构造器详细说明
-
IterativeLegendreGaussIntegrator
public IterativeLegendreGaussIntegrator(int n, double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException
Builds an integrator with given accuracies and iterations counts.
构建具有给定精度和迭代计数的集成商。
-
参数:
-
n
- Number of integration points.
n - 集成点数。
-
relativeAccuracy
- Relative accuracy of the result.
相对准确性 - 结果的相对准确性。
-
absoluteAccuracy
- Absolute accuracy of the result.
绝对准确性 - 结果绝对精度。
-
minimalIterationCount
- Minimum number of iterations.
minimaliantationcount - 最小迭代次数。
-
maximalIterationCount
- Maximum number of iterations.
maximalimerationcount - 最大迭代次数。
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations or number of points are not strictly positive.
NOTSTRICLYPositiveException - 如果最小的迭代数或点数并不严格为正。
-
NumberIsTooSmallException
- if maximal number of iterations is smaller than or equal to the minimal number of iterations.
numberistoosmallexception - 如果最大次数的迭代次数小于或等于最小的迭代次数。
-
-
IterativeLegendreGaussIntegrator
public IterativeLegendreGaussIntegrator(int n, double relativeAccuracy, double absoluteAccuracy) throws NotStrictlyPositiveException
Builds an integrator with given accuracies.
构建具有给定精度的集成商。
-
参数:
-
n
- Number of integration points.
n - 集成点数。
-
relativeAccuracy
- Relative accuracy of the result.
相对准确性 - 结果的相对准确性。
-
absoluteAccuracy
- Absolute accuracy of the result.
绝对准确性 - 结果绝对精度。
抛出:
-
NotStrictlyPositiveException
- ifn < 1
.
notstrictypositiveexception - 如果n <1。
-
-
IterativeLegendreGaussIntegrator
public IterativeLegendreGaussIntegrator(int n, int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException
Builds an integrator with given iteration counts.
构建具有给定迭代计数的集成商。
-
参数:
-
n
- Number of integration points.
n - 集成点数。
-
minimalIterationCount
- Minimum number of iterations.
minimaliantationcount - 最小迭代次数。
-
maximalIterationCount
- Maximum number of iterations.
maximalimerationcount - 最大迭代次数。
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive.
NOTSTRICLYPositiveException - 如果最小的迭代次数并不严格积极。
-
NumberIsTooSmallException
- if maximal number of iterations is smaller than or equal to the minimal number of iterations.
numberistoosmallexception - 如果最大次数的迭代次数小于或等于最小的迭代次数。
-
NotStrictlyPositiveException
- ifn < 1
.
notstrictypositiveexception - 如果n <1。
-
-
-
方法详细说明
-
doIntegrate
protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
指定者:
-
doIntegrate
in classBaseAbstractUnivariateIntegrator
在课堂Baseabstractunigariation integrator中进行了致力于
返回:
-
the root.
根。
抛出:
-
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.
toomanyevalionsexception - 如果超出了最大数量的评估。
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
MathIllegalArgumentException
MathilleGalargumentException.
-
-
-
4.2. IterativeLegendreGaussIntegrator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.integration;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.integration.gauss.GaussIntegratorFactory;
import org.apache.commons.math3.analysis.integration.gauss.GaussIntegrator;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.exception.util.LocalizedFormats;
import org.apache.commons.math3.util.FastMath;
/**
* This algorithm divides the integration interval into equally-sized
* sub-interval and on each of them performs a
* <a href="http://mathworld.wolfram.com/Legendre-GaussQuadrature.html">
* Legendre-Gauss</a> quadrature.
* Because of its <em>non-adaptive</em> nature, this algorithm can
* converge to a wrong value for the integral (for example, if the
* function is significantly different from zero toward the ends of the
* integration interval).
* In particular, a change of variables aimed at estimating integrals
* over infinite intervals as proposed
* <a href="http://en.wikipedia.org/w/index.php?title=Numerical_integration#Integrals_over_infinite_intervals">
* here</a> should be avoided when using this class.
*
* @since 3.1
*/
public class IterativeLegendreGaussIntegrator
extends BaseAbstractUnivariateIntegrator {
/** Factory that computes the points and weights. */
private static final GaussIntegratorFactory FACTORY
= new GaussIntegratorFactory();
/** Number of integration points (per interval). */
private final int numberOfPoints;
/**
* Builds an integrator with given accuracies and iterations counts.
*
* @param n Number of integration points.
* @param relativeAccuracy Relative accuracy of the result.
* @param absoluteAccuracy Absolute accuracy of the result.
* @param minimalIterationCount Minimum number of iterations.
* @param maximalIterationCount Maximum number of iterations.
* @throws NotStrictlyPositiveException if minimal number of iterations
* or number of points are not strictly positive.
* @throws NumberIsTooSmallException if maximal number of iterations
* is smaller than or equal to the minimal number of iterations.
*/
public IterativeLegendreGaussIntegrator(final int n,
final double relativeAccuracy,
final double absoluteAccuracy,
final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException {
super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount);
if (n <= 0) {
throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS, n);
}
numberOfPoints = n;
}
/**
* Builds an integrator with given accuracies.
*
* @param n Number of integration points.
* @param relativeAccuracy Relative accuracy of the result.
* @param absoluteAccuracy Absolute accuracy of the result.
* @throws NotStrictlyPositiveException if {@code n < 1}.
*/
public IterativeLegendreGaussIntegrator(final int n,
final double relativeAccuracy,
final double absoluteAccuracy)
throws NotStrictlyPositiveException {
this(n, relativeAccuracy, absoluteAccuracy,
DEFAULT_MIN_ITERATIONS_COUNT, DEFAULT_MAX_ITERATIONS_COUNT);
}
/**
* Builds an integrator with given iteration counts.
*
* @param n Number of integration points.
* @param minimalIterationCount Minimum number of iterations.
* @param maximalIterationCount Maximum number of iterations.
* @throws NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive.
* @throws NumberIsTooSmallException if maximal number of iterations
* is smaller than or equal to the minimal number of iterations.
* @throws NotStrictlyPositiveException if {@code n < 1}.
*/
public IterativeLegendreGaussIntegrator(final int n,
final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException {
this(n, DEFAULT_RELATIVE_ACCURACY, DEFAULT_ABSOLUTE_ACCURACY,
minimalIterationCount, maximalIterationCount);
}
/** {@inheritDoc} */
@Override
protected double doIntegrate()
throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {
// Compute first estimate with a single step.
double oldt = stage(1);
int n = 2;
while (true) {
// Improve integral with a larger number of steps.
final double t = stage(n);
// Estimate the error.
final double delta = FastMath.abs(t - oldt);
final double limit =
FastMath.max(getAbsoluteAccuracy(),
getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5);
// check convergence
if (getIterations() + 1 >= getMinimalIterationCount() &&
delta <= limit) {
return t;
}
// Prepare next iteration.
final double ratio = FastMath.min(4, FastMath.pow(delta / limit, 0.5 / numberOfPoints));
n = FastMath.max((int) (ratio * n), n + 1);
oldt = t;
incrementCount();
}
}
/**
* Compute the n-th stage integral.
*
* @param n Number of steps.
* @return the value of n-th stage integral.
* @throws TooManyEvaluationsException if the maximum number of evaluations
* is exceeded.
*/
private double stage(final int n)
throws TooManyEvaluationsException {
// Function to be integrated is stored in the base class.
final UnivariateFunction f = new UnivariateFunction() {
/** {@inheritDoc} */
public double value(double x)
throws MathIllegalArgumentException, TooManyEvaluationsException {
return computeObjectiveValue(x);
}
};
final double min = getMin();
final double max = getMax();
final double step = (max - min) / n;
double sum = 0;
for (int i = 0; i < n; i++) {
// Integrate over each sub-interval [a, b].
final double a = min + i * step;
final double b = a + step;
final GaussIntegrator g = FACTORY.legendreHighPrecision(numberOfPoints, a, b);
sum += g.integrate(f);
}
return sum;
}
}
5. 类 org.apache.commons.math3.analysis.integration.LegendreGaussIntegrator
5.1. LegendreGaussIntegrator
中英对照文档
类 LegendreGaussIntegrator
- java.lang.Object
-
- org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
-
- org.apache.commons.math3.analysis.integration.LegendreGaussIntegrator
-
-
All Implemented Interfaces:
-
UnivariateIntegrator
单抗体钢结构
Deprecated.As of 3.1 (to be removed in 4.0). Please useIterativeLegendreGaussIntegrator
instead.
截至3.1(4.0中删除)。请使用iterativelegendregaussIntegrator。
弃用。截至3.1(4.0中删除)。请使用iterativelegendregaussIntegrator。
@Deprecated public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator
Implements the Legendre-Gauss quadrature formula.Legendre-Gauss integrators are efficient integrators that can accurately integrate functions with few function evaluations. A Legendre-Gauss integrator using an n-points quadrature formula can integrate 2n-1 degree polynomials exactly.
These integrators evaluate the function on n carefully chosen abscissas in each step interval (mapped to the canonical [-1,1] interval). The evaluation abscissas are not evenly spaced and none of them are at the interval endpoints. This implies the function integrated can be undefined at integration interval endpoints.
The evaluation abscissas xi are the roots of the degree n Legendre polynomial. The weights ai of the quadrature formula integrals from -1 to +1 ∫ Li2 where Li (x) = ∏ (x-xk)/(xi-xk) for k != i.
实现Legendre-Gauss正交公式。Legendre-Gauss Integators是有效的集成商,可以准确地集成功能评估。使用N点正交配方的Legendre-Gauss积分器可以完全集成2N-1度多项式。这些集成商在每个步骤间隔中评估N仔细选择的横坐标的功能(映射到规范[-1,1]间隔)。评估横坐标均匀间隔,并且它们都不是在间隔端点。这意味着集成的功能可以在集成间隔端点处未定义。评估横坐标xi是N型Legendre多项式的根源。从-1到+1≠li2的正交公式的重量ai为k!= i的li(x)=π(x-xk)/(xi-xk)。
-
从以下版本开始:
-
1.2
1.2
-
UnivariateIntegrator
-
-
字段概要
-
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
-
-
构造器概要
构造器 构造器和说明 LegendreGaussIntegrator(int n, double relativeAccuracy, double absoluteAccuracy)
Deprecated.
弃用。
Build a Legendre-Gauss integrator with given accuracies.
构建具有给定精度的Legendre-Gauss Integrator。
LegendreGaussIntegrator(int n, double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount)
Deprecated.
弃用。
Build a Legendre-Gauss integrator with given accuracies and iterations counts.
构建具有给定精度和迭代计数的Legendre-Gauss Integrator。
LegendreGaussIntegrator(int n, int minimalIterationCount, int maximalIterationCount)
Deprecated.
弃用。
Build a Legendre-Gauss integrator with given iteration counts.
构建具有给定迭代计数的Legendre-Gauss Integrator。
-
方法概要
Methods 限定符和类型 方法和说明 protected double
doIntegrate()
Deprecated.
弃用。
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
从类继承的方法 org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getIterations, getMax, getMaximalIterationCount, getMin, getMinimalIterationCount, getRelativeAccuracy, incrementCount, integrate, setup
-
-
-
-
构造器详细说明
-
LegendreGaussIntegrator
public LegendreGaussIntegrator(int n, double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount) throws MathIllegalArgumentException, NotStrictlyPositiveException, NumberIsTooSmallException
Deprecated.
弃用。
Build a Legendre-Gauss integrator with given accuracies and iterations counts.
构建具有给定精度和迭代计数的Legendre-Gauss Integrator。
-
参数:
-
n
- number of points desired (must be between 2 and 5 inclusive)
n - 所需的点数(必须在2到5之间)
-
relativeAccuracy
- relative accuracy of the result
相对准确性 - 结果的相对准确性
-
absoluteAccuracy
- absolute accuracy of the result
绝对精度 - 结果绝对准确性
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations
maximalimerationcount - 最大迭代次数
抛出:
-
MathIllegalArgumentException
- if number of points is out of [2; 5]
MathilleGalargumentException - 如果点数超出[2;5]
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
-
LegendreGaussIntegrator
public LegendreGaussIntegrator(int n, double relativeAccuracy, double absoluteAccuracy) throws MathIllegalArgumentException
Deprecated.
弃用。
Build a Legendre-Gauss integrator with given accuracies.
构建具有给定精度的Legendre-Gauss Integrator。
-
参数:
-
n
- number of points desired (must be between 2 and 5 inclusive)
n - 所需的点数(必须在2到5之间)
-
relativeAccuracy
- relative accuracy of the result
相对准确性 - 结果的相对准确性
-
absoluteAccuracy
- absolute accuracy of the result
绝对精度 - 结果绝对准确性
抛出:
-
MathIllegalArgumentException
- if number of points is out of [2; 5]
MathilleGalargumentException - 如果点数超出[2;5]
-
-
LegendreGaussIntegrator
public LegendreGaussIntegrator(int n, int minimalIterationCount, int maximalIterationCount) throws MathIllegalArgumentException
Deprecated.
弃用。
Build a Legendre-Gauss integrator with given iteration counts.
构建具有给定迭代计数的Legendre-Gauss Integrator。
-
参数:
-
n
- number of points desired (must be between 2 and 5 inclusive)
n - 所需的点数(必须在2到5之间)
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations
maximalimerationcount - 最大迭代次数
抛出:
-
MathIllegalArgumentException
- if number of points is out of [2; 5]
MathilleGalargumentException - 如果点数超出[2;5]
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
-
-
方法详细说明
-
doIntegrate
protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException
Deprecated.
弃用。
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
指定者:
-
doIntegrate
in classBaseAbstractUnivariateIntegrator
在课堂Baseabstractunigariation integrator中进行了致力于
返回:
-
the root.
根。
抛出:
-
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.
toomanyevalionsexception - 如果超出了最大数量的评估。
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
MathIllegalArgumentException
MathilleGalargumentException.
-
-
-
5.2. LegendreGaussIntegrator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.integration;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.exception.util.LocalizedFormats;
import org.apache.commons.math3.util.FastMath;
/**
* Implements the <a href="http://mathworld.wolfram.com/Legendre-GaussQuadrature.html">
* Legendre-Gauss</a> quadrature formula.
* <p>
* Legendre-Gauss integrators are efficient integrators that can
* accurately integrate functions with few function evaluations. A
* Legendre-Gauss integrator using an n-points quadrature formula can
* integrate 2n-1 degree polynomials exactly.
* </p>
* <p>
* These integrators evaluate the function on n carefully chosen
* abscissas in each step interval (mapped to the canonical [-1,1] interval).
* The evaluation abscissas are not evenly spaced and none of them are
* at the interval endpoints. This implies the function integrated can be
* undefined at integration interval endpoints.
* </p>
* <p>
* The evaluation abscissas x<sub>i</sub> are the roots of the degree n
* Legendre polynomial. The weights a<sub>i</sub> of the quadrature formula
* integrals from -1 to +1 ∫ Li<sup>2</sup> where Li (x) =
* ∏ (x-x<sub>k</sub>)/(x<sub>i</sub>-x<sub>k</sub>) for k != i.
* </p>
* <p>
* @since 1.2
* @deprecated As of 3.1 (to be removed in 4.0). Please use
* {@link IterativeLegendreGaussIntegrator} instead.
*/
@Deprecated
public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator {
/** Abscissas for the 2 points method. */
private static final double[] ABSCISSAS_2 = {
-1.0 / FastMath.sqrt(3.0),
1.0 / FastMath.sqrt(3.0)
};
/** Weights for the 2 points method. */
private static final double[] WEIGHTS_2 = {
1.0,
1.0
};
/** Abscissas for the 3 points method. */
private static final double[] ABSCISSAS_3 = {
-FastMath.sqrt(0.6),
0.0,
FastMath.sqrt(0.6)
};
/** Weights for the 3 points method. */
private static final double[] WEIGHTS_3 = {
5.0 / 9.0,
8.0 / 9.0,
5.0 / 9.0
};
/** Abscissas for the 4 points method. */
private static final double[] ABSCISSAS_4 = {
-FastMath.sqrt((15.0 + 2.0 * FastMath.sqrt(30.0)) / 35.0),
-FastMath.sqrt((15.0 - 2.0 * FastMath.sqrt(30.0)) / 35.0),
FastMath.sqrt((15.0 - 2.0 * FastMath.sqrt(30.0)) / 35.0),
FastMath.sqrt((15.0 + 2.0 * FastMath.sqrt(30.0)) / 35.0)
};
/** Weights for the 4 points method. */
private static final double[] WEIGHTS_4 = {
(90.0 - 5.0 * FastMath.sqrt(30.0)) / 180.0,
(90.0 + 5.0 * FastMath.sqrt(30.0)) / 180.0,
(90.0 + 5.0 * FastMath.sqrt(30.0)) / 180.0,
(90.0 - 5.0 * FastMath.sqrt(30.0)) / 180.0
};
/** Abscissas for the 5 points method. */
private static final double[] ABSCISSAS_5 = {
-FastMath.sqrt((35.0 + 2.0 * FastMath.sqrt(70.0)) / 63.0),
-FastMath.sqrt((35.0 - 2.0 * FastMath.sqrt(70.0)) / 63.0),
0.0,
FastMath.sqrt((35.0 - 2.0 * FastMath.sqrt(70.0)) / 63.0),
FastMath.sqrt((35.0 + 2.0 * FastMath.sqrt(70.0)) / 63.0)
};
/** Weights for the 5 points method. */
private static final double[] WEIGHTS_5 = {
(322.0 - 13.0 * FastMath.sqrt(70.0)) / 900.0,
(322.0 + 13.0 * FastMath.sqrt(70.0)) / 900.0,
128.0 / 225.0,
(322.0 + 13.0 * FastMath.sqrt(70.0)) / 900.0,
(322.0 - 13.0 * FastMath.sqrt(70.0)) / 900.0
};
/** Abscissas for the current method. */
private final double[] abscissas;
/** Weights for the current method. */
private final double[] weights;
/**
* Build a Legendre-Gauss integrator with given accuracies and iterations counts.
* @param n number of points desired (must be between 2 and 5 inclusive)
* @param relativeAccuracy relative accuracy of the result
* @param absoluteAccuracy absolute accuracy of the result
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* @exception MathIllegalArgumentException if number of points is out of [2; 5]
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
*/
public LegendreGaussIntegrator(final int n,
final double relativeAccuracy,
final double absoluteAccuracy,
final int minimalIterationCount,
final int maximalIterationCount)
throws MathIllegalArgumentException, NotStrictlyPositiveException, NumberIsTooSmallException {
super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount);
switch(n) {
case 2 :
abscissas = ABSCISSAS_2;
weights = WEIGHTS_2;
break;
case 3 :
abscissas = ABSCISSAS_3;
weights = WEIGHTS_3;
break;
case 4 :
abscissas = ABSCISSAS_4;
weights = WEIGHTS_4;
break;
case 5 :
abscissas = ABSCISSAS_5;
weights = WEIGHTS_5;
break;
default :
throw new MathIllegalArgumentException(
LocalizedFormats.N_POINTS_GAUSS_LEGENDRE_INTEGRATOR_NOT_SUPPORTED,
n, 2, 5);
}
}
/**
* Build a Legendre-Gauss integrator with given accuracies.
* @param n number of points desired (must be between 2 and 5 inclusive)
* @param relativeAccuracy relative accuracy of the result
* @param absoluteAccuracy absolute accuracy of the result
* @exception MathIllegalArgumentException if number of points is out of [2; 5]
*/
public LegendreGaussIntegrator(final int n,
final double relativeAccuracy,
final double absoluteAccuracy)
throws MathIllegalArgumentException {
this(n, relativeAccuracy, absoluteAccuracy,
DEFAULT_MIN_ITERATIONS_COUNT, DEFAULT_MAX_ITERATIONS_COUNT);
}
/**
* Build a Legendre-Gauss integrator with given iteration counts.
* @param n number of points desired (must be between 2 and 5 inclusive)
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* @exception MathIllegalArgumentException if number of points is out of [2; 5]
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
*/
public LegendreGaussIntegrator(final int n,
final int minimalIterationCount,
final int maximalIterationCount)
throws MathIllegalArgumentException {
this(n, DEFAULT_RELATIVE_ACCURACY, DEFAULT_ABSOLUTE_ACCURACY,
minimalIterationCount, maximalIterationCount);
}
/** {@inheritDoc} */
@Override
protected double doIntegrate()
throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {
// compute first estimate with a single step
double oldt = stage(1);
int n = 2;
while (true) {
// improve integral with a larger number of steps
final double t = stage(n);
// estimate error
final double delta = FastMath.abs(t - oldt);
final double limit =
FastMath.max(getAbsoluteAccuracy(),
getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5);
// check convergence
if ((getIterations() + 1 >= getMinimalIterationCount()) && (delta <= limit)) {
return t;
}
// prepare next iteration
double ratio = FastMath.min(4, FastMath.pow(delta / limit, 0.5 / abscissas.length));
n = FastMath.max((int) (ratio * n), n + 1);
oldt = t;
incrementCount();
}
}
/**
* Compute the n-th stage integral.
* @param n number of steps
* @return the value of n-th stage integral
* @throws TooManyEvaluationsException if the maximum number of evaluations
* is exceeded.
*/
private double stage(final int n)
throws TooManyEvaluationsException {
// set up the step for the current stage
final double step = (getMax() - getMin()) / n;
final double halfStep = step / 2.0;
// integrate over all elementary steps
double midPoint = getMin() + halfStep;
double sum = 0.0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < abscissas.length; ++j) {
sum += weights[j] * computeObjectiveValue(midPoint + halfStep * abscissas[j]);
}
midPoint += step;
}
return halfStep * sum;
}
}
6. 类 org.apache.commons.math3.analysis.integration.MidPointIntegrator
6.1. MidPointIntegrator
中英对照文档
类 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.
实现中点规则,以实现实际单变量函数的集成。参考,见数字数学,ISBN 0387989595,第9.2章。该功能应该是可集成的。
-
从以下版本开始:
-
3.3
3.3
-
UnivariateIntegrator
-
-
字段概要
字段 限定符和类型 Field and 的说明 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
-
-
构造器概要
构造器 构造器和说明 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.
构建具有给定迭代计数的中点积分器。
-
方法概要
Methods 限定符和类型 方法和说明 protected double
doIntegrate()
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
从类继承的方法 org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getIterations, getMax, getMaximalIterationCount, getMin, getMinimalIterationCount, getRelativeAccuracy, incrementCount, integrate, setup
-
-
-
-
字段详情:
-
MIDPOINT_MAX_ITERATIONS_COUNT
public static final int MIDPOINT_MAX_ITERATIONS_COUNT
Maximum number of iterations for midpoint.
中点的最大迭代次数。
-
另请参阅:
-
Constant Field Values
恒定字段值
-
Constant Field Values
-
-
构造器详细说明
-
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.
构建具有给定精度和迭代计数的中点积分器。
-
参数:
-
relativeAccuracy
- relative accuracy of the result
相对准确性 - 结果的相对准确性
-
absoluteAccuracy
- absolute accuracy of the result
绝对精度 - 结果绝对准确性
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations (must be less than or equal toMIDPOINT_MAX_ITERATIONS_COUNT
maximalimerationcount - 最大迭代次数(必须小于或等于midpoint_max_iterations_count
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
NumberIsTooLargeException
- if maximal number of iterations is greater thanMIDPOINT_MAX_ITERATIONS_COUNT
NumberStoolArgeException - 如果最大迭代次数大于MIDPOINT_MAX_ITERATIONS_COUNT
-
-
MidPointIntegrator
public MidPointIntegrator(int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException
Build a midpoint integrator with given iteration counts.
构建具有给定迭代计数的中点积分器。
-
参数:
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations (must be less than or equal toMIDPOINT_MAX_ITERATIONS_COUNT
maximalimerationcount - 最大迭代次数(必须小于或等于midpoint_max_iterations_count
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
NumberIsTooLargeException
- if maximal number of iterations is greater thanMIDPOINT_MAX_ITERATIONS_COUNT
NumberStoolArgeException - 如果最大迭代次数大于MIDPOINT_MAX_ITERATIONS_COUNT
-
-
MidPointIntegrator
public MidPointIntegrator()
Construct a midpoint integrator with default settings. (max iteration count set toMIDPOINT_MAX_ITERATIONS_COUNT
)
使用默认设置构造中点积分器。(最多迭代计数设置为midpoint_max_Iterations_count)
-
-
方法详细说明
-
doIntegrate
protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
指定者:
-
doIntegrate
in classBaseAbstractUnivariateIntegrator
在课堂Baseabstractunigariation integrator中进行了致力于
返回:
-
the root.
根。
抛出:
-
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.
toomanyevalionsexception - 如果超出了最大数量的评估。
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
MathIllegalArgumentException
MathilleGalargumentException.
-
-
-
6.2. MidPointIntegrator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.integration;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NumberIsTooLargeException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.util.FastMath;
/**
* Implements the <a href="http://en.wikipedia.org/wiki/Midpoint_method">
* Midpoint Rule</a> for integration of real univariate functions. For
* reference, see <b>Numerical Mathematics</b>, ISBN 0387989595,
* chapter 9.2.
* <p>
* The function should be integrable.</p>
*
* @since 3.3
*/
public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator {
/** Maximum number of iterations for midpoint. */
public static final int MIDPOINT_MAX_ITERATIONS_COUNT = 64;
/**
* Build a midpoint integrator with given accuracies and iterations counts.
* @param relativeAccuracy relative accuracy of the result
* @param absoluteAccuracy absolute accuracy of the result
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* (must be less than or equal to {@link #MIDPOINT_MAX_ITERATIONS_COUNT}
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
* @exception NumberIsTooLargeException if maximal number of iterations
* is greater than {@link #MIDPOINT_MAX_ITERATIONS_COUNT}
*/
public MidPointIntegrator(final double relativeAccuracy,
final double absoluteAccuracy,
final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {
super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount);
if (maximalIterationCount > MIDPOINT_MAX_ITERATIONS_COUNT) {
throw new NumberIsTooLargeException(maximalIterationCount,
MIDPOINT_MAX_ITERATIONS_COUNT, false);
}
}
/**
* Build a midpoint integrator with given iteration counts.
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* (must be less than or equal to {@link #MIDPOINT_MAX_ITERATIONS_COUNT}
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
* @exception NumberIsTooLargeException if maximal number of iterations
* is greater than {@link #MIDPOINT_MAX_ITERATIONS_COUNT}
*/
public MidPointIntegrator(final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {
super(minimalIterationCount, maximalIterationCount);
if (maximalIterationCount > MIDPOINT_MAX_ITERATIONS_COUNT) {
throw new NumberIsTooLargeException(maximalIterationCount,
MIDPOINT_MAX_ITERATIONS_COUNT, false);
}
}
/**
* Construct a midpoint integrator with default settings.
* (max iteration count set to {@link #MIDPOINT_MAX_ITERATIONS_COUNT})
*/
public MidPointIntegrator() {
super(DEFAULT_MIN_ITERATIONS_COUNT, MIDPOINT_MAX_ITERATIONS_COUNT);
}
/**
* Compute the n-th stage integral of midpoint rule.
* This function should only be called by API <code>integrate()</code> in the package.
* To save time it does not verify arguments - caller does.
* <p>
* 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.</p>
*
* @param n the stage of 1/2 refinement. Must be larger than 0.
* @param previousStageResult Result from the previous call to the
* {@code stage} method.
* @param min Lower bound of the integration interval.
* @param diffMaxMin Difference between the lower bound and upper bound
* of the integration interval.
* @return the value of n-th stage integral
* @throws TooManyEvaluationsException if the maximal number of evaluations
* is exceeded.
*/
private double stage(final int n,
double previousStageResult,
double min,
double diffMaxMin)
throws TooManyEvaluationsException {
// number of new points in this stage
final long np = 1L << (n - 1);
double sum = 0;
// spacing between adjacent new points
final double spacing = diffMaxMin / np;
// the first new point
double x = min + 0.5 * spacing;
for (long i = 0; i < np; i++) {
sum += computeObjectiveValue(x);
x += spacing;
}
// add the new sum to previously calculated result
return 0.5 * (previousStageResult + sum * spacing);
}
/** {@inheritDoc} */
@Override
protected double doIntegrate()
throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {
final double min = getMin();
final double diff = getMax() - min;
final double midPoint = min + 0.5 * diff;
double oldt = diff * computeObjectiveValue(midPoint);
while (true) {
incrementCount();
final int i = getIterations();
final double t = stage(i, oldt, min, diff);
if (i >= getMinimalIterationCount()) {
final double delta = FastMath.abs(t - oldt);
final double rLimit =
getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5;
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
return t;
}
}
oldt = t;
}
}
}
7. 类 org.apache.commons.math3.analysis.integration.RombergIntegrator
7.1. RombergIntegrator
中英对照文档
类 RombergIntegrator
- java.lang.Object
-
- org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
-
- org.apache.commons.math3.analysis.integration.RombergIntegrator
-
-
All Implemented Interfaces:
-
UnivariateIntegrator
单抗体钢结构
public class RombergIntegrator extends BaseAbstractUnivariateIntegrator
Implements the Romberg Algorithm for integration of real univariate functions. For reference, see Introduction to Numerical Analysis, ISBN 038795452X, chapter 3.Romberg integration employs k successive refinements of the trapezoid rule to remove error terms less than order O(N^(-2k)). Simpson's rule is a special case of k = 2.
实现romberg算法,以集成真正的单变量函数。参见,参见数值分析简介,ISBN 038795452x,第3章romberg集成采用梯形规则的k连续改进,以删除比Order O的错误条款(n ^( - 2k))。辛普森的规则是k = 2的特殊情况。
-
从以下版本开始:
-
1.2
1.2
-
UnivariateIntegrator
-
-
字段概要
字段 限定符和类型 Field and 的说明 static int
ROMBERG_MAX_ITERATIONS_COUNT
Maximal number of iterations for Romberg.
Romberg的最大迭代次数。
-
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
-
-
构造器概要
构造器 构造器和说明 RombergIntegrator()
Construct a Romberg integrator with default settings (max iteration count set toROMBERG_MAX_ITERATIONS_COUNT
)
构建具有默认设置的romberg集成商(Max Iteration Count设置为romberg_max_iterations_count)
RombergIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount)
Build a Romberg integrator with given accuracies and iterations counts.
构建具有给定精度和迭代计数的romberg Integrator。
RombergIntegrator(int minimalIterationCount, int maximalIterationCount)
Build a Romberg integrator with given iteration counts.
构建带有迭代计数的romberg集成商。
-
方法概要
Methods 限定符和类型 方法和说明 protected double
doIntegrate()
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
从类继承的方法 org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getIterations, getMax, getMaximalIterationCount, getMin, getMinimalIterationCount, getRelativeAccuracy, incrementCount, integrate, setup
-
-
-
-
字段详情:
-
ROMBERG_MAX_ITERATIONS_COUNT
public static final int ROMBERG_MAX_ITERATIONS_COUNT
Maximal number of iterations for Romberg.
Romberg的最大迭代次数。
-
另请参阅:
-
Constant Field Values
恒定字段值
-
Constant Field Values
-
-
构造器详细说明
-
RombergIntegrator
public RombergIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException
Build a Romberg integrator with given accuracies and iterations counts.
构建具有给定精度和迭代计数的romberg Integrator。
-
参数:
-
relativeAccuracy
- relative accuracy of the result
相对准确性 - 结果的相对准确性
-
absoluteAccuracy
- absolute accuracy of the result
绝对精度 - 结果绝对准确性
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations (must be less than or equal toROMBERG_MAX_ITERATIONS_COUNT
)
maximalimerationcount - 最大迭代次数(必须小于或等于romberg_max_iterations_count)
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
NumberIsTooLargeException
- if maximal number of iterations is greater thanROMBERG_MAX_ITERATIONS_COUNT
NumberStoolarGeexception - 如果最大迭代次数大于romberg_max_iterations_count
-
-
RombergIntegrator
public RombergIntegrator(int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException
Build a Romberg integrator with given iteration counts.
构建带有迭代计数的romberg集成商。
-
参数:
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations (must be less than or equal toROMBERG_MAX_ITERATIONS_COUNT
)
maximalimerationcount - 最大迭代次数(必须小于或等于romberg_max_iterations_count)
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
NumberIsTooLargeException
- if maximal number of iterations is greater thanROMBERG_MAX_ITERATIONS_COUNT
NumberStoolarGeexception - 如果最大迭代次数大于romberg_max_iterations_count
-
-
RombergIntegrator
public RombergIntegrator()
Construct a Romberg integrator with default settings (max iteration count set toROMBERG_MAX_ITERATIONS_COUNT
)
构建具有默认设置的romberg集成商(Max Iteration Count设置为romberg_max_iterations_count)
-
-
方法详细说明
-
doIntegrate
protected double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
指定者:
-
doIntegrate
in classBaseAbstractUnivariateIntegrator
在课堂Baseabstractunigariation integrator中进行了致力于
返回:
-
the root.
根。
抛出:
-
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.
toomanyevalionsexception - 如果超出了最大数量的评估。
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
-
-
7.2. RombergIntegrator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.integration;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NumberIsTooLargeException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.util.FastMath;
/**
* Implements the <a href="http://mathworld.wolfram.com/RombergIntegration.html">
* Romberg Algorithm</a> for integration of real univariate functions. For
* reference, see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X,
* chapter 3.
* <p>
* Romberg integration employs k successive refinements of the trapezoid
* rule to remove error terms less than order O(N^(-2k)). Simpson's rule
* is a special case of k = 2.</p>
*
* @since 1.2
*/
public class RombergIntegrator extends BaseAbstractUnivariateIntegrator {
/** Maximal number of iterations for Romberg. */
public static final int ROMBERG_MAX_ITERATIONS_COUNT = 32;
/**
* Build a Romberg integrator with given accuracies and iterations counts.
* @param relativeAccuracy relative accuracy of the result
* @param absoluteAccuracy absolute accuracy of the result
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* (must be less than or equal to {@link #ROMBERG_MAX_ITERATIONS_COUNT})
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
* @exception NumberIsTooLargeException if maximal number of iterations
* is greater than {@link #ROMBERG_MAX_ITERATIONS_COUNT}
*/
public RombergIntegrator(final double relativeAccuracy,
final double absoluteAccuracy,
final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {
super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount);
if (maximalIterationCount > ROMBERG_MAX_ITERATIONS_COUNT) {
throw new NumberIsTooLargeException(maximalIterationCount,
ROMBERG_MAX_ITERATIONS_COUNT, false);
}
}
/**
* Build a Romberg integrator with given iteration counts.
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* (must be less than or equal to {@link #ROMBERG_MAX_ITERATIONS_COUNT})
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
* @exception NumberIsTooLargeException if maximal number of iterations
* is greater than {@link #ROMBERG_MAX_ITERATIONS_COUNT}
*/
public RombergIntegrator(final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {
super(minimalIterationCount, maximalIterationCount);
if (maximalIterationCount > ROMBERG_MAX_ITERATIONS_COUNT) {
throw new NumberIsTooLargeException(maximalIterationCount,
ROMBERG_MAX_ITERATIONS_COUNT, false);
}
}
/**
* Construct a Romberg integrator with default settings
* (max iteration count set to {@link #ROMBERG_MAX_ITERATIONS_COUNT})
*/
public RombergIntegrator() {
super(DEFAULT_MIN_ITERATIONS_COUNT, ROMBERG_MAX_ITERATIONS_COUNT);
}
/** {@inheritDoc} */
@Override
protected double doIntegrate()
throws TooManyEvaluationsException, MaxCountExceededException {
final int m = getMaximalIterationCount() + 1;
double previousRow[] = new double[m];
double currentRow[] = new double[m];
TrapezoidIntegrator qtrap = new TrapezoidIntegrator();
currentRow[0] = qtrap.stage(this, 0);
incrementCount();
double olds = currentRow[0];
while (true) {
final int i = getIterations();
// switch rows
final double[] tmpRow = previousRow;
previousRow = currentRow;
currentRow = tmpRow;
currentRow[0] = qtrap.stage(this, i);
incrementCount();
for (int j = 1; j <= i; j++) {
// Richardson extrapolation coefficient
final double r = (1L << (2 * j)) - 1;
final double tIJm1 = currentRow[j - 1];
currentRow[j] = tIJm1 + (tIJm1 - previousRow[j - 1]) / r;
}
final double s = currentRow[i];
if (i >= getMinimalIterationCount()) {
final double delta = FastMath.abs(s - olds);
final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5;
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
return s;
}
}
olds = s;
}
}
}
8. 类 org.apache.commons.math3.analysis.integration.SimpsonIntegrator
8.1. SimpsonIntegrator
中英对照文档
类 SimpsonIntegrator
- java.lang.Object
-
- org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
-
- org.apache.commons.math3.analysis.integration.SimpsonIntegrator
-
-
All Implemented Interfaces:
-
UnivariateIntegrator
单抗体钢结构
public class SimpsonIntegrator extends BaseAbstractUnivariateIntegrator
Implements Simpson's Rule for integration of real univariate functions. For reference, see Introduction to Numerical Analysis, ISBN 038795452X, chapter 3.This implementation employs the basic trapezoid rule to calculate Simpson's rule.
实现辛普森的规则,以集成真正单变量功能。有关参考,请参阅介绍数值分析,ISBN 038795452x,第3章。此实现采用基本梯形规则来计算SIMPSON的规则。
-
从以下版本开始:
-
1.2
1.2
-
UnivariateIntegrator
-
-
字段概要
字段 限定符和类型 Field and 的说明 static int
SIMPSON_MAX_ITERATIONS_COUNT
Maximal number of iterations for Simpson.
辛普森的最大迭代次数。
-
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
-
-
构造器概要
构造器 构造器和说明 SimpsonIntegrator()
Construct an integrator with default settings.
构建具有默认设置的集成器。
SimpsonIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount)
Build a Simpson integrator with given accuracies and iterations counts.
构建具有给定精度和迭代计数的辛普森集成商。
SimpsonIntegrator(int minimalIterationCount, int maximalIterationCount)
Build a Simpson integrator with given iteration counts.
构建具有给定迭代计数的SIMPSON Integrator。
-
方法概要
Methods 限定符和类型 方法和说明 protected double
doIntegrate()
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
从类继承的方法 org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getIterations, getMax, getMaximalIterationCount, getMin, getMinimalIterationCount, getRelativeAccuracy, incrementCount, integrate, setup
-
-
-
-
字段详情:
-
SIMPSON_MAX_ITERATIONS_COUNT
public static final int SIMPSON_MAX_ITERATIONS_COUNT
Maximal number of iterations for Simpson.
辛普森的最大迭代次数。
-
另请参阅:
-
Constant Field Values
恒定字段值
-
Constant Field Values
-
-
构造器详细说明
-
SimpsonIntegrator
public SimpsonIntegrator(double relativeAccuracy, double absoluteAccuracy, int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException
Build a Simpson integrator with given accuracies and iterations counts.
构建具有给定精度和迭代计数的辛普森集成商。
-
参数:
-
relativeAccuracy
- relative accuracy of the result
相对准确性 - 结果的相对准确性
-
absoluteAccuracy
- absolute accuracy of the result
绝对精度 - 结果绝对准确性
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations (must be less than or equal toSIMPSON_MAX_ITERATIONS_COUNT
)
maximalimerationcount - 最大迭代次数(必须小于或等于SIMPSON_MAX_INTATIONS_COUNT)
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
NumberIsTooLargeException
- if maximal number of iterations is greater thanSIMPSON_MAX_ITERATIONS_COUNT
NumberStoolarGeexception - 如果最大迭代次数大于SIMPSON_MAX_ITERATIONS_COUNT
-
-
SimpsonIntegrator
public SimpsonIntegrator(int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException
Build a Simpson integrator with given iteration counts.
构建具有给定迭代计数的SIMPSON Integrator。
-
参数:
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations (must be less than or equal toSIMPSON_MAX_ITERATIONS_COUNT
)
maximalimerationcount - 最大迭代次数(必须小于或等于SIMPSON_MAX_INTATIONS_COUNT)
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
NumberIsTooLargeException
- if maximal number of iterations is greater thanSIMPSON_MAX_ITERATIONS_COUNT
NumberStoolarGeexception - 如果最大迭代次数大于SIMPSON_MAX_ITERATIONS_COUNT
-
-
SimpsonIntegrator
public SimpsonIntegrator()
Construct an integrator with default settings. (max iteration count set toSIMPSON_MAX_ITERATIONS_COUNT
)
构建具有默认设置的集成器。(MAX迭代计数设置为SIMPSON_MAX_ITIRATIONS_COUNT)
-
-
方法详细说明
-
doIntegrate
protected double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
指定者:
-
doIntegrate
in classBaseAbstractUnivariateIntegrator
在课堂Baseabstractunigariation integrator中进行了致力于
返回:
-
the root.
根。
抛出:
-
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.
toomanyevalionsexception - 如果超出了最大数量的评估。
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
-
-
8.2. SimpsonIntegrator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.integration;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NumberIsTooLargeException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.util.FastMath;
/**
* Implements <a href="http://mathworld.wolfram.com/SimpsonsRule.html">
* Simpson's Rule</a> for integration of real univariate functions. For
* reference, see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X,
* chapter 3.
* <p>
* This implementation employs the basic trapezoid rule to calculate Simpson's
* rule.</p>
*
* @since 1.2
*/
public class SimpsonIntegrator extends BaseAbstractUnivariateIntegrator {
/** Maximal number of iterations for Simpson. */
public static final int SIMPSON_MAX_ITERATIONS_COUNT = 64;
/**
* Build a Simpson integrator with given accuracies and iterations counts.
* @param relativeAccuracy relative accuracy of the result
* @param absoluteAccuracy absolute accuracy of the result
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* (must be less than or equal to {@link #SIMPSON_MAX_ITERATIONS_COUNT})
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
* @exception NumberIsTooLargeException if maximal number of iterations
* is greater than {@link #SIMPSON_MAX_ITERATIONS_COUNT}
*/
public SimpsonIntegrator(final double relativeAccuracy,
final double absoluteAccuracy,
final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {
super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount);
if (maximalIterationCount > SIMPSON_MAX_ITERATIONS_COUNT) {
throw new NumberIsTooLargeException(maximalIterationCount,
SIMPSON_MAX_ITERATIONS_COUNT, false);
}
}
/**
* Build a Simpson integrator with given iteration counts.
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* (must be less than or equal to {@link #SIMPSON_MAX_ITERATIONS_COUNT})
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
* @exception NumberIsTooLargeException if maximal number of iterations
* is greater than {@link #SIMPSON_MAX_ITERATIONS_COUNT}
*/
public SimpsonIntegrator(final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {
super(minimalIterationCount, maximalIterationCount);
if (maximalIterationCount > SIMPSON_MAX_ITERATIONS_COUNT) {
throw new NumberIsTooLargeException(maximalIterationCount,
SIMPSON_MAX_ITERATIONS_COUNT, false);
}
}
/**
* Construct an integrator with default settings.
* (max iteration count set to {@link #SIMPSON_MAX_ITERATIONS_COUNT})
*/
public SimpsonIntegrator() {
super(DEFAULT_MIN_ITERATIONS_COUNT, SIMPSON_MAX_ITERATIONS_COUNT);
}
/** {@inheritDoc} */
@Override
protected double doIntegrate()
throws TooManyEvaluationsException, MaxCountExceededException {
TrapezoidIntegrator qtrap = new TrapezoidIntegrator();
if (getMinimalIterationCount() == 1) {
return (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0;
}
// Simpson's rule requires at least two trapezoid stages.
double olds = 0;
double oldt = qtrap.stage(this, 0);
while (true) {
final double t = qtrap.stage(this, getIterations());
incrementCount();
final double s = (4 * t - oldt) / 3.0;
if (getIterations() >= getMinimalIterationCount()) {
final double delta = FastMath.abs(s - olds);
final double rLimit =
getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5;
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
return s;
}
}
olds = s;
oldt = t;
}
}
}
9. 类 org.apache.commons.math3.analysis.integration.TrapezoidIntegrator
9.1. TrapezoidIntegrator
中英对照文档
类 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.
实现梯形规则,以便集成真正的单变量函数。供参考,请参阅介绍数值分析,ISBN 038795452x,第3章。功能应该是可集成的。
-
从以下版本开始:
-
1.2
1.2
-
UnivariateIntegrator
-
-
字段概要
字段 限定符和类型 Field and 的说明 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
-
-
构造器概要
构造器 构造器和说明 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.
构建具有给定迭代计数的梯形集成器。
-
方法概要
Methods 限定符和类型 方法和说明 protected double
doIntegrate()
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
从类继承的方法 org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getIterations, getMax, getMaximalIterationCount, getMin, getMinimalIterationCount, getRelativeAccuracy, incrementCount, integrate, setup
-
-
-
-
字段详情:
-
TRAPEZOID_MAX_ITERATIONS_COUNT
public static final int TRAPEZOID_MAX_ITERATIONS_COUNT
Maximum number of iterations for trapezoid.
梯形的最大迭代次数。
-
另请参阅:
-
Constant Field Values
恒定字段值
-
Constant Field Values
-
-
构造器详细说明
-
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.
构建具有给定精度和迭代计数的梯形集成器。
-
参数:
-
relativeAccuracy
- relative accuracy of the result
相对准确性 - 结果的相对准确性
-
absoluteAccuracy
- absolute accuracy of the result
绝对精度 - 结果绝对准确性
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations (must be less than or equal toTRAPEZOID_MAX_ITERATIONS_COUNT
maximalimerationcount - 最大迭代次数(必须小于或等于trapezoid_max_iterations_count
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
NumberIsTooLargeException
- if maximal number of iterations is greater thanTRAPEZOID_MAX_ITERATIONS_COUNT
NumberStoolarGeexception - 如果最大迭代次数大于Trapezoid_max_Iterations_count
-
-
TrapezoidIntegrator
public TrapezoidIntegrator(int minimalIterationCount, int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException
Build a trapezoid integrator with given iteration counts.
构建具有给定迭代计数的梯形集成器。
-
参数:
-
minimalIterationCount
- minimum number of iterations
minimalitorioncount - 最小迭代次数
-
maximalIterationCount
- maximum number of iterations (must be less than or equal toTRAPEZOID_MAX_ITERATIONS_COUNT
maximalimerationcount - 最大迭代次数(必须小于或等于trapezoid_max_iterations_count
抛出:
-
NotStrictlyPositiveException
- if minimal number of iterations is not strictly positive
NOTSTRICLYPOSIVEIVEEXception - 如果最小的迭代数量并不严格积极
-
NumberIsTooSmallException
- if maximal number of iterations is lesser than or equal to the minimal number of iterations
numberistoosmallexception - 如果最大迭代次数小于或等于最小数量的迭代次数
-
NumberIsTooLargeException
- if maximal number of iterations is greater thanTRAPEZOID_MAX_ITERATIONS_COUNT
NumberStoolarGeexception - 如果最大迭代次数大于Trapezoid_max_Iterations_count
-
-
TrapezoidIntegrator
public TrapezoidIntegrator()
Construct a trapezoid integrator with default settings. (max iteration count set toTRAPEZOID_MAX_ITERATIONS_COUNT
)
用默认设置构造梯形集成器。(最多迭代计数设置为trapezoid_max_iterations_count)
-
-
方法详细说明
-
doIntegrate
protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException
Method for implementing actual integration algorithms in derived classes.
在派生类中实现实际集成算法的方法。
-
指定者:
-
doIntegrate
in classBaseAbstractUnivariateIntegrator
在课堂Baseabstractunigariation integrator中进行了致力于
返回:
-
the root.
根。
抛出:
-
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.
toomanyevalionsexception - 如果超出了最大数量的评估。
-
MaxCountExceededException
- if the maximum iteration count is exceeded or the integrator detects convergence problems otherwise
MaxCountExceedEdException - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题
-
MathIllegalArgumentException
MathilleGalargumentException.
-
-
-
9.2. TrapezoidIntegrator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.integration;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NumberIsTooLargeException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.util.FastMath;
/**
* Implements the <a href="http://mathworld.wolfram.com/TrapezoidalRule.html">
* Trapezoid Rule</a> for integration of real univariate functions. For
* reference, see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X,
* chapter 3.
* <p>
* The function should be integrable.</p>
*
* @since 1.2
*/
public class TrapezoidIntegrator extends BaseAbstractUnivariateIntegrator {
/** Maximum number of iterations for trapezoid. */
public static final int TRAPEZOID_MAX_ITERATIONS_COUNT = 64;
/** Intermediate result. */
private double s;
/**
* Build a trapezoid integrator with given accuracies and iterations counts.
* @param relativeAccuracy relative accuracy of the result
* @param absoluteAccuracy absolute accuracy of the result
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* (must be less than or equal to {@link #TRAPEZOID_MAX_ITERATIONS_COUNT}
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
* @exception NumberIsTooLargeException if maximal number of iterations
* is greater than {@link #TRAPEZOID_MAX_ITERATIONS_COUNT}
*/
public TrapezoidIntegrator(final double relativeAccuracy,
final double absoluteAccuracy,
final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {
super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount);
if (maximalIterationCount > TRAPEZOID_MAX_ITERATIONS_COUNT) {
throw new NumberIsTooLargeException(maximalIterationCount,
TRAPEZOID_MAX_ITERATIONS_COUNT, false);
}
}
/**
* Build a trapezoid integrator with given iteration counts.
* @param minimalIterationCount minimum number of iterations
* @param maximalIterationCount maximum number of iterations
* (must be less than or equal to {@link #TRAPEZOID_MAX_ITERATIONS_COUNT}
* @exception NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive
* @exception NumberIsTooSmallException if maximal number of iterations
* is lesser than or equal to the minimal number of iterations
* @exception NumberIsTooLargeException if maximal number of iterations
* is greater than {@link #TRAPEZOID_MAX_ITERATIONS_COUNT}
*/
public TrapezoidIntegrator(final int minimalIterationCount,
final int maximalIterationCount)
throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {
super(minimalIterationCount, maximalIterationCount);
if (maximalIterationCount > TRAPEZOID_MAX_ITERATIONS_COUNT) {
throw new NumberIsTooLargeException(maximalIterationCount,
TRAPEZOID_MAX_ITERATIONS_COUNT, false);
}
}
/**
* Construct a trapezoid integrator with default settings.
* (max iteration count set to {@link #TRAPEZOID_MAX_ITERATIONS_COUNT})
*/
public TrapezoidIntegrator() {
super(DEFAULT_MIN_ITERATIONS_COUNT, TRAPEZOID_MAX_ITERATIONS_COUNT);
}
/**
* Compute the n-th stage integral of trapezoid rule. This function
* should only be called by API <code>integrate()</code> in the package.
* To save time it does not verify arguments - caller does.
* <p>
* 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.</p>
*
* @param baseIntegrator integrator holding integration parameters
* @param n the stage of 1/2 refinement, n = 0 is no refinement
* @return the value of n-th stage integral
* @throws TooManyEvaluationsException if the maximal number of evaluations
* is exceeded.
*/
double stage(final BaseAbstractUnivariateIntegrator baseIntegrator, final int n)
throws TooManyEvaluationsException {
if (n == 0) {
final double max = baseIntegrator.getMax();
final double min = baseIntegrator.getMin();
s = 0.5 * (max - min) *
(baseIntegrator.computeObjectiveValue(min) +
baseIntegrator.computeObjectiveValue(max));
return s;
} else {
final long np = 1L << (n-1); // number of new points in this stage
double sum = 0;
final double max = baseIntegrator.getMax();
final double min = baseIntegrator.getMin();
// spacing between adjacent new points
final double spacing = (max - min) / np;
double x = min + 0.5 * spacing; // the first new point
for (long i = 0; i < np; i++) {
sum += baseIntegrator.computeObjectiveValue(x);
x += spacing;
}
// add the new sum to previously calculated result
s = 0.5 * (s + sum * spacing);
return s;
}
}
/** {@inheritDoc} */
@Override
protected double doIntegrate()
throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {
double oldt = stage(this, 0);
incrementCount();
while (true) {
final int i = getIterations();
final double t = stage(this, i);
if (i >= getMinimalIterationCount()) {
final double delta = FastMath.abs(t - oldt);
final double rLimit =
getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5;
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
return t;
}
}
oldt = t;
incrementCount();
}
}
}