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

摘要:中英对照文档、源码赏析、org.apache.commons.math3.analysis.integration.gauss、BaseRuleFactory<T extends Number>、GaussIntegrator、GaussIntegratorFactory、HermiteRuleFactory、LegendreHighPrecisionRuleFactory、LegendreRuleFactory、SymmetricGaussIntegrator

完整中文文档、中英对照文档下载请移步:commons-math3-中文文档、中英对照文档-CSDN下载

1. 开源组件说明

jar包名称:commons-math3-3.6.1.jar

Maven 依赖:

<dependency><groupId>org.apache.commons</groupId><artifactId>commons-math3</artifactId><version>3.6.1</version>
</dependency>

完整中文文档、中英对照文档下载请移步:commons-math3-中文文档、中英对照文档-CSDN下载

程序包 org.apache.commons.math3.analysis.integration.gauss

Gauss family of quadrature schemes.

高斯系列正交计划。

See: 说明

  • 类 Summary  
    说明
    BaseRuleFactory<T extends Number>
    Base class for rules that determines the integration nodes and their weights.

    用于确定集成节点及其权重的规则的基类。

    GaussIntegrator
    Class that implements the Gaussian rule for integrating a weighted function.

    实现用于集成加权函数的高斯规则的类。

    GaussIntegratorFactory
    Class that provides different ways to compute the nodes and weights to be used by the Gaussian integration rule.

    类提供不同方式来计算高斯集成规则要使用的节点和权重。

    HermiteRuleFactory
    Factory that creates a Gauss-type quadrature rule using Hermite polynomials of the first kind.

    使用第一类Hermite多项式创建高斯型正交规则的工厂。

    LegendreHighPrecisionRuleFactory
    Factory that creates Gauss-type quadrature rule using Legendre polynomials.

    使用Legendre多项式创建高斯型正交规则的工厂。

    LegendreRuleFactory
    Factory that creates Gauss-type quadrature rule using Legendre polynomials.

    使用Legendre多项式创建高斯型正交规则的工厂。

    SymmetricGaussIntegrator
    This class's implements integrate method assuming that the integral is symmetric about 0.

    此类的实现将方法集成,假设积分是对称的约0。

程序包 org.apache.commons.math3.analysis.integration.gauss 的说明

Gauss family of quadrature schemes.

高斯系列正交计划。

2. 类 org.apache.commons.math3.analysis.integration.gauss.BaseRuleFactory<T extends Number>

2.1. BaseRuleFactory<T extends Number> 中英对照文档

org.apache.commons.math3.analysis.integration.gauss

类 BaseRuleFactory<T extends Number>

  • java.lang.Object
    • org.apache.commons.math3.analysis.integration.gauss.BaseRuleFactory<T>
  • Type Parameters:
    T - Type of the number used to represent the points and weights of the quadrature rules.

    T - 用于表示正交规则的点和权重的数字的类型。

    Direct Known Subclasses:
    HermiteRuleFactory, LegendreHighPrecisionRuleFactory, LegendreRuleFactory

    冬宫,LegendrehighPrecisionRulefactory,Legendrerulefactory



    public abstract class BaseRuleFactory<T extends Number>
    extends Object
    Base class for rules that determines the integration nodes and their weights. Subclasses must implement the computeRule method.

    用于确定集成节点及其权重的规则的基类。子类必须实现计算机方法。

    从以下版本开始:
    3.1

    3.1

    • 构造器概要

      构造器  
      构造器和说明
      BaseRuleFactory() 
    • 方法概要

      Methods  
      限定符和类型 方法和说明
      protected void addRule(Pair<T[],T[]> rule)

      Stores a rule.

      存储规则。

      protected abstract Pair<T[],T[]> computeRule(int numberOfPoints)

      Computes the rule for the given order.

      计算给定顺序的规则。

      Pair<double[],double[]> getRule(int numberOfPoints)

      Gets a copy of the quadrature rule with the given number of integration points.

      获取具有给定数量的集成点数的正交规则副本。

      protected Pair<T[],T[]> getRuleInternal(int numberOfPoints)

      Gets a rule.

      得到一个规则。

      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    • 构造器详细说明

      • BaseRuleFactory

        public BaseRuleFactory()
    • 方法详细说明

      • getRule

        public Pair<double[],double[]> getRule(int numberOfPoints)throws NotStrictlyPositiveException,DimensionMismatchException
        Gets a copy of the quadrature rule with the given number of integration points.

        获取具有给定数量的集成点数的正交规则副本。

        参数:
        numberOfPoints - Number of integration points.

        NumberOfPoints - 集成点数。

        返回:
        a copy of the integration rule.

        集成规则的副本。

        抛出:
        NotStrictlyPositiveException - if numberOfPoints < 1.

        notstrictypositiveexception - 如果numberofpoints <1。

        DimensionMismatchException - if the elements of the rule pair do not have the same length.

        DimensionMismatchException - 如果规则对的元素没有相同的长度。

      • getRuleInternal

        protected Pair<T[],T[]> getRuleInternal(int numberOfPoints)throws DimensionMismatchException
        Gets a rule. Synchronization ensures that rules will be computed and added to the cache at most once. The returned rule is a reference into the cache.

        得到一个规则。同步可确保最多一次计算规则并将其添加到缓存中。返回的规则是缓存的引用。

        参数:
        numberOfPoints - Order of the rule to be retrieved.

        NumberOfPoints - 要检索的规则的顺序。

        返回:
        the points and weights corresponding to the given order.

        对应于给定顺序的点和权重。

        抛出:
        DimensionMismatchException - if the elements of the rule pair do not have the same length.

        DimensionMismatchException - 如果规则对的元素没有相同的长度。

      • addRule

        protected void addRule(Pair<T[],T[]> rule)throws DimensionMismatchException
        Stores a rule.

        存储规则。

        参数:
        rule - Rule to be stored.

        规则 - 要存储的规则。

        抛出:
        DimensionMismatchException - if the elements of the pair do not have the same length.

        DimensionMismatchException - 如果该对的元素没有相同的长度。

      • computeRule

        protected abstract Pair<T[],T[]> computeRule(int numberOfPoints)throws DimensionMismatchException
        Computes the rule for the given order.

        计算给定顺序的规则。

        参数:
        numberOfPoints - Order of the rule to be computed.

        NumberOfPoints - 要计算规则的顺序。

        返回:
        the computed rule.

        计算规则。

        抛出:
        DimensionMismatchException - if the elements of the pair do not have the same length.

        DimensionMismatchException - 如果该对的元素没有相同的长度。

2.2. BaseRuleFactory<T extends Number> 源码赏析

/** 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.gauss;import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.math3.util.Pair;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.util.LocalizedFormats;/*** Base class for rules that determines the integration nodes and their* weights.* Subclasses must implement the {@link #computeRule(int) computeRule} method.** @param <T> Type of the number used to represent the points and weights of* the quadrature rules.** @since 3.1*/
public abstract class BaseRuleFactory<T extends Number> {/** List of points and weights, indexed by the order of the rule. */private final Map<Integer, Pair<T[], T[]>> pointsAndWeights= new TreeMap<Integer, Pair<T[], T[]>>();/** Cache for double-precision rules. */private final Map<Integer, Pair<double[], double[]>> pointsAndWeightsDouble= new TreeMap<Integer, Pair<double[], double[]>>();/*** Gets a copy of the quadrature rule with the given number of integration* points.** @param numberOfPoints Number of integration points.* @return a copy of the integration rule.* @throws NotStrictlyPositiveException if {@code numberOfPoints < 1}.* @throws DimensionMismatchException if the elements of the rule pair do not* have the same length.*/public Pair<double[], double[]> getRule(int numberOfPoints)throws NotStrictlyPositiveException, DimensionMismatchException {if (numberOfPoints <= 0) {throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS,numberOfPoints);}// Try to obtain the rule from the cache.Pair<double[], double[]> cached = pointsAndWeightsDouble.get(numberOfPoints);if (cached == null) {// Rule not computed yet.// Compute the rule.final Pair<T[], T[]> rule = getRuleInternal(numberOfPoints);cached = convertToDouble(rule);// Cache it.pointsAndWeightsDouble.put(numberOfPoints, cached);}// Return a copy.return new Pair<double[], double[]>(cached.getFirst().clone(),cached.getSecond().clone());}/*** Gets a rule.* Synchronization ensures that rules will be computed and added to the* cache at most once.* The returned rule is a reference into the cache.** @param numberOfPoints Order of the rule to be retrieved.* @return the points and weights corresponding to the given order.* @throws DimensionMismatchException if the elements of the rule pair do not* have the same length.*/protected synchronized Pair<T[], T[]> getRuleInternal(int numberOfPoints)throws DimensionMismatchException {final Pair<T[], T[]> rule = pointsAndWeights.get(numberOfPoints);if (rule == null) {addRule(computeRule(numberOfPoints));// The rule should be available now.return getRuleInternal(numberOfPoints);}return rule;}/*** Stores a rule.** @param rule Rule to be stored.* @throws DimensionMismatchException if the elements of the pair do not* have the same length.*/protected void addRule(Pair<T[], T[]> rule) throws DimensionMismatchException {if (rule.getFirst().length != rule.getSecond().length) {throw new DimensionMismatchException(rule.getFirst().length,rule.getSecond().length);}pointsAndWeights.put(rule.getFirst().length, rule);}/*** Computes the rule for the given order.** @param numberOfPoints Order of the rule to be computed.* @return the computed rule.* @throws DimensionMismatchException if the elements of the pair do not* have the same length.*/protected abstract Pair<T[], T[]> computeRule(int numberOfPoints)throws DimensionMismatchException;/*** Converts the from the actual {@code Number} type to {@code double}** @param <T> Type of the number used to represent the points and* weights of the quadrature rules.* @param rule Points and weights.* @return points and weights as {@code double}s.*/private static <T extends Number> Pair<double[], double[]> convertToDouble(Pair<T[], T[]> rule) {final T[] pT = rule.getFirst();final T[] wT = rule.getSecond();final int len = pT.length;final double[] pD = new double[len];final double[] wD = new double[len];for (int i = 0; i < len; i++) {pD[i] = pT[i].doubleValue();wD[i] = wT[i].doubleValue();}return new Pair<double[], double[]>(pD, wD);}
}

3. 类 org.apache.commons.math3.analysis.integration.gauss.GaussIntegrator

3.1. GaussIntegrator 中英对照文档

org.apache.commons.math3.analysis.integration.gauss

类 GaussIntegrator

  • java.lang.Object
    • org.apache.commons.math3.analysis.integration.gauss.GaussIntegrator
  • Direct Known Subclasses:
    SymmetricGaussIntegrator

    SymmetricgaussIntegrator.


    public class GaussIntegrator
    extends Object
    Class that implements the Gaussian rule for integrating a weighted function.

    实现用于集成加权函数的高斯规则的类。

    从以下版本开始:
    3.1

    3.1

    • 构造器概要

      构造器  
      构造器和说明
      GaussIntegrator(double[] points, double[] weights)

      Creates an integrator from the given points and weights.

      从给定点和权重创建积分器。

      GaussIntegrator(Pair<double[],double[]> pointsAndWeights)

      Creates an integrator from the given pair of points (first element of the pair) and weights (second element of the pair.

      从给定对点(一对的第一元素)和权重(该对的第二个元素)创建积分器。

    • 方法概要

      Methods  
      限定符和类型 方法和说明
      int getNumberOfPoints() 
      double getPoint(int index)

      Gets the integration point at the given index.

      获取给定索引处的集成点。

      double getWeight(int index)

      Gets the weight of the integration point at the given index.

      获取给定索引处的集成点的权重。

      double integrate(UnivariateFunction f)

      Returns an estimate of the integral of f(x) * w(x), where w is a weight function that depends on the actual flavor of the Gauss integration scheme.

      返回F(x)* w(x)的积分的估计,其中w是一种重量函数,其取决于高斯集成方案的实际风味。

      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    • 构造器详细说明

      • GaussIntegrator

        public GaussIntegrator(double[] points,double[] weights)throws NonMonotonicSequenceException,DimensionMismatchException
        Creates an integrator from the given points and weights. The integration interval is defined by the first and last value of points which must be sorted in increasing order.

        从给定点和权重创建积分器。集成间隔由必须按越来顺序排序的点的第一和最后一个值定义。

        参数:
        points - Integration points.

        积分 - 集成点。

        weights - Weights of the corresponding integration nodes.

        权重 - 相应积分节点的权重。

        抛出:
        NonMonotonicSequenceException - if the points are not sorted in increasing order.

        非单调序列exception - 如果点不在越来越顺序排序。

        DimensionMismatchException - if points and weights don't have the same length

        DimensionMismatchException - 如果点和权重没有相同的长度

      • GaussIntegrator

        public GaussIntegrator(Pair<double[],double[]> pointsAndWeights)throws NonMonotonicSequenceException
        Creates an integrator from the given pair of points (first element of the pair) and weights (second element of the pair.

        从给定对点(一对的第一元素)和权重(该对的第二个元素)创建积分器。

        参数:
        pointsAndWeights - Integration points and corresponding weights.

        指点配备 - 集成点和相应的权重。

        抛出:
        NonMonotonicSequenceException - if the points are not sorted in increasing order.

        非单调序列exception - 如果点不在越来越顺序排序。

        另请参阅:
        GaussIntegrator(double[], double[])

        高斯煤矿化器(Double [],Double [])

    • 方法详细说明

      • integrate

        public double integrate(UnivariateFunction f)
        Returns an estimate of the integral of f(x) * w(x), where w is a weight function that depends on the actual flavor of the Gauss integration scheme. The algorithm uses the points and associated weights, as passed to the constructor.

        返回F(x)* w(x)的积分的估计,其中w是一种重量函数,其取决于高斯集成方案的实际风味。该算法使用到构造函数的点和相关权重。

        参数:
        f - Function to integrate.

        f - 集成的功能。

        返回:
        the integral of the weighted function.

        加权函数的积分。

      • getNumberOfPoints

        public int getNumberOfPoints()
        返回:
        the order of the integration rule (the number of integration points).

        集成规则的顺序(集成点数)。

      • getPoint

        public double getPoint(int index)
        Gets the integration point at the given index. The index must be in the valid range but no check is performed.

        获取给定索引处的集成点。索引必须位于有效范围内,但未执行校验。

        参数:
        index - index of the integration point

        索引 - 集成点的索引

        返回:
        the integration point.

        集成点。

      • getWeight

        public double getWeight(int index)
        Gets the weight of the integration point at the given index. The index must be in the valid range but no check is performed.

        获取给定索引处的集成点的权重。索引必须位于有效范围内,但未执行校验。

        参数:
        index - index of the integration point

        索引 - 集成点的索引

        返回:
        the weight.

        重量。

3.2. GaussIntegrator 源码赏析

/** 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.gauss;import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
import org.apache.commons.math3.util.MathArrays;
import org.apache.commons.math3.util.Pair;/*** Class that implements the Gaussian rule for* {@link #integrate(UnivariateFunction) integrating} a weighted* function.** @since 3.1*/
public class GaussIntegrator {/** Nodes. */private final double[] points;/** Nodes weights. */private final double[] weights;/*** Creates an integrator from the given {@code points} and {@code weights}.* The integration interval is defined by the first and last value of* {@code points} which must be sorted in increasing order.** @param points Integration points.* @param weights Weights of the corresponding integration nodes.* @throws NonMonotonicSequenceException if the {@code points} are not* sorted in increasing order.* @throws DimensionMismatchException if points and weights don't have the same length*/public GaussIntegrator(double[] points,double[] weights)throws NonMonotonicSequenceException, DimensionMismatchException {if (points.length != weights.length) {throw new DimensionMismatchException(points.length,weights.length);}MathArrays.checkOrder(points, MathArrays.OrderDirection.INCREASING, true, true);this.points = points.clone();this.weights = weights.clone();}/*** Creates an integrator from the given pair of points (first element of* the pair) and weights (second element of the pair.** @param pointsAndWeights Integration points and corresponding weights.* @throws NonMonotonicSequenceException if the {@code points} are not* sorted in increasing order.** @see #GaussIntegrator(double[], double[])*/public GaussIntegrator(Pair<double[], double[]> pointsAndWeights)throws NonMonotonicSequenceException {this(pointsAndWeights.getFirst(), pointsAndWeights.getSecond());}/*** Returns an estimate of the integral of {@code f(x) * w(x)},* where {@code w} is a weight function that depends on the actual* flavor of the Gauss integration scheme.* The algorithm uses the points and associated weights, as passed* to the {@link #GaussIntegrator(double[],double[]) constructor}.** @param f Function to integrate.* @return the integral of the weighted function.*/public double integrate(UnivariateFunction f) {double s = 0;double c = 0;for (int i = 0; i < points.length; i++) {final double x = points[i];final double w = weights[i];final double y = w * f.value(x) - c;final double t = s + y;c = (t - s) - y;s = t;}return s;}/*** @return the order of the integration rule (the number of integration* points).*/public int getNumberOfPoints() {return points.length;}/*** Gets the integration point at the given index.* The index must be in the valid range but no check is performed.* @param index index of the integration point* @return the integration point.*/public double getPoint(int index) {return points[index];}/*** Gets the weight of the integration point at the given index.* The index must be in the valid range but no check is performed.* @param index index of the integration point* @return the weight.*/public double getWeight(int index) {return weights[index];}
}

4. 类 org.apache.commons.math3.analysis.integration.gauss.GaussIntegratorFactory

4.1. GaussIntegratorFactory 中英对照文档

org.apache.commons.math3.analysis.integration.gauss

类 GaussIntegratorFactory

  • java.lang.Object
    • org.apache.commons.math3.analysis.integration.gauss.GaussIntegratorFactory

  • public class GaussIntegratorFactory
    extends Object
    Class that provides different ways to compute the nodes and weights to be used by the Gaussian integration rule.

    类提供不同方式来计算高斯集成规则要使用的节点和权重。

    从以下版本开始:
    3.1

    3.1

    • 构造器概要

      构造器  
      构造器和说明
      GaussIntegratorFactory() 
    • 方法概要

      Methods  
      限定符和类型 方法和说明
      SymmetricGaussIntegrator hermite(int numberOfPoints)

      Creates a Gauss-Hermite integrator of the given order.

      创建给定订单的高斯 - Hermite Integrator。

      GaussIntegrator legendre(int numberOfPoints)

      Creates a Gauss-Legendre integrator of the given order.

      创建给定订单的Gauss-Legendre Integrator。

      GaussIntegrator legendre(int numberOfPoints, double lowerBound, double upperBound)

      Creates a Gauss-Legendre integrator of the given order.

      创建给定订单的Gauss-Legendre Integrator。

      GaussIntegrator legendreHighPrecision(int numberOfPoints)

      Creates a Gauss-Legendre integrator of the given order.

      创建给定订单的Gauss-Legendre Integrator。

      GaussIntegrator legendreHighPrecision(int numberOfPoints, double lowerBound, double upperBound)

      Creates an integrator of the given order, and whose call to the integrate method will perform an integration on the given interval.

      创建给定顺序的集成器,并且其调用集成方法将在给定间隔上执行集成。

      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    • 构造器详细说明

      • GaussIntegratorFactory

        public GaussIntegratorFactory()
    • 方法详细说明

      • legendre

        public GaussIntegrator legendre(int numberOfPoints)
        Creates a Gauss-Legendre integrator of the given order. The call to the integrate method will perform an integration on the natural interval [-1 , 1].

        创建给定订单的Gauss-Legendre Integrator。对Integrate方法的调用将对自然间隔进行集成[-1,1]。

        参数:
        numberOfPoints - Order of the integration rule.

        NumberOfPoints - 集成规则的顺序。

        返回:
        a Gauss-Legendre integrator.

        一个高斯传奇的集成商。

      • legendre

        public GaussIntegrator legendre(int numberOfPoints,double lowerBound,double upperBound)throws NotStrictlyPositiveException
        Creates a Gauss-Legendre integrator of the given order. The call to the integrate method will perform an integration on the given interval.

        创建给定订单的Gauss-Legendre Integrator。对Integrate方法的调用将对给定间隔执行集成。

        参数:
        numberOfPoints - Order of the integration rule.

        NumberOfPoints - 集成规则的顺序。

        lowerBound - Lower bound of the integration interval.

        积分间隔的低下界限。

        upperBound - Upper bound of the integration interval.

        上行 - 集成间隔的上限。

        返回:
        a Gauss-Legendre integrator.

        一个高斯传奇的集成商。

        抛出:
        NotStrictlyPositiveException - if number of points is not positive

        notstrictypositiveexception - 如果点数不是积极的

      • legendreHighPrecision

        public GaussIntegrator legendreHighPrecision(int numberOfPoints)throws NotStrictlyPositiveException
        Creates a Gauss-Legendre integrator of the given order. The call to the integrate method will perform an integration on the natural interval [-1 , 1].

        创建给定订单的Gauss-Legendre Integrator。对Integrate方法的调用将对自然间隔进行集成[-1,1]。

        参数:
        numberOfPoints - Order of the integration rule.

        NumberOfPoints - 集成规则的顺序。

        返回:
        a Gauss-Legendre integrator.

        一个高斯传奇的集成商。

        抛出:
        NotStrictlyPositiveException - if number of points is not positive

        notstrictypositiveexception - 如果点数不是积极的

      • legendreHighPrecision

        public GaussIntegrator legendreHighPrecision(int numberOfPoints,double lowerBound,double upperBound)throws NotStrictlyPositiveException
        Creates an integrator of the given order, and whose call to the integrate method will perform an integration on the given interval.

        创建给定顺序的集成器,并且其调用集成方法将在给定间隔上执行集成。

        参数:
        numberOfPoints - Order of the integration rule.

        NumberOfPoints - 集成规则的顺序。

        lowerBound - Lower bound of the integration interval.

        积分间隔的低下界限。

        upperBound - Upper bound of the integration interval.

        上行 - 集成间隔的上限。

        返回:
        a Gauss-Legendre integrator.

        一个高斯传奇的集成商。

        抛出:
        NotStrictlyPositiveException - if number of points is not positive

        notstrictypositiveexception - 如果点数不是积极的

      • hermite

        public SymmetricGaussIntegrator hermite(int numberOfPoints)
        Creates a Gauss-Hermite integrator of the given order. The call to the integrate method will perform a weighted integration on the interval \([-\infty, +\infty]\): the computed value is the improper integral of \(e^{-x^2}f(x)\) where \(f(x)\) is the function passed to the integrate method.

        创建给定订单的高斯 - Hermite Integrator。对Integrate方法的调用将在间隔内执行加权集成([ - \ idty,+ \ idty] \):计算值是\(e ^ { - x ^ 2} f(x)的不可分割\)其中\(f(x)\)是传递给Integrate方法的函数。

        参数:
        numberOfPoints - Order of the integration rule.

        NumberOfPoints - 集成规则的顺序。

        返回:
        a Gauss-Hermite integrator.

        高斯 - Hermite Integrator。

4.2. GaussIntegratorFactory 源码赏析

/** 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.gauss;import java.math.BigDecimal;import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.util.Pair;/*** Class that provides different ways to compute the nodes and weights to be* used by the {@link GaussIntegrator Gaussian integration rule}.** @since 3.1*/
public class GaussIntegratorFactory {/** Generator of Gauss-Legendre integrators. */private final BaseRuleFactory<Double> legendre = new LegendreRuleFactory();/** Generator of Gauss-Legendre integrators. */private final BaseRuleFactory<BigDecimal> legendreHighPrecision = new LegendreHighPrecisionRuleFactory();/** Generator of Gauss-Hermite integrators. */private final BaseRuleFactory<Double> hermite = new HermiteRuleFactory();/*** Creates a Gauss-Legendre integrator of the given order.* The call to the* {@link GaussIntegrator#integrate(org.apache.commons.math3.analysis.UnivariateFunction)* integrate} method will perform an integration on the natural interval* {@code [-1 , 1]}.** @param numberOfPoints Order of the integration rule.* @return a Gauss-Legendre integrator.*/public GaussIntegrator legendre(int numberOfPoints) {return new GaussIntegrator(getRule(legendre, numberOfPoints));}/*** Creates a Gauss-Legendre integrator of the given order.* The call to the* {@link GaussIntegrator#integrate(org.apache.commons.math3.analysis.UnivariateFunction)* integrate} method will perform an integration on the given interval.** @param numberOfPoints Order of the integration rule.* @param lowerBound Lower bound of the integration interval.* @param upperBound Upper bound of the integration interval.* @return a Gauss-Legendre integrator.* @throws NotStrictlyPositiveException if number of points is not positive*/public GaussIntegrator legendre(int numberOfPoints,double lowerBound,double upperBound)throws NotStrictlyPositiveException {return new GaussIntegrator(transform(getRule(legendre, numberOfPoints),lowerBound, upperBound));}/*** Creates a Gauss-Legendre integrator of the given order.* The call to the* {@link GaussIntegrator#integrate(org.apache.commons.math3.analysis.UnivariateFunction)* integrate} method will perform an integration on the natural interval* {@code [-1 , 1]}.** @param numberOfPoints Order of the integration rule.* @return a Gauss-Legendre integrator.* @throws NotStrictlyPositiveException if number of points is not positive*/public GaussIntegrator legendreHighPrecision(int numberOfPoints)throws NotStrictlyPositiveException {return new GaussIntegrator(getRule(legendreHighPrecision, numberOfPoints));}/*** Creates an integrator of the given order, and whose call to the* {@link GaussIntegrator#integrate(org.apache.commons.math3.analysis.UnivariateFunction)* integrate} method will perform an integration on the given interval.** @param numberOfPoints Order of the integration rule.* @param lowerBound Lower bound of the integration interval.* @param upperBound Upper bound of the integration interval.* @return a Gauss-Legendre integrator.* @throws NotStrictlyPositiveException if number of points is not positive*/public GaussIntegrator legendreHighPrecision(int numberOfPoints,double lowerBound,double upperBound)throws NotStrictlyPositiveException {return new GaussIntegrator(transform(getRule(legendreHighPrecision, numberOfPoints),lowerBound, upperBound));}/*** Creates a Gauss-Hermite integrator of the given order.* The call to the* {@link SymmetricGaussIntegrator#integrate(org.apache.commons.math3.analysis.UnivariateFunction)* integrate} method will perform a weighted integration on the interval* \([-\infty, +\infty]\): the computed value is the improper integral of* \(e^{-x^2}f(x)\)* where \(f(x)\) is the function passed to the* {@link SymmetricGaussIntegrator#integrate(org.apache.commons.math3.analysis.UnivariateFunction)* integrate} method.** @param numberOfPoints Order of the integration rule.* @return a Gauss-Hermite integrator.*/public SymmetricGaussIntegrator hermite(int numberOfPoints) {return new SymmetricGaussIntegrator(getRule(hermite, numberOfPoints));}/*** @param factory Integration rule factory.* @param numberOfPoints Order of the integration rule.* @return the integration nodes and weights.* @throws NotStrictlyPositiveException if number of points is not positive* @throws DimensionMismatchException if the elements of the rule pair do not* have the same length.*/private static Pair<double[], double[]> getRule(BaseRuleFactory<? extends Number> factory,int numberOfPoints)throws NotStrictlyPositiveException, DimensionMismatchException {return factory.getRule(numberOfPoints);}/*** Performs a change of variable so that the integration can be performed* on an arbitrary interval {@code [a, b]}.* It is assumed that the natural interval is {@code [-1, 1]}.** @param rule Original points and weights.* @param a Lower bound of the integration interval.* @param b Lower bound of the integration interval.* @return the points and weights adapted to the new interval.*/private static Pair<double[], double[]> transform(Pair<double[], double[]> rule,double a,double b) {final double[] points = rule.getFirst();final double[] weights = rule.getSecond();// Scalingfinal double scale = (b - a) / 2;final double shift = a + scale;for (int i = 0; i < points.length; i++) {points[i] = points[i] * scale + shift;weights[i] *= scale;}return new Pair<double[], double[]>(points, weights);}
}

5. 类 org.apache.commons.math3.analysis.integration.gauss.HermiteRuleFactory

5.1. HermiteRuleFactory 中英对照文档

org.apache.commons.math3.analysis.integration.gauss

类 HermiteRuleFactory

  • java.lang.Object
    • org.apache.commons.math3.analysis.integration.gauss.BaseRuleFactory<Double>
      • org.apache.commons.math3.analysis.integration.gauss.HermiteRuleFactory

  • public class HermiteRuleFactory
    extends BaseRuleFactory<Double>
    Factory that creates a Gauss-type quadrature rule using Hermite polynomials of the first kind. Such a quadrature rule allows the calculation of improper integrals of a function

    \(f(x) e^{-x^2}\)

    Recurrence relation and weights computation follow Abramowitz and Stegun, 1964.

    The coefficients of the standard Hermite polynomials grow very rapidly. In order to avoid overflows, each Hermite polynomial is normalized with respect to the underlying scalar product. The initial interval for the application of the bisection method is based on the roots of the previous Hermite polynomial (interlacing). Upper and lower bounds of these roots are provided by

    I. Krasikov, Nonnegative quadratic forms and bounds on orthogonal polynomials, Journal of Approximation theory 111, 31-49

    使用第一类Hermite多项式创建高斯型正交规则的工厂。这种正交规则允许计算函数的不正确积分\(f(x)e ^ { - x ^ 2}的复发关系和权重计算遵循abramowitz和stegun,1964年。标准Hermite多项式的系数非常生长迅速。为了避免溢出,每个Hermite多项式相对于下面的标量产品归一化。用于施加二分法的初始间隔基于先前的Hermite多项式(交织)的根。这些根的上限和下界由I. Krasikov,非负二次形式和正交多项式的界限提供,近似理论111,31-49

    从以下版本开始:
    3.3

    3.3

    • 构造器概要

      构造器  
      构造器和说明
      HermiteRuleFactory() 
    • 方法概要

      Methods  
      限定符和类型 方法和说明
      protected Pair<Double[],Double[]> computeRule(int numberOfPoints)

      Computes the rule for the given order.

      计算给定顺序的规则。

      • 从类继承的方法 org.apache.commons.math3.analysis.integration.gauss.BaseRuleFactory

        addRule, getRule, getRuleInternal

      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    • 构造器详细说明

      • HermiteRuleFactory

        public HermiteRuleFactory()
    • 方法详细说明

      • computeRule

        protected Pair<Double[],Double[]> computeRule(int numberOfPoints)throws DimensionMismatchException
        Computes the rule for the given order.

        计算给定顺序的规则。

        指定者:
        computeRule in class  BaseRuleFactory<Double>

        Computer BaseRulefactory

        参数:
        numberOfPoints - Order of the rule to be computed.

        NumberOfPoints - 要计算规则的顺序。

        返回:
        the computed rule.

        计算规则。

        抛出:
        DimensionMismatchException - if the elements of the pair do not have the same length.

        DimensionMismatchException - 如果该对的元素没有相同的长度。

5.2. HermiteRuleFactory 源码赏析

/** 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.gauss;import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.util.Pair;
import org.apache.commons.math3.util.FastMath;/*** Factory that creates a* <a href="http://en.wikipedia.org/wiki/Gauss-Hermite_quadrature">* Gauss-type quadrature rule using Hermite polynomials</a>* of the first kind.* Such a quadrature rule allows the calculation of improper integrals* of a function* <p>*  \(f(x) e^{-x^2}\)* </p><p>* Recurrence relation and weights computation follow* <a href="http://en.wikipedia.org/wiki/Abramowitz_and_Stegun">* Abramowitz and Stegun, 1964</a>.* </p><p>* The coefficients of the standard Hermite polynomials grow very rapidly.* In order to avoid overflows, each Hermite polynomial is normalized with* respect to the underlying scalar product.* The initial interval for the application of the bisection method is* based on the roots of the previous Hermite polynomial (interlacing).* Upper and lower bounds of these roots are provided by </p>* <blockquote>*  I. Krasikov,*  <em>Nonnegative quadratic forms and bounds on orthogonal polynomials</em>,*  Journal of Approximation theory <b>111</b>, 31-49* </blockquote>** @since 3.3*/
public class HermiteRuleFactory extends BaseRuleFactory<Double> {/** &pi;<sup>1/2</sup> */private static final double SQRT_PI = 1.77245385090551602729;/** &pi;<sup>-1/4</sup> */private static final double H0 = 7.5112554446494248286e-1;/** &pi;<sup>-1/4</sup> &radic;2 */private static final double H1 = 1.0622519320271969145;/** {@inheritDoc} */@Overrideprotected Pair<Double[], Double[]> computeRule(int numberOfPoints)throws DimensionMismatchException {if (numberOfPoints == 1) {// Break recursion.return new Pair<Double[], Double[]>(new Double[] { 0d },new Double[] { SQRT_PI });}// Get previous rule.// If it has not been computed yet it will trigger a recursive call// to this method.final int lastNumPoints = numberOfPoints - 1;final Double[] previousPoints = getRuleInternal(lastNumPoints).getFirst();// Compute next rule.final Double[] points = new Double[numberOfPoints];final Double[] weights = new Double[numberOfPoints];final double sqrtTwoTimesLastNumPoints = FastMath.sqrt(2 * lastNumPoints);final double sqrtTwoTimesNumPoints = FastMath.sqrt(2 * numberOfPoints);// Find i-th root of H[n+1] by bracketing.final int iMax = numberOfPoints / 2;for (int i = 0; i < iMax; i++) {// Lower-bound of the interval.double a = (i == 0) ? -sqrtTwoTimesLastNumPoints : previousPoints[i - 1].doubleValue();// Upper-bound of the interval.double b = (iMax == 1) ? -0.5 : previousPoints[i].doubleValue();// H[j-1](a)double hma = H0;// H[j](a)double ha = H1 * a;// H[j-1](b)double hmb = H0;// H[j](b)double hb = H1 * b;for (int j = 1; j < numberOfPoints; j++) {// Compute H[j+1](a) and H[j+1](b)final double jp1 = j + 1;final double s = FastMath.sqrt(2 / jp1);final double sm = FastMath.sqrt(j / jp1);final double hpa = s * a * ha - sm * hma;final double hpb = s * b * hb - sm * hmb;hma = ha;ha = hpa;hmb = hb;hb = hpb;}// Now ha = H[n+1](a), and hma = H[n](a) (same holds for b).// Middle of the interval.double c = 0.5 * (a + b);// P[j-1](c)double hmc = H0;// P[j](c)double hc = H1 * c;boolean done = false;while (!done) {done = b - a <= Math.ulp(c);hmc = H0;hc = H1 * c;for (int j = 1; j < numberOfPoints; j++) {// Compute H[j+1](c)final double jp1 = j + 1;final double s = FastMath.sqrt(2 / jp1);final double sm = FastMath.sqrt(j / jp1);final double hpc = s * c * hc - sm * hmc;hmc = hc;hc = hpc;}// Now h = H[n+1](c) and hm = H[n](c).if (!done) {if (ha * hc < 0) {b = c;hmb = hmc;hb = hc;} else {a = c;hma = hmc;ha = hc;}c = 0.5 * (a + b);}}final double d = sqrtTwoTimesNumPoints * hmc;final double w = 2 / (d * d);points[i] = c;weights[i] = w;final int idx = lastNumPoints - i;points[idx] = -c;weights[idx] = w;}// If "numberOfPoints" is odd, 0 is a root.// Note: as written, the test for oddness will work for negative// integers too (although it is not necessary here), preventing// a FindBugs warning.if (numberOfPoints % 2 != 0) {double hm = H0;for (int j = 1; j < numberOfPoints; j += 2) {final double jp1 = j + 1;hm = -FastMath.sqrt(j / jp1) * hm;}final double d = sqrtTwoTimesNumPoints * hm;final double w = 2 / (d * d);points[iMax] = 0d;weights[iMax] = w;}return new Pair<Double[], Double[]>(points, weights);}
}

6. 类 org.apache.commons.math3.analysis.integration.gauss.LegendreHighPrecisionRuleFactory

6.1. LegendreHighPrecisionRuleFactory 中英对照文档

org.apache.commons.math3.analysis.integration.gauss

类 LegendreHighPrecisionRuleFactory

  • java.lang.Object
    • org.apache.commons.math3.analysis.integration.gauss.BaseRuleFactory<BigDecimal>
      • org.apache.commons.math3.analysis.integration.gauss.LegendreHighPrecisionRuleFactory

  • public class LegendreHighPrecisionRuleFactory
    extends BaseRuleFactory<BigDecimal>
    Factory that creates Gauss-type quadrature rule using Legendre polynomials. In this implementation, the lower and upper bounds of the natural interval of integration are -1 and 1, respectively. The Legendre polynomials are evaluated using the recurrence relation presented in Abramowitz and Stegun, 1964.

    使用Legendre多项式创建高斯型正交规则的工厂。在该实现中,集成自然间隔的下限和上限分别为-1和1。使用Abramowitz和Setegun,1964年的复发关系评估了图例多项式。

    从以下版本开始:
    3.1

    3.1

    • 构造器概要

      构造器  
      构造器和说明
      LegendreHighPrecisionRuleFactory()

      Default precision is DECIMAL128.

      默认精度为DECIMA1128。

      LegendreHighPrecisionRuleFactory(MathContext mContext) 
    • 方法概要

      Methods  
      限定符和类型 方法和说明
      protected Pair<BigDecimal[],BigDecimal[]> computeRule(int numberOfPoints)

      Computes the rule for the given order.

      计算给定顺序的规则。

      • 从类继承的方法 org.apache.commons.math3.analysis.integration.gauss.BaseRuleFactory

        addRule, getRule, getRuleInternal

      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    • 构造器详细说明

      • LegendreHighPrecisionRuleFactory

        public LegendreHighPrecisionRuleFactory()
        Default precision is DECIMAL128.

        默认精度为DECIMA1128。

      • LegendreHighPrecisionRuleFactory

        public LegendreHighPrecisionRuleFactory(MathContext mContext)
        参数:
        mContext - Precision setting for computing the quadrature rules.

        Mcontext - 计算正交规则的精度设置。

    • 方法详细说明

      • computeRule

        protected Pair<BigDecimal[],BigDecimal[]> computeRule(int numberOfPoints)throws DimensionMismatchException
        Computes the rule for the given order.

        计算给定顺序的规则。

        指定者:
        computeRule in class  BaseRuleFactory<BigDecimal>

        Computer baseRulefactory

        参数:
        numberOfPoints - Order of the rule to be computed.

        NumberOfPoints - 要计算规则的顺序。

        返回:
        the computed rule.

        计算规则。

        抛出:
        DimensionMismatchException - if the elements of the pair do not have the same length.

        DimensionMismatchException - 如果该对的元素没有相同的长度。

6.2. LegendreHighPrecisionRuleFactory 源码赏析

/** 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.gauss;import java.math.BigDecimal;
import java.math.MathContext;import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.util.Pair;/*** Factory that creates Gauss-type quadrature rule using Legendre polynomials.* In this implementation, the lower and upper bounds of the natural interval* of integration are -1 and 1, respectively.* The Legendre polynomials are evaluated using the recurrence relation* presented in <a href="http://en.wikipedia.org/wiki/Abramowitz_and_Stegun">* Abramowitz and Stegun, 1964</a>.** @since 3.1*/
public class LegendreHighPrecisionRuleFactory extends BaseRuleFactory<BigDecimal> {/** Settings for enhanced precision computations. */private final MathContext mContext;/** The number {@code 2}. */private final BigDecimal two;/** The number {@code -1}. */private final BigDecimal minusOne;/** The number {@code 0.5}. */private final BigDecimal oneHalf;/*** Default precision is {@link MathContext#DECIMAL128 DECIMAL128}.*/public LegendreHighPrecisionRuleFactory() {this(MathContext.DECIMAL128);}/*** @param mContext Precision setting for computing the quadrature rules.*/public LegendreHighPrecisionRuleFactory(MathContext mContext) {this.mContext = mContext;two = new BigDecimal("2", mContext);minusOne = new BigDecimal("-1", mContext);oneHalf = new BigDecimal("0.5", mContext);}/** {@inheritDoc} */@Overrideprotected Pair<BigDecimal[], BigDecimal[]> computeRule(int numberOfPoints)throws DimensionMismatchException {if (numberOfPoints == 1) {// Break recursion.return new Pair<BigDecimal[], BigDecimal[]>(new BigDecimal[] { BigDecimal.ZERO },new BigDecimal[] { two });}// Get previous rule.// If it has not been computed yet it will trigger a recursive call// to this method.final BigDecimal[] previousPoints = getRuleInternal(numberOfPoints - 1).getFirst();// Compute next rule.final BigDecimal[] points = new BigDecimal[numberOfPoints];final BigDecimal[] weights = new BigDecimal[numberOfPoints];// Find i-th root of P[n+1] by bracketing.final int iMax = numberOfPoints / 2;for (int i = 0; i < iMax; i++) {// Lower-bound of the interval.BigDecimal a = (i == 0) ? minusOne : previousPoints[i - 1];// Upper-bound of the interval.BigDecimal b = (iMax == 1) ? BigDecimal.ONE : previousPoints[i];// P[j-1](a)BigDecimal pma = BigDecimal.ONE;// P[j](a)BigDecimal pa = a;// P[j-1](b)BigDecimal pmb = BigDecimal.ONE;// P[j](b)BigDecimal pb = b;for (int j = 1; j < numberOfPoints; j++) {final BigDecimal b_two_j_p_1 = new BigDecimal(2 * j + 1, mContext);final BigDecimal b_j = new BigDecimal(j, mContext);final BigDecimal b_j_p_1 = new BigDecimal(j + 1, mContext);// Compute P[j+1](a)// ppa = ((2 * j + 1) * a * pa - j * pma) / (j + 1);BigDecimal tmp1 = a.multiply(b_two_j_p_1, mContext);tmp1 = pa.multiply(tmp1, mContext);BigDecimal tmp2 = pma.multiply(b_j, mContext);// P[j+1](a)BigDecimal ppa = tmp1.subtract(tmp2, mContext);ppa = ppa.divide(b_j_p_1, mContext);// Compute P[j+1](b)// ppb = ((2 * j + 1) * b * pb - j * pmb) / (j + 1);tmp1 = b.multiply(b_two_j_p_1, mContext);tmp1 = pb.multiply(tmp1, mContext);tmp2 = pmb.multiply(b_j, mContext);// P[j+1](b)BigDecimal ppb = tmp1.subtract(tmp2, mContext);ppb = ppb.divide(b_j_p_1, mContext);pma = pa;pa = ppa;pmb = pb;pb = ppb;}// Now pa = P[n+1](a), and pma = P[n](a). Same holds for b.// Middle of the interval.BigDecimal c = a.add(b, mContext).multiply(oneHalf, mContext);// P[j-1](c)BigDecimal pmc = BigDecimal.ONE;// P[j](c)BigDecimal pc = c;boolean done = false;while (!done) {BigDecimal tmp1 = b.subtract(a, mContext);BigDecimal tmp2 = c.ulp().multiply(BigDecimal.TEN, mContext);done = tmp1.compareTo(tmp2) <= 0;pmc = BigDecimal.ONE;pc = c;for (int j = 1; j < numberOfPoints; j++) {final BigDecimal b_two_j_p_1 = new BigDecimal(2 * j + 1, mContext);final BigDecimal b_j = new BigDecimal(j, mContext);final BigDecimal b_j_p_1 = new BigDecimal(j + 1, mContext);// Compute P[j+1](c)tmp1 = c.multiply(b_two_j_p_1, mContext);tmp1 = pc.multiply(tmp1, mContext);tmp2 = pmc.multiply(b_j, mContext);// P[j+1](c)BigDecimal ppc = tmp1.subtract(tmp2, mContext);ppc = ppc.divide(b_j_p_1, mContext);pmc = pc;pc = ppc;}// Now pc = P[n+1](c) and pmc = P[n](c).if (!done) {if (pa.signum() * pc.signum() <= 0) {b = c;pmb = pmc;pb = pc;} else {a = c;pma = pmc;pa = pc;}c = a.add(b, mContext).multiply(oneHalf, mContext);}}final BigDecimal nP = new BigDecimal(numberOfPoints, mContext);BigDecimal tmp1 = pmc.subtract(c.multiply(pc, mContext), mContext);tmp1 = tmp1.multiply(nP);tmp1 = tmp1.pow(2, mContext);BigDecimal tmp2 = c.pow(2, mContext);tmp2 = BigDecimal.ONE.subtract(tmp2, mContext);tmp2 = tmp2.multiply(two, mContext);tmp2 = tmp2.divide(tmp1, mContext);points[i] = c;weights[i] = tmp2;final int idx = numberOfPoints - i - 1;points[idx] = c.negate(mContext);weights[idx] = tmp2;}// If "numberOfPoints" is odd, 0 is a root.// Note: as written, the test for oddness will work for negative// integers too (although it is not necessary here), preventing// a FindBugs warning.if (numberOfPoints % 2 != 0) {BigDecimal pmc = BigDecimal.ONE;for (int j = 1; j < numberOfPoints; j += 2) {final BigDecimal b_j = new BigDecimal(j, mContext);final BigDecimal b_j_p_1 = new BigDecimal(j + 1, mContext);// pmc = -j * pmc / (j + 1);pmc = pmc.multiply(b_j, mContext);pmc = pmc.divide(b_j_p_1, mContext);pmc = pmc.negate(mContext);}// 2 / pow(numberOfPoints * pmc, 2);final BigDecimal nP = new BigDecimal(numberOfPoints, mContext);BigDecimal tmp1 = pmc.multiply(nP, mContext);tmp1 = tmp1.pow(2, mContext);BigDecimal tmp2 = two.divide(tmp1, mContext);points[iMax] = BigDecimal.ZERO;weights[iMax] = tmp2;}return new Pair<BigDecimal[], BigDecimal[]>(points, weights);}
}

7. 类 org.apache.commons.math3.analysis.integration.gauss.LegendreRuleFactory

7.1. LegendreRuleFactory 中英对照文档

org.apache.commons.math3.analysis.integration.gauss

类 LegendreRuleFactory

  • java.lang.Object
    • org.apache.commons.math3.analysis.integration.gauss.BaseRuleFactory<Double>
      • org.apache.commons.math3.analysis.integration.gauss.LegendreRuleFactory

  • public class LegendreRuleFactory
    extends BaseRuleFactory<Double>
    Factory that creates Gauss-type quadrature rule using Legendre polynomials. In this implementation, the lower and upper bounds of the natural interval of integration are -1 and 1, respectively. The Legendre polynomials are evaluated using the recurrence relation presented in Abramowitz and Stegun, 1964.

    使用Legendre多项式创建高斯型正交规则的工厂。在该实现中,集成自然间隔的下限和上限分别为-1和1。使用Abramowitz和Setegun,1964年的复发关系评估了图例多项式。

    从以下版本开始:
    3.1

    3.1

    • 构造器概要

      构造器  
      构造器和说明
      LegendreRuleFactory() 
    • 方法概要

      Methods  
      限定符和类型 方法和说明
      protected Pair<Double[],Double[]> computeRule(int numberOfPoints)

      Computes the rule for the given order.

      计算给定顺序的规则。

      • 从类继承的方法 org.apache.commons.math3.analysis.integration.gauss.BaseRuleFactory

        addRule, getRule, getRuleInternal

      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    • 构造器详细说明

      • LegendreRuleFactory

        public LegendreRuleFactory()
    • 方法详细说明

      • computeRule

        protected Pair<Double[],Double[]> computeRule(int numberOfPoints)throws DimensionMismatchException
        Computes the rule for the given order.

        计算给定顺序的规则。

        指定者:
        computeRule in class  BaseRuleFactory<Double>

        Computer BaseRulefactory

        参数:
        numberOfPoints - Order of the rule to be computed.

        NumberOfPoints - 要计算规则的顺序。

        返回:
        the computed rule.

        计算规则。

        抛出:
        DimensionMismatchException - if the elements of the pair do not have the same length.

        DimensionMismatchException - 如果该对的元素没有相同的长度。

7.2. LegendreRuleFactory 源码赏析

/** 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.gauss;import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.util.Pair;/*** Factory that creates Gauss-type quadrature rule using Legendre polynomials.* In this implementation, the lower and upper bounds of the natural interval* of integration are -1 and 1, respectively.* The Legendre polynomials are evaluated using the recurrence relation* presented in <a href="http://en.wikipedia.org/wiki/Abramowitz_and_Stegun">* Abramowitz and Stegun, 1964</a>.** @since 3.1*/
public class LegendreRuleFactory extends BaseRuleFactory<Double> {/** {@inheritDoc} */@Overrideprotected Pair<Double[], Double[]> computeRule(int numberOfPoints)throws DimensionMismatchException {if (numberOfPoints == 1) {// Break recursion.return new Pair<Double[], Double[]>(new Double[] { 0d },new Double[] { 2d });}// Get previous rule.// If it has not been computed yet it will trigger a recursive call// to this method.final Double[] previousPoints = getRuleInternal(numberOfPoints - 1).getFirst();// Compute next rule.final Double[] points = new Double[numberOfPoints];final Double[] weights = new Double[numberOfPoints];// Find i-th root of P[n+1] by bracketing.final int iMax = numberOfPoints / 2;for (int i = 0; i < iMax; i++) {// Lower-bound of the interval.double a = (i == 0) ? -1 : previousPoints[i - 1].doubleValue();// Upper-bound of the interval.double b = (iMax == 1) ? 1 : previousPoints[i].doubleValue();// P[j-1](a)double pma = 1;// P[j](a)double pa = a;// P[j-1](b)double pmb = 1;// P[j](b)double pb = b;for (int j = 1; j < numberOfPoints; j++) {final int two_j_p_1 = 2 * j + 1;final int j_p_1 = j + 1;// P[j+1](a)final double ppa = (two_j_p_1 * a * pa - j * pma) / j_p_1;// P[j+1](b)final double ppb = (two_j_p_1 * b * pb - j * pmb) / j_p_1;pma = pa;pa = ppa;pmb = pb;pb = ppb;}// Now pa = P[n+1](a), and pma = P[n](a) (same holds for b).// Middle of the interval.double c = 0.5 * (a + b);// P[j-1](c)double pmc = 1;// P[j](c)double pc = c;boolean done = false;while (!done) {done = b - a <= Math.ulp(c);pmc = 1;pc = c;for (int j = 1; j < numberOfPoints; j++) {// P[j+1](c)final double ppc = ((2 * j + 1) * c * pc - j * pmc) / (j + 1);pmc = pc;pc = ppc;}// Now pc = P[n+1](c) and pmc = P[n](c).if (!done) {if (pa * pc <= 0) {b = c;pmb = pmc;pb = pc;} else {a = c;pma = pmc;pa = pc;}c = 0.5 * (a + b);}}final double d = numberOfPoints * (pmc - c * pc);final double w = 2 * (1 - c * c) / (d * d);points[i] = c;weights[i] = w;final int idx = numberOfPoints - i - 1;points[idx] = -c;weights[idx] = w;}// If "numberOfPoints" is odd, 0 is a root.// Note: as written, the test for oddness will work for negative// integers too (although it is not necessary here), preventing// a FindBugs warning.if (numberOfPoints % 2 != 0) {double pmc = 1;for (int j = 1; j < numberOfPoints; j += 2) {pmc = -j * pmc / (j + 1);}final double d = numberOfPoints * pmc;final double w = 2 / (d * d);points[iMax] = 0d;weights[iMax] = w;}return new Pair<Double[], Double[]>(points, weights);}
}

8. 类 org.apache.commons.math3.analysis.integration.gauss.SymmetricGaussIntegrator

8.1. SymmetricGaussIntegrator 中英对照文档

org.apache.commons.math3.analysis.integration.gauss

类 SymmetricGaussIntegrator

  • java.lang.Object
    • org.apache.commons.math3.analysis.integration.gauss.GaussIntegrator
      • org.apache.commons.math3.analysis.integration.gauss.SymmetricGaussIntegrator

  • public class SymmetricGaussIntegrator
    extends GaussIntegrator
    This class's implements integrate method assuming that the integral is symmetric about 0. This allows to reduce numerical errors.

    此类实现将方法集成了,假设积分是对称的约0.这允许减少数值误差。

    从以下版本开始:
    3.3

    3.3

    • 构造器概要

      构造器  
      构造器和说明
      SymmetricGaussIntegrator(double[] points, double[] weights)

      Creates an integrator from the given points and weights.

      从给定点和权重创建积分器。

      SymmetricGaussIntegrator(Pair<double[],double[]> pointsAndWeights)

      Creates an integrator from the given pair of points (first element of the pair) and weights (second element of the pair.

      从给定对点(一对的第一元素)和权重(该对的第二个元素)创建积分器。

    • 方法概要

      Methods  
      限定符和类型 方法和说明
      double integrate(UnivariateFunction f)

      Returns an estimate of the integral of f(x) * w(x), where w is a weight function that depends on the actual flavor of the Gauss integration scheme.

      返回F(x)* w(x)的积分的估计,其中w是一种重量函数,其取决于高斯集成方案的实际风味。

      • 从类继承的方法 org.apache.commons.math3.analysis.integration.gauss.GaussIntegrator

        getNumberOfPoints, getPoint, getWeight

      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    • 构造器详细说明

      • SymmetricGaussIntegrator

        public SymmetricGaussIntegrator(double[] points,double[] weights)throws NonMonotonicSequenceException,DimensionMismatchException
        Creates an integrator from the given points and weights. The integration interval is defined by the first and last value of points which must be sorted in increasing order.

        从给定点和权重创建积分器。集成间隔由必须按越来顺序排序的点的第一和最后一个值定义。

        参数:
        points - Integration points.

        积分 - 集成点。

        weights - Weights of the corresponding integration nodes.

        权重 - 相应积分节点的权重。

        抛出:
        NonMonotonicSequenceException - if the points are not sorted in increasing order.

        非单调序列exception - 如果点不在越来越顺序排序。

        DimensionMismatchException - if points and weights don't have the same length

        DimensionMismatchException - 如果点和权重没有相同的长度

      • SymmetricGaussIntegrator

        public SymmetricGaussIntegrator(Pair<double[],double[]> pointsAndWeights)throws NonMonotonicSequenceException
        Creates an integrator from the given pair of points (first element of the pair) and weights (second element of the pair.

        从给定对点(一对的第一元素)和权重(该对的第二个元素)创建积分器。

        参数:
        pointsAndWeights - Integration points and corresponding weights.

        指点配备 - 集成点和相应的权重。

        抛出:
        NonMonotonicSequenceException - if the points are not sorted in increasing order.

        非单调序列exception - 如果点不在越来越顺序排序。

        另请参阅:
        SymmetricGaussIntegrator(double[], double[])

        SymmetricgaussIntegrator(Double [],Double [])

    • 方法详细说明

      • integrate

        public double integrate(UnivariateFunction f)
        Returns an estimate of the integral of f(x) * w(x), where w is a weight function that depends on the actual flavor of the Gauss integration scheme. The algorithm uses the points and associated weights, as passed to the constructor.

        返回F(x)* w(x)的积分的估计,其中w是一种重量函数,其取决于高斯集成方案的实际风味。该算法使用到构造函数的点和相关权重。

        重写:
        integrate in class  GaussIntegrator

        整合在课堂高斯煤矿

        参数:
        f - Function to integrate.

        f - 集成的功能。

        返回:
        the integral of the weighted function.

        加权函数的积分。

8.2. SymmetricGaussIntegrator 源码赏析

/** 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.gauss;import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
import org.apache.commons.math3.util.Pair;/*** This class's implements {@link #integrate(UnivariateFunction) integrate}* method assuming that the integral is symmetric about 0.* This allows to reduce numerical errors.** @since 3.3*/
public class SymmetricGaussIntegrator extends GaussIntegrator {/*** Creates an integrator from the given {@code points} and {@code weights}.* The integration interval is defined by the first and last value of* {@code points} which must be sorted in increasing order.** @param points Integration points.* @param weights Weights of the corresponding integration nodes.* @throws NonMonotonicSequenceException if the {@code points} are not* sorted in increasing order.* @throws DimensionMismatchException if points and weights don't have the same length*/public SymmetricGaussIntegrator(double[] points,double[] weights)throws NonMonotonicSequenceException, DimensionMismatchException {super(points, weights);}/*** Creates an integrator from the given pair of points (first element of* the pair) and weights (second element of the pair.** @param pointsAndWeights Integration points and corresponding weights.* @throws NonMonotonicSequenceException if the {@code points} are not* sorted in increasing order.** @see #SymmetricGaussIntegrator(double[], double[])*/public SymmetricGaussIntegrator(Pair<double[], double[]> pointsAndWeights)throws NonMonotonicSequenceException {this(pointsAndWeights.getFirst(), pointsAndWeights.getSecond());}/*** {@inheritDoc}*/@Overridepublic double integrate(UnivariateFunction f) {final int ruleLength = getNumberOfPoints();if (ruleLength == 1) {return getWeight(0) * f.value(0d);}final int iMax = ruleLength / 2;double s = 0;double c = 0;for (int i = 0; i < iMax; i++) {final double p = getPoint(i);final double w = getWeight(i);final double f1 = f.value(p);final double f2 = f.value(-p);final double y = w * (f1 + f2) - c;final double t = s + y;c = (t - s) - y;s = t;}if (ruleLength % 2 != 0) {final double w = getWeight(iMax);final double y = w * f.value(0d) - c;final double t = s + y;s = t;}return s;}
}

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

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

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

  2. commons-math3-3.6.1-org.apache.commons.math3.analysis.differentiation-包下的接口-中英对照文档及源码赏析

    commons-math3-3.6.1-org.apache.commons.math3.analysis.differentiation-包下的接口-中英对照文档及源码赏析 摘要:中英对照文档.源码 ...

  3. commons-math3-3.6.1-org.apache.commons.math3.analysis.function-包下的类(三)-中英对照文档及源码赏析

    commons-math3-3.6.1-org.apache.commons.math3.analysis.function-包下的类(三)-中英对照文档及源码赏析 摘要:中英对照文档.源码赏析.or ...

  4. commons-math3-3.6.1-org.apache.commons.math3.analysis.function-包下的类(二)-中英对照文档及源码赏析

    commons-math3-3.6.1-org.apache.commons.math3.analysis.function-包下的类(二)-中英对照文档及源码赏析 摘要:中英对照文档.源码赏析.or ...

  5. Apache POI 生成折线图+柱状图设置双Y轴并导出word文档

    实际项目中遇到的问题,相关信息实在较少,怕自己忘记,菜鸟记录一下 我设置的是双Y轴的组和图表.左侧为折线图Y轴,右侧为柱状图Y轴. 直接上代码. // An highlighted block pub ...

  6. 文档处理工具库——Apache POI的使用

    Apache POI工具包可用来出来microsoft office办公套件中的Word文档,excel文档,ppt文档以及visio文档等,直接使用maven导入jar包即可使用. 目录 1.处理e ...

  7. Apache Commons Math3学习笔记(2) - 多项式曲线拟合(转)

    多项式曲线拟合:org.apache.commons.math3.fitting.PolynomialCurveFitter类. 用法示例代码: [java] view plain copy   // ...

  8. 如何在Java中正确使用Apache Commons数学库中的ZipfDistribution?

    java   apache-commons-math   zipf 温馨提示:将鼠标放在语句上可以显示对应的英文.   或者   切换至中英文显示 我想基于遵循Zipf分布的单词(来自字典)创建数据源 ...

  9. Apache Commons Pool 故事一则 专题

    Apache Commons Pool 故事一则 最近工作中遇到一个由于对commons-pool的使用不当而引发的问题,习得正确的使用姿势后,写下这个简单的故事,帮助理解Apache Commons ...

最新文章

  1. hive on tez踩坑记2-hive0.14 on tez
  2. Part2_3 正则表达式、Excel表格相关操作
  3. MFC框架类、文档类、视图类相互访问(及窗口句柄获取)的方法
  4. hdu-1104-Remainder(BFS打印路径+数论)(%与mod的区别)
  5. Django基础一之web框架的本质
  6. Flink流计算编程--在WindowedStream中体会EventTime与ProcessingTime
  7. 剑指offer之链表续
  8. 七、线性表的链式存储结构
  9. 深拷贝与浅拷贝的区别
  10. 图像处理 之 同态滤波
  11. python之数据运算、字典、列表
  12. asp 后台批量管理程序
  13. 基于snowflake的Id序列号生成器
  14. 2018全球最值得关注的60家半导体公司,7家中国公司新上榜 | 年度榜单
  15. win10电脑磁盘占用百分百,电脑优化
  16. Learning Premiere Elements 15 Premiere Elements 15教程 Lynda课程中文字幕
  17. 华三华为设备序列号查看生产日期
  18. 微信Android客户端后台保活经验分享
  19. 实体消歧、实体统一和指代消歧
  20. LiveNVR传统视频监控互联网无插件-按需直播最大利用有效上行

热门文章

  1. 欢迎大家收听喜马拉雅,我的主播频道http://m.ximalaya.com/weizhubo/44966139
  2. 运用小数据逆袭,一家地区超市让沃尔玛甘拜下风
  3. Mac M1 pro 安装 python2 教程
  4. 激光雷达A1M8与STM32通信
  5. 关于向量的期望值、均值向量和协方差矩阵
  6. Think PHP 5 实现短信发送 此API为京东万象
  7. C语言if-break,if-continue和if-return区别
  8. JavaScript - 对象专用语句[ with语句 ]
  9. 学习能力篇:为什么你一定要知道学贵有法和学无定法?
  10. 互联网行业喜欢推陈出新,玩概念,各种新词层出不穷