Example usage for org.apache.commons.math.analysis.solvers NewtonSolver NewtonSolver

List of usage examples for org.apache.commons.math.analysis.solvers NewtonSolver NewtonSolver

Introduction

In this page you can find the example usage for org.apache.commons.math.analysis.solvers NewtonSolver NewtonSolver.

Prototype

@Deprecated
public NewtonSolver(DifferentiableUnivariateRealFunction f) 

Source Link

Document

Construct a solver for the given function.

Usage

From source file:dr.math.distributions.KernelDensityEstimatorDistribution.java

/**
 * quantile (inverse cumulative density function) of the distribution
 *
 * @param y argument//from   ww w .  j a v a2  s .  c o  m
 * @return cdf value
 */
public double quantile(final double y) {

    final DifferentiableUnivariateRealFunction root = new DifferentiableUnivariateRealFunction() {

        @Override
        public UnivariateRealFunction derivative() {
            return pdfFunction;
        }

        @Override
        public double value(double x) throws FunctionEvaluationException {

            return cdfFunction.value(x) - y;
        }
    };

    NewtonSolver solver = new NewtonSolver(root);

    double q;
    try {
        q = solver.solve(getFromPoint(), getToPoint());
    } catch (MaxIterationsExceededException e) {
        throw new RuntimeException(e.getMessage());
    } catch (FunctionEvaluationException e) {
        throw new RuntimeException(e.getMessage());
    }

    return q;
}