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

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

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.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 voidaddRule(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.

      得到一个规则。

    • 构造器详细说明
      • 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  
      限定符和类型方法和说明
      intgetNumberOfPoints() 
      doublegetPoint(int index)
      Gets the integration point at the given index.

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

      doublegetWeight(int index)
      Gets the weight of the integration point at the given index.

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

      doubleintegrate(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是一种重量函数,其取决于高斯集成方案的实际风味。

    • 构造器详细说明
      • 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  
      限定符和类型方法和说明
      SymmetricGaussIntegratorhermite(int numberOfPoints)
      Creates a Gauss-Hermite integrator of the given order.

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

      GaussIntegratorlegendre(int numberOfPoints)
      Creates a Gauss-Legendre integrator of the given order.

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

      GaussIntegratorlegendre(int numberOfPoints, double lowerBound, double upperBound)
      Creates a Gauss-Legendre integrator of the given order.

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

      GaussIntegratorlegendreHighPrecision(int numberOfPoints)
      Creates a Gauss-Legendre integrator of the given order.

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

      GaussIntegratorlegendreHighPrecision(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.

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

    • 构造器详细说明
      • 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();

        // Scaling
        final 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


  • 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
        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} */
    @Override
    protected 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


  • 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
        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} */
    @Override
    protected 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


  • 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
        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} */
    @Override
    protected 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


  • 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  
      限定符和类型方法和说明
      doubleintegrate(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
    • 构造器详细说明
      • 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}
     */
    @Override
    public 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;
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: commons-math3-3.6.1-api文档-对照版.zip是一个Commons Math库3.6.1版本的API文档的压缩文件。Commons Math是一个Java库,提供了许多数学功能和算法的实现。 API文档是帮助开发人员理解库可用的类、方法和属性的官方文档。它提供了关于每个类的详细说明,括类的用途、方法的功能、参数和返回值的说明等。通过阅读API文档,开发人员可以很容易地了解如何正确地使用库的各个部分。 这个特定的API文档版本是对照版,这意味着文档提供了文和文的对照版本。这将有助于使用文不太熟练的开发人员更好地理解文档的内容。无论是母语为文的开发者还是母语为文的开发者,都可以从这个对照的API文档受益。 要使用这个API文档,你可以下载并解压缩这个.zip文件。解压后,你将获得一个文件夹,里面含了所有的API文档文件。你可以打开文档并浏览其的类和方法,查找你需要的信息。 总之,commons-math3-3.6.1-api文档-对照版.zip是一个含了Commons Math库3.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、付费专栏及课程。

余额充值