Example usage for org.apache.commons.math.analysis.polynomials PolynomialFunction degree

List of usage examples for org.apache.commons.math.analysis.polynomials PolynomialFunction degree

Introduction

In this page you can find the example usage for org.apache.commons.math.analysis.polynomials PolynomialFunction degree.

Prototype

public int degree() 

Source Link

Document

Returns the degree of the polynomial

Usage

From source file:cz.cuni.mff.d3s.spl.example.newton.app.Main.java

public static void main(String[] args) {
    try {/*from w  ww.  j  av  a2  s.  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);
}