commons-math3-3.6.1-org.apache.commons.math3.analysis.integration-包下的类-中英对照文档及源码赏析

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. 开源组件说明

commonsmath.gif

commonslogo.png

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

Numerical integration (quadrature) algorithms for univariate real functions.

单变量真正函数的数值积分(正交)算法。

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正交。

    LegendreGaussIntegratorDeprecated
    As of 3.1 (to be removed in 4.0).

    截至3.1(4.0中删除)。

    MidPointIntegrator
    Implements the Midpoint Rule for integration of real univariate functions.

    实现中点规则,以实现实际单变量函数的集成。

    RombergIntegrator
    Implements the Romberg Algorithm for integration of real univariate functions.

    实现romberg算法,以集成真正的单变量函数。

    SimpsonIntegrator
    Implements Simpson's Rule for integration of real univariate functions.

    实现辛普森的规则,以集成真正单变量功能。

    TrapezoidIntegrator
    Implements the Trapezoid Rule for integration of real univariate functions.

    实现梯形规则,以便集成真正的单变量函数。

程序包 org.apache.commons.math3.analysis.integration 的说明
Numerical integration (quadrature) algorithms for univariate real functions.

单变量真正函数的数值积分(正交)算法。

2. 类 org.apache.commons.math3.analysis.integration.UnivariateIntegrator

2.1. UnivariateIntegrator 中英对照文档

org.apache.commons.math3.analysis.integration
接口 UnivariateIntegrator
    • 方法概要
      Methods  
      限定符和类型方法和说明
      doublegetAbsoluteAccuracy()
      Get the absolute accuracy.

      获得绝对的准确性。

      intgetEvaluations()
      Get the number of function evaluations of the last run of the integrator.

      获取积分器最后一次运行的函数评估数。

      intgetIterations()
      Get the number of iterations of the last run of the integrator.

      获取积分器最后一次运行的迭代次数。

      intgetMaximalIterationCount()
      Get the upper limit for the number of iterations.

      获取迭代次数的上限。

      intgetMinimalIterationCount()
      Get the min limit for the number of iterations.

      获取迭代次数的最小限制。

      doublegetRelativeAccuracy()
      Get the relative accuracy.

      获得相对准确性。

      doubleintegrate(int maxEval, UnivariateFunction f, double min, double max)
      Integrate the function in the given interval.

      在给定间隔中集成函数。

    • 方法详细说明
      • getRelativeAccuracy
        double getRelativeAccuracy()
        Get the relative accuracy.

        获得相对准确性。

        返回:
        the accuracy

        准确性

      • getAbsoluteAccuracy
        double getAbsoluteAccuracy()
        Get the absolute accuracy.

        获得绝对的准确性。

        返回:
        the accuracy

        准确性

      • getMinimalIterationCount
        int getMinimalIterationCount()
        Get the min limit for the number of iterations.

        获取迭代次数的最小限制。

        返回:
        the actual min limit

        实际最小限制

      • getMaximalIterationCount
        int getMaximalIterationCount()
        Get the upper limit for the number of iterations.

        获取迭代次数的上限。

        返回:
        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 - if min > max or the endpoints do not satisfy the requirements specified by the integrator

        MathilleGalargumentException - 如果min> max或端点不满足积分器指定的要求

        NullArgumentException - if f is null.

        nullargumentException - 如果f为null。

      • getEvaluations
        int getEvaluations()
        Get the number of function evaluations of the last run of the integrator.

        获取积分器最后一次运行的函数评估数。

        返回:
        number of function evaluations

        功能评估数量

      • getIterations
        int getIterations()
        Get the number of iterations of the last run of the integrator.

        获取积分器最后一次运行的迭代次数。

        返回:
        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 中英对照文档

org.apache.commons.math3.analysis.integration
类 BaseAbstractUnivariateIntegrator
  • java.lang.Object
    • org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator
    • 字段概要
      字段  
      限定符和类型Field and 的说明
      static doubleDEFAULT_ABSOLUTE_ACCURACY
      Default absolute accuracy.

      默认绝对准确性。

      static intDEFAULT_MAX_ITERATIONS_COUNT
      Default maximal iteration count.

      默认最大迭代计数。

      static intDEFAULT_MIN_ITERATIONS_COUNT
      Default minimal iteration count.

      默认最小迭代计数。

      static doubleDEFAULT_RELATIVE_ACCURACY
      Default relative accuracy.

      默认的相对准确性。

      protected Incrementoriterations
      Deprecated. 
      as of 3.6, this field has been replaced with incrementCount()

      截至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 doublecomputeObjectiveValue(double point)
      Compute the objective function value.

      计算目标函数值。

      protected abstract doubledoIntegrate()
      Method for implementing actual integration algorithms in derived classes.

      在派生类中实现实际集成算法的方法。

      doublegetAbsoluteAccuracy()
      Get the absolute accuracy.

      获得绝对的准确性。

      intgetEvaluations()
      Get the number of function evaluations of the last run of the integrator.

      获取积分器最后一次运行的函数评估数。

      intgetIterations()
      Get the number of iterations of the last run of the integrator.

      获取积分器最后一次运行的迭代次数。

      protected doublegetMax() 
      intgetMaximalIterationCount()
      Get the upper limit for the number of iterations.

      获取迭代次数的上限。

      protected doublegetMin() 
      intgetMinimalIterationCount()
      Get the min limit for the number of iterations.

      获取迭代次数的最小限制。

      doublegetRelativeAccuracy()
      Get the relative accuracy.

      获得相对准确性。

      protected voidincrementCount()
      Increment the number of iterations.

      递增迭代次数。

      doubleintegrate(int maxEval, UnivariateFunction f, double lower, double upper)
      Integrate the function in the given interval.

      在给定间隔中集成函数。

      protected voidsetup(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

        恒定字段值

      • DEFAULT_RELATIVE_ACCURACY
        public static final double DEFAULT_RELATIVE_ACCURACY
        Default relative accuracy.

        默认的相对准确性。

        另请参阅:
        Constant Field Values

        恒定字段值

      • DEFAULT_MIN_ITERATIONS_COUNT
        public static final int DEFAULT_MIN_ITERATIONS_COUNT
        Default minimal iteration count.

        默认最小迭代计数。

        另请参阅:
        Constant Field Values

        恒定字段值

      • DEFAULT_MAX_ITERATIONS_COUNT
        public static final int DEFAULT_MAX_ITERATIONS_COUNT
        Default maximal iteration count.

        默认最大迭代计数。

        另请参阅:
        Constant Field Values

        恒定字段值

      • iterations
        @Deprecated
        protected Incrementor iterations
        Deprecated.  as of 3.6, this field has been replaced with incrementCount()

        弃用。截至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 - 如果最大迭代次数小于或等于最小数量的迭代次数

      • 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 interface  UnivariateIntegrator

        界面非变量钢结构中的GetrelativeAccuracy

        返回:
        the accuracy

        准确性

      • getAbsoluteAccuracy
        public double getAbsoluteAccuracy()
        Get the absolute accuracy.

        获得绝对的准确性。

        指定者:
        getAbsoluteAccuracy in interface  UnivariateIntegrator

        在界面单变量钢结构中的GetAbsoluteAccuracy

        返回:
        the accuracy

        准确性

      • getMinimalIterationCount
        public int getMinimalIterationCount()
        Get the min limit for the number of iterations.

        获取迭代次数的最小限制。

        指定者:
        getMinimalIterationCount in interface  UnivariateIntegrator

        interfaceunimalierationcount在一个单变量钢结构中

        返回:
        the actual min limit

        实际最小限制

      • getMaximalIterationCount
        public int getMaximalIterationCount()
        Get the upper limit for the number of iterations.

        获取迭代次数的上限。

        指定者:
        getMaximalIterationCount in interface  UnivariateIntegrator

        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 interface  UnivariateIntegrator

        界面非变量钢结构中的GeteValuation

        返回:
        number of function evaluations

        功能评估数量

      • getIterations
        public int getIterations()
        Get the number of iterations of the last run of the integrator.

        获取积分器最后一次运行的迭代次数。

        指定者:
        getIterations in interface  UnivariateIntegrator

        界面单因素钢结构中的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.

        下限。

      • getMax
        protected double getMax()
        返回:
        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 the solve 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 - if f is null.

        nullargumentException - 如果f为null。

        MathIllegalArgumentException - if min >= 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 interface  UnivariateIntegrator

        集成在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 - if min > max or the endpoints do not satisfy the requirements specified by the integrator

        MathilleGalargumentException - 如果min> max或端点不满足积分器指定的要求

        NullArgumentException - if f is null.

        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 - 如果超出了最大迭代计数,或者积分器否则会检测到融合问题

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 中英对照文档

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

    • 字段概要
      • 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 doubledoIntegrate()
      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 - if n < 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 - if n < 1.

        notstrictypositiveexception - 如果n <1。

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 中英对照文档

org.apache.commons.math3.analysis.integration
类 LegendreGaussIntegrator
  • All Implemented Interfaces:
    UnivariateIntegrator

    单抗体钢结构


    Deprecated. 
    As of 3.1 (to be removed in 4.0). Please use IterativeLegendreGaussIntegrator 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

    • 字段概要
      • 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 doubledoIntegrate()
      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 - 如果最大迭代次数小于或等于最小数量的迭代次数

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 &int; Li<sup>2</sup> where Li (x) =
 * &prod; (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 中英对照文档

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

    • 字段概要
      字段  
      限定符和类型Field and 的说明
      static intMIDPOINT_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 doubledoIntegrate()
      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

        恒定字段值

    • 构造器详细说明
      • 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 to MIDPOINT_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 than MIDPOINT_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 to MIDPOINT_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 than MIDPOINT_MAX_ITERATIONS_COUNT

        NumberStoolArgeException - 如果最大迭代次数大于MIDPOINT_MAX_ITERATIONS_COUNT

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

        使用默认设置构造中点积分器。(最多迭代计数设置为midpoint_max_Iterations_count)

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 中英对照文档

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

    • 字段概要
      字段  
      限定符和类型Field and 的说明
      static intROMBERG_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 to ROMBERG_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 doubledoIntegrate()
      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

        恒定字段值

    • 构造器详细说明
      • 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 to ROMBERG_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 than ROMBERG_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 to ROMBERG_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 than ROMBERG_MAX_ITERATIONS_COUNT

        NumberStoolarGeexception - 如果最大迭代次数大于romberg_max_iterations_count

      • RombergIntegrator
        public RombergIntegrator()
        Construct a Romberg integrator with default settings (max iteration count set to ROMBERG_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 class  BaseAbstractUnivariateIntegrator

        在课堂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 中英对照文档

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

    • 字段概要
      字段  
      限定符和类型Field and 的说明
      static intSIMPSON_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 doubledoIntegrate()
      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

        恒定字段值

    • 构造器详细说明
      • 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 to SIMPSON_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 than SIMPSON_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 to SIMPSON_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 than SIMPSON_MAX_ITERATIONS_COUNT

        NumberStoolarGeexception - 如果最大迭代次数大于SIMPSON_MAX_ITERATIONS_COUNT

      • SimpsonIntegrator
        public SimpsonIntegrator()
        Construct an integrator with default settings. (max iteration count set to SIMPSON_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 class  BaseAbstractUnivariateIntegrator

        在课堂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 中英对照文档

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

    • 字段概要
      字段  
      限定符和类型Field and 的说明
      static intTRAPEZOID_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 doubledoIntegrate()
      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

        恒定字段值

    • 构造器详细说明
      • 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 to TRAPEZOID_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 than TRAPEZOID_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 to TRAPEZOID_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 than TRAPEZOID_MAX_ITERATIONS_COUNT

        NumberStoolarGeexception - 如果最大迭代次数大于Trapezoid_max_Iterations_count

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

        用默认设置构造梯形集成器。(最多迭代计数设置为trapezoid_max_iterations_count)

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();
        }

    }

}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: commons-math3-3.6.1-api文档-中英对照版.zip是一个包含Commons Math3.6.1版本的API文档的压缩文件。Commons Math是一个Java库,提供了许多数学功能和算法的实现。 API文档是帮助开发人员理解库中可用的、方法和属性的官方文档。它提供了关于每个的详细说明,包括的用途、方法的功能、参数和返回值的说明等。通过阅读API文档,开发人员可以很容易地了解如何正确地使用库的各个部分。 这个特定的API文档版本是中英对照版,这意味着文档提供了中文和英文的对照版本。这将有助于使用英文不太熟练的开发人员更好地理解文档的内容。无论是母语为中文的开发者还是母语为英文的开发者,都可以从这个中英对照的API文档中受益。 要使用这个API文档,你可以下载并解压缩这个.zip文件。解压后,你将获得一个文件夹,里面包含了所有的API文档文件。你可以打开文档并浏览其中的和方法,查找你需要的信息。 总之,commons-math3-3.6.1-api文档-中英对照版.zip是一个包含了Commons Math3.6.1版本的API文档的压缩文件。它是中英对照的,可以帮助开发人员更好地理解和使用这个库的功能和算法。 ### 回答2: commons-math3-3.6.1-api文档-中英对照版.zip是Apache Commons Math库的文档。这个文档提供了Apache Commons Math库中各个和方法的详细说明,包括参数、返回值、异常等方面的信息。它是以中英对照的方式呈现,方便中英文用户理解和使用该库。 Apache Commons Math是一个开源的数学库,提供了一系列的数学算法和工具,旨在帮助开发人员解决各种数学问题。这个库包括了统计、线性代数、函数优化、随机数生成等方面的功能。其中,统计模块可以用于计算均值、方差、相关系数等统计量;线性代数模块提供了矩阵运算、线性方程组求解等功能;函数优化模块可以用来寻找函数的最小值或最大值;随机数模块可以生成各种概率分布的随机数。 通过使用Apache Commons Math库,开发人员可以避免自己实现复杂的数学算法,提高开发效率。而文档则是帮助开发人员理解和使用该库的重要工具。commons-math3-3.6.1-api文档-中英对照版.zip提供了方便用户查找和阅读的中英文对照版本,使得使用该库的过程更加顺畅。 ### 回答3: commons-math3-3.6.1-api文档-中英对照版.zip是一个压缩文件,其中包含了Apache Commons Math库版本3.6.1的API文档。这个库是一个开源的Java数学库,提供了许多数学函数和算法,用于解决常见的数学问题。 这个API文档提供了针对每个和方法的详细说明,包括参数、返回值、异常以及使用示例等。中英对照版意味着文档中同时提供了中文和英文的说明,方便开发人员根据自己的语言习惯进行阅读和理解。 通过查阅这个API文档,开发人员可以了解到Apache Commons Math库中每个和方法的功能和用法,从而可以更加高效地利用这个数学库来完成自己的项目开发任务。此外,API文档还提供了丰富的示例代码,帮助开发人员更快地掌握如何正确地使用这些数学函数和算法。 总之,commons-math3-3.6.1-api文档-中英对照版.zip是一个非常实用的文件,提供了Apache Commons Math库版本3.6.1的API文档,方便开发人员学习和使用这个功能强大的数学库。它对于进行数学计算和处理的项目开发者来说是一个宝贵的资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寒水馨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值