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


Java BrentSolver.solve方法代码示例

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


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

示例1: testSolveWaterVapourFunction

import org.apache.commons.math3.analysis.solvers.BrentSolver; //导入方法依赖的package包/类
@Test
public void testSolveWaterVapourFunction() throws Exception {

    // all numbers in this test taken from IDL test run, cellIndexX=1, cellIndexY=0
    WaterVapourFunction wvFunction = new WaterVapourFunction();
    wvFunction.setMerisRatio(0.64714217);
    wvFunction.setWvGr2(new double[]{0.301, 1.0, 1.5, 2.0, 2.7, 4.999});
    final double[][][] parAtmH = initParAtmH();
    wvFunction.setParAtmH(parAtmH);
    wvFunction.setReflPix(new double[]{0.358543, 0.365387});

    // Define the fractional tolerance:
    final double ftol = 1.0e-4;
    final int maxIter = 10000;

    final double wvLower = 0.302;
    final double wvUpper = 4.998;

    BrentSolver brentSolver = new BrentSolver(ftol);
    double result = brentSolver.solve(maxIter, wvFunction, wvLower, wvUpper);
    assertEquals(1.96476, result, ftol);
}
 
开发者ID:senbox-org,项目名称:s3tbx-scape-m,代码行数:23,代码来源:WaterVapourFunctionTest.java

示例2: testDekkerBrentFunction

import org.apache.commons.math3.analysis.solvers.BrentSolver; //导入方法依赖的package包/类
@Test
public void testDekkerBrentFunction() throws Exception {
    // Define the fractional tolerance:
    final double ftol = 1.0e-4;
    final int maxIter = 10000;

    // f(x) = x - 1
    DekkerBrentTestFunction1 testFunction = new DekkerBrentTestFunction1();

    double a = 0.5;
    double b = 2.0;

    BrentSolver brentSolver = new BrentSolver(ftol);
    double result = brentSolver.solve(maxIter, testFunction, a, b);
    assertEquals(1.0, result, 1.E-4);

    // f(x) = cos(x)
    DekkerBrentTestFunction2 testFunction2 = new DekkerBrentTestFunction2();

    a = 1.0;
    b = 2.0;

    result = brentSolver.solve(maxIter, testFunction2, a, b);
    assertEquals(Math.PI/2.0, result, 1.E-4);
}
 
开发者ID:senbox-org,项目名称:s3tbx-scape-m,代码行数:26,代码来源:DekkerBrentTest.java

示例3: simpleTest

import org.apache.commons.math3.analysis.solvers.BrentSolver; //导入方法依赖的package包/类
/**
 * Test on a 4th degree polynomial with 4 real roots at x = 0, 1, 2, 3. This objective function is positive for
 * large enough positive and negative values of its arguments. Therefore, the simple Brent solver complains that
 * the search interval does not bracket a root. The robust Brent solver, however, subdivides the given search
 * interval and finds a bracketing sub-interval.
 *
 * The "best" root according to the given merit function (set to the anti-derivative of the objective function)
 * is in fact the one at x = 0. We require the robust solver to output x = 0, and the simple solver to fail.
 */
@Test
public void simpleTest() {
    final UnivariateFunction objFunc = x -> 30 * x * (x - 1) * (x - 2) * (x - 3);
    final UnivariateFunction meritFunc = x -> 6 * FastMath.pow(x, 5) - 45 * FastMath.pow(x, 4) + 110 * FastMath.pow(x, 3) -
            90 * FastMath.pow(x, 2);
    final RobustBrentSolver solverRobust = new RobustBrentSolver(DEF_REL_ACC, DEF_REL_ACC, DEF_F_ACC,
            meritFunc, 4, 1);
    final BrentSolver solverSimple = new BrentSolver(DEF_REL_ACC, DEF_REL_ACC, DEF_F_ACC);
    final double xRobust = solverRobust.solve(100, objFunc, -1, 4);
    Assert.assertEquals(xRobust, 0, DEF_ABS_ACC);
    boolean simpleSolverFails = false;
    try {
        /* this will fail */
        solverSimple.solve(100, objFunc, -1, 4);
    } catch (final NoBracketingException ex) {
        simpleSolverFails = true;
    }
    Assert.assertTrue(simpleSolverFails);
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:29,代码来源:RobustBrentSolverUnitTest.java


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