List of usage examples for org.apache.commons.math.analysis.solvers NewtonSolver solve
@Deprecated public double solve(final UnivariateRealFunction f, final double min, final double max, final double startValue) throws MaxIterationsExceededException, FunctionEvaluationException
startValue
. From source file:cz.cuni.mff.d3s.spl.example.newton.app.Main.java
public static void main(String[] args) { try {/*from w w w . ja v a2s .c o m*/ System.out.printf("Letting things settle down before actual computation.\n"); Thread.sleep(1000 * 1); } catch (InterruptedException ignored) { } /* This seed gives reasonable data, keep it at that ;-). */ Random random = new Random(2); double[] coefficients = generateCoefficients(random); PolynomialFunction function = new PolynomialFunction(coefficients); NewtonSolver solver = new NewtonSolver(); System.out.printf("Will solve polynomial function of degree %d.\n", function.degree()); inspectClass(solver); try { for (int i = 0; i < WARM_UP_LOOPS; i++) { double result = solver.solve(10000, function, -1000, 1000); } long startTimeNanos = System.nanoTime(); for (int i = 0; i < MEASURED_LOOPS; i++) { double result = solver.solve(10000, function, -1000, 1000); } long endTimeNanos = System.nanoTime(); long runTimeNanos = endTimeNanos - startTimeNanos; long runTimeMillis = runTimeNanos / (1000 * 1000); System.out.printf("%d loops of solving took %dns (%dms).\n", MEASURED_LOOPS, runTimeNanos, runTimeMillis); } catch (MaxIterationsExceededException e) { e.printStackTrace(); } catch (FunctionEvaluationException e) { e.printStackTrace(); } inspectClass(solver); }