Package org.apache.commons.math.analysis

Examples of org.apache.commons.math.analysis.UnivariateRealFunction


    /**
     * Test deprecated APIs.
     */
    @Deprecated
    public void testDeprecated() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealSolver solver = new MullerSolver(f);
        double min, max, expected, result, tolerance;

        min = 3.0; max = 4.0; expected = FastMath.PI;
        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
View Full Code Here


    /**
     * Test deprecated APIs.
     */
    @Deprecated
    public void testDeprecated2() throws MathException {
        UnivariateRealFunction f = new QuinticFunction();
        MullerSolver solver = new MullerSolver(f);
        double min, max, expected, result, tolerance;

        min = -0.4; max = 0.2; expected = 0.0;
        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
View Full Code Here

    /**
     * Test of solver for the sine function.
     */
    public void testSinFunction() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealSolver solver = new MullerSolver();
        double min, max, expected, result, tolerance;

        min = 3.0; max = 4.0; expected = FastMath.PI;
        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
View Full Code Here

    /**
     * Test of solver for the sine function using solve2().
     */
    public void testSinFunction2() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        MullerSolver solver = new MullerSolver();
        double min, max, expected, result, tolerance;

        min = 3.0; max = 4.0; expected = FastMath.PI;
        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
View Full Code Here

    /**
     * Test of solver for the quintic function.
     */
    public void testQuinticFunction() throws MathException {
        UnivariateRealFunction f = new QuinticFunction();
        UnivariateRealSolver solver = new MullerSolver();
        double min, max, expected, result, tolerance;

        min = -0.4; max = 0.2; expected = 0.0;
        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
View Full Code Here

    /**
     * Test of solver for the quintic function using solve2().
     */
    public void testQuinticFunction2() throws MathException {
        UnivariateRealFunction f = new QuinticFunction();
        MullerSolver solver = new MullerSolver();
        double min, max, expected, result, tolerance;

        min = -0.4; max = 0.2; expected = 0.0;
        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
View Full Code Here

     * It takes 10 to 15 iterations for the last two tests to converge.
     * In fact, if not for the bisection alternative, the solver would
     * exceed the default maximal iteration of 100.
     */
    public void testExpm1Function() throws MathException {
        UnivariateRealFunction f = new Expm1Function();
        UnivariateRealSolver solver = new MullerSolver();
        double min, max, expected, result, tolerance;

        min = -1.0; max = 2.0; expected = 0.0;
        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
View Full Code Here

     * Test of solver for the exponential function using solve2().
     * <p>
     * It takes 25 to 50 iterations for the last two tests to converge.
     */
    public void testExpm1Function2() throws MathException {
        UnivariateRealFunction f = new Expm1Function();
        MullerSolver solver = new MullerSolver();
        double min, max, expected, result, tolerance;

        min = -1.0; max = 2.0; expected = 0.0;
        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
View Full Code Here

    /**
     * Test of parameters for the solver.
     */
    public void testParameters() throws Exception {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealSolver solver = new MullerSolver();

        try {
            // bad interval
            solver.solve(f, 1, -1);
View Full Code Here

            throw new IllegalArgumentException("p must be between 0.0 and 1.0, inclusive.");
        }

        // by default, do simple root finding using bracketing and default solver.
        // subclasses can overide if there is a better method.
        UnivariateRealFunction rootFindingFunction =
            new UnivariateRealFunction() {

            public double value(double x) throws FunctionEvaluationException {
                try {
                    return cumulativeProbability(x) - p;
                } catch (MathException ex) {
                    throw new FunctionEvaluationException
                        (x, "Error computing cdf", ex);
                }
            }
        };
             
        // Try to bracket root, test domain endoints if this fails    
        double lowerBound = getDomainLowerBound(p);
        double upperBound = getDomainUpperBound(p);
        double[] bracket = null;
        try {
            bracket = UnivariateRealSolverUtils.bracket(
                    rootFindingFunction, getInitialDomain(p),
                    lowerBound, upperBound);
        catch (ConvergenceException ex) {
            /*
             * Check domain endpoints to see if one gives value that is within
             * the default solver's defaultAbsoluteAccuracy of 0 (will be the
             * case if density has bounded support and p is 0 or 1).
             *
             * TODO: expose the default solver, defaultAbsoluteAccuracy as
             * a constant.
             */
            if (Math.abs(rootFindingFunction.value(lowerBound)) < 1E-6) {
                return lowerBound;
            }
            if (Math.abs(rootFindingFunction.value(upperBound)) < 1E-6) {
                return upperBound;
            }    
            // Failed bracket convergence was not because of corner solution
            throw new MathException(ex);
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.analysis.UnivariateRealFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.