当前位置: 首页>>代码示例>>Java>>正文


Java ArithmeticUtils.factorial方法代码示例

本文整理汇总了Java中org.apache.commons.math3.util.ArithmeticUtils.factorial方法的典型用法代码示例。如果您正苦于以下问题:Java ArithmeticUtils.factorial方法的具体用法?Java ArithmeticUtils.factorial怎么用?Java ArithmeticUtils.factorial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.util.ArithmeticUtils的用法示例。


在下文中一共展示了ArithmeticUtils.factorial方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: taylor

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
/** Evaluate Taylor expansion of a derivative structure.
 * @param ds array holding the derivative structure
 * @param dsOffset offset of the derivative structure in its array
 * @param delta parameters offsets (Δx, Δy, ...)
 * @return value of the Taylor expansion at x + Δx, y + Δy, ...
 * @throws MathArithmeticException if factorials becomes too large
 */
public double taylor(final double[] ds, final int dsOffset, final double ... delta)
   throws MathArithmeticException {
    double value = 0;
    for (int i = getSize() - 1; i >= 0; --i) {
        final int[] orders = getPartialDerivativeOrders(i);
        double term = ds[dsOffset + i];
        for (int k = 0; k < orders.length; ++k) {
            if (orders[k] > 0) {
                try {
                    term *= FastMath.pow(delta[k], orders[k]) /
                            ArithmeticUtils.factorial(orders[k]);
                } catch (NotPositiveException e) {
                    // this cannot happen
                    throw new MathInternalError(e);
                }
            }
        }
        value += term;
    }
    return value;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:DSCompiler.java

示例2: taylor

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
/** Evaluate Taylor expansion of a derivative structure.
 * @param ds array holding the derivative structure
 * @param dsOffset offset of the derivative structure in its array
 * @param delta parameters offsets (&Delta;x, &Delta;y, ...)
 * @return value of the Taylor expansion at x + &Delta;x, y + &Delta;y, ...
 */
public double taylor(final double[] ds, final int dsOffset, final double ... delta) {
    double value = 0;
    for (int i = getSize() - 1; i >= 0; --i) {
        final int[] orders = getPartialDerivativeOrders(i);
        double term = ds[dsOffset + i];
        for (int k = 0; k < orders.length; ++k) {
            if (orders[k] > 0) {
                term *= FastMath.pow(delta[k], orders[k]) / ArithmeticUtils.factorial(orders[k]);
            }
        }
        value += term;
    }
    return value;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:DSCompiler.java

示例3: testReciprocal

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
@Test
public void testReciprocal() {
    for (double x = 0.1; x < 1.2; x += 0.1) {
        DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
        Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
        for (int i = 1; i < r.getOrder(); ++i) {
            double expected = ArithmeticUtils.pow(-1, i) * ArithmeticUtils.factorial(i) /
                              FastMath.pow(x, i + 1);
            Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:13,代码来源:DerivativeStructureTest.java

示例4: testLog

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
@Test
public void testLog() {
    double[] epsilon = new double[] { 1.0e-16, 1.0e-16, 3.0e-14, 7.0e-13, 3.0e-11 };
    for (int maxOrder = 0; maxOrder < 5; ++maxOrder) {
        for (double x = 0.1; x < 1.2; x += 0.001) {
            DerivativeStructure log = new DerivativeStructure(1, maxOrder, 0, x).log();
            Assert.assertEquals(FastMath.log(x), log.getValue(), epsilon[0]);
            for (int n = 1; n <= maxOrder; ++n) {
                double refDer = -ArithmeticUtils.factorial(n - 1) / FastMath.pow(-x, n);
                Assert.assertEquals(refDer, log.getPartialDerivative(n), epsilon[n]);
            }
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:15,代码来源:DerivativeStructureTest.java

示例5: testLog

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
@Override
@Test
public void testLog() {
    double[] epsilon = new double[] { 1.0e-16, 1.0e-16, 3.0e-14, 7.0e-13, 3.0e-11 };
    for (int maxOrder = 0; maxOrder < 5; ++maxOrder) {
        for (double x = 0.1; x < 1.2; x += 0.001) {
            DerivativeStructure log = new DerivativeStructure(1, maxOrder, 0, x).log();
            Assert.assertEquals(FastMath.log(x), log.getValue(), epsilon[0]);
            for (int n = 1; n <= maxOrder; ++n) {
                double refDer = -ArithmeticUtils.factorial(n - 1) / FastMath.pow(-x, n);
                Assert.assertEquals(refDer, log.getPartialDerivative(n), epsilon[n]);
            }
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:DerivativeStructureTest.java

示例6: evaluate

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
public BigDecimal evaluate(AFactorialPostfixop expression)
{
   BigDecimal value = evaluate(expression.getPostfixop());
   int valInt;
   try {
      valInt = value.intValueExact();
   } catch (ArithmeticException e) {
      throw new RuntimeException(String.format(
            "Cannot compute factorial of non-integer value '%s' at %s",
            value,
            Printer.nodeToString(expression)));
   }
   return new BigDecimal(ArithmeticUtils.factorial(valInt), STORED_PRECISION);
}
 
开发者ID:RichardBradley,项目名称:casio-cfx-9800g,代码行数:15,代码来源:Evaluator.java


注:本文中的org.apache.commons.math3.util.ArithmeticUtils.factorial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。