List of usage examples for org.apache.commons.math.analysis.solvers BrentSolver solve
@Deprecated public double solve(final UnivariateRealFunction f, final double min, final double max) throws MaxIterationsExceededException, FunctionEvaluationException
From source file:org.renjin.primitives.optimize.Roots.java
/** * Searches the interval from lower to upper for a root (i.e., zero) of the function f with * respect to its first argument./* www .j av a 2 s.c o m*/ * * <p> * This internal primitive is used by the uniroot() function in the stats package. * * <p> * This implementation wraps the Commons Math {@link BrentSolver}; there are however * */ public static DoubleVector zeroin2(@Current Context context, @Current Environment rho, Function fn, double lower, double upper, double fLower, double fUpper, double tol, int maximumIterations) { BrentSolver solver = new BrentSolver(maximumIterations, tol); double root; int iterations; double estimatedPrecision = DoubleVector.EPSILON; // not exposed by commons math impl try { root = solver.solve(new UnivariateRealClosure(context, rho, fn), lower, upper); iterations = 1; // the Commons math impl doesn't expose this } catch (MaxIterationsExceededException e) { root = DoubleVector.NA; iterations = -1; } catch (FunctionEvaluationException e) { throw new EvalException(e); } return new DoubleArrayVector(root, iterations, estimatedPrecision); }
From source file:r.base.optimize.Roots.java
/** * Searches the interval from lower to upper for a root (i.e., zero) of the function f with * respect to its first argument.//from ww w. j a v a2 s.c om * * <p> * This internal primitive is used by the uniroot() function in the stats package. * * <p> * This implementation wraps the Commons Math {@link BrentSolver}; there are however * */ public static DoubleVector zeroin2(@Current Context context, @Current Environment rho, Function fn, double lower, double upper, double fLower, double fUpper, double tol, int maximumIterations) { BrentSolver solver = new BrentSolver(maximumIterations, tol); double root; int iterations; double estimatedPrecision = DoubleVector.EPSILON; // not exposed by commons math impl try { root = solver.solve(new UnivariateRealClosure(context, rho, fn), lower, upper); iterations = 1; // the Commons math impl doesn't expose this } catch (MaxIterationsExceededException e) { root = DoubleVector.NA; iterations = -1; } catch (FunctionEvaluationException e) { throw new EvalException(e); } return new DoubleVector(root, iterations, estimatedPrecision); }