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

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

Introduction

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

Prototype

public NewtonSolver(DifferentiableUnivariateRealFunction f) 

Source Link

Document

Construct a solver for the given function.

Usage

From source file:org.jcurl.math.analysis.DistanceSqTest.java

public void testIntersectStraightLines() throws ConvergenceException, FunctionEvaluationException {
    {/*w  w  w .j av  a 2s  .c o  m*/
        final double dt = 1e-6;
        final R1RnCurve g1 = R1RnCurve.straightLine(1, 0.5);
        final R1RnCurve g2 = R1RnCurve.straightLine(-6, 4);
        final R1R1Function distSq = new DistanceSq(g1, g2);
        double t = new NewtonSolver(distSq).solve(2, 4);
        assertEquals("", 2.0, t, dt);
        assertEquals("", 0.0, distSq.value(t), dt);
    }
    {
        final double dt = 1e-6;
        final R1RnCurve g1 = R1RnCurve.straightLine(1, 0.5);
        final R1RnCurve g2 = R1RnCurve.straightLine(-6, 3);
        final DifferentiableUnivariateRealFunction distSq = new DistanceSq(g1, g2);
        double t = new NewtonSolver(distSq).solve(2, 4);
        assertEquals("", 2.8, t, dt);
        assertEquals("", 0.0, distSq.value(t), dt);
    }
}

From source file:org.jcurl.model.ComputedPaths.java

static double firstHit(final R1RnCurve a, final R1RnCurve b, double tmin, double tmax)
        throws FunctionEvaluationException {
    final DistanceSq dist = new DistanceSq(a, b);
    final UnivariateRealSolver solver = new NewtonSolver(dist);
    try {// ww  w . j  av a2 s. c  om
        return solver.solve(tmin, tmax, tmin + 1e-2);
    } catch (ConvergenceException e) {
        return Never;
    }
}

From source file:org.jcurl.model.DennyCurvesTest.java

public void testStraight() throws FunctionEvaluationException, ConvergenceException {
    final DennyCurves m = new DennyCurves();
    final PathSegment f = m.compute(0, 0, 0, 0, 0, 2.5, 0, 1);
    assertEquals("", 0.0, f.value(0, 0), 1e-9);
    assertEquals("", 0.0, f.value(1, 0), 1e-9);
    assertEquals("", 0.0, f.value(2, 0), 1e-9);

    assertEquals("p(x) = 1.7565092079712113E-5*x^4 - 4.699551873981532E-4*x^3", f.component(0).toString());
    assertEquals("p(x) = -0.0622935*x^2 + 2.5*x^1", f.component(1).toString());

    // find the stop
    double tStopX = new NewtonSolver((DifferentiableUnivariateRealFunction) f.component(0).derivative())
            .solve(0, 100);/*from  w  w  w.j  a  v  a  2s.  c  o m*/
    assertEquals("", 20.066299052068032, tStopX, 1e-12);
    assertEquals("", tStopX,
            new NewtonSolver((DifferentiableUnivariateRealFunction) f.component(1).derivative()).solve(0, 100,
                    0.1),
            1e-12);
}