Search in sources :

Example 1 with BrentSolver

use of org.hipparchus.analysis.solvers.BrentSolver in project symja_android_library by axkr.

the class FindRoot method findRoot.

private double findRoot(ISymbol method, int maxIterations, IAST list, ISignedNumber min, ISignedNumber max, IExpr function, EvalEngine engine) {
    ISymbol xVar = (ISymbol) list.arg1();
    function = engine.evaluate(function);
    UnivariateFunction f = new UnaryNumerical(function, xVar, engine);
    BaseAbstractUnivariateSolver<UnivariateFunction> solver = null;
    if (method.isSymbolName("Bisection")) {
        solver = new BisectionSolver();
    } else if (method.isSymbolName("Brent")) {
        solver = new BrentSolver();
    // } else if (method.isSymbolName("Laguerre")) {
    // solver = new LaguerreSolver();
    } else if (method.isSymbolName("Muller")) {
        solver = new MullerSolver();
    } else if (method.isSymbolName("Ridders")) {
        solver = new RiddersSolver();
    } else if (method.isSymbolName("Secant")) {
        solver = new SecantSolver();
    } else if (method.isSymbolName("RegulaFalsi")) {
        solver = new RegulaFalsiSolver();
    } else if (method.isSymbolName("Illinois")) {
        solver = new IllinoisSolver();
    } else if (method.isSymbolName("Pegasus")) {
        solver = new PegasusSolver();
    } else {
        // default: NewtonSolver
        DifferentiableUnivariateFunction fNewton = new UnaryNumerical(function, xVar, engine);
        BaseAbstractUnivariateSolver<DifferentiableUnivariateFunction> solver2 = new NewtonSolver();
        if (max == null) {
            return solver2.solve(maxIterations, fNewton, min.doubleValue());
        }
        return solver2.solve(maxIterations, fNewton, min.doubleValue(), max.doubleValue());
    }
    if (max == null) {
        return solver.solve(maxIterations, f, min.doubleValue());
    }
    return solver.solve(maxIterations, f, min.doubleValue(), max.doubleValue());
}
Also used : BrentSolver(org.hipparchus.analysis.solvers.BrentSolver) UnaryNumerical(org.matheclipse.core.generic.UnaryNumerical) ISymbol(org.matheclipse.core.interfaces.ISymbol) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DifferentiableUnivariateFunction(org.matheclipse.commons.math.analysis.solvers.DifferentiableUnivariateFunction) SecantSolver(org.hipparchus.analysis.solvers.SecantSolver) NewtonSolver(org.matheclipse.commons.math.analysis.solvers.NewtonSolver) IllinoisSolver(org.hipparchus.analysis.solvers.IllinoisSolver) BaseAbstractUnivariateSolver(org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver) PegasusSolver(org.hipparchus.analysis.solvers.PegasusSolver) MullerSolver(org.hipparchus.analysis.solvers.MullerSolver) BisectionSolver(org.hipparchus.analysis.solvers.BisectionSolver) RegulaFalsiSolver(org.hipparchus.analysis.solvers.RegulaFalsiSolver) RiddersSolver(org.hipparchus.analysis.solvers.RiddersSolver) DifferentiableUnivariateFunction(org.matheclipse.commons.math.analysis.solvers.DifferentiableUnivariateFunction)

Aggregations

UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)1 BaseAbstractUnivariateSolver (org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver)1 BisectionSolver (org.hipparchus.analysis.solvers.BisectionSolver)1 BrentSolver (org.hipparchus.analysis.solvers.BrentSolver)1 IllinoisSolver (org.hipparchus.analysis.solvers.IllinoisSolver)1 MullerSolver (org.hipparchus.analysis.solvers.MullerSolver)1 PegasusSolver (org.hipparchus.analysis.solvers.PegasusSolver)1 RegulaFalsiSolver (org.hipparchus.analysis.solvers.RegulaFalsiSolver)1 RiddersSolver (org.hipparchus.analysis.solvers.RiddersSolver)1 SecantSolver (org.hipparchus.analysis.solvers.SecantSolver)1 DifferentiableUnivariateFunction (org.matheclipse.commons.math.analysis.solvers.DifferentiableUnivariateFunction)1 NewtonSolver (org.matheclipse.commons.math.analysis.solvers.NewtonSolver)1 UnaryNumerical (org.matheclipse.core.generic.UnaryNumerical)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1