Example usage for org.apache.commons.math3.analysis.solvers BrentSolver BrentSolver

List of usage examples for org.apache.commons.math3.analysis.solvers BrentSolver BrentSolver

Introduction

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

Prototype

public BrentSolver() 

Source Link

Document

Construct a solver with default accuracy (1e-6).

Usage

From source file:jat.core.cm.CRTBP.java

public void findZeroVelocity() {
    JacobiFixedx JF = new JacobiFixedx();
    BisectionSolver bis = new BisectionSolver();
    BrentSolver brs = new BrentSolver();
    JF.setC(C);/*from   w ww.  j a  v a 2  s . c  o  m*/
    double x = -1.;
    double lasty = 0;
    while ((x += .01) < 1.3) {
        JF.setx(x);

        double y = 0;
        boolean success = false;
        try {
            success = true;
            y = brs.solve(100, JF, lasty - .4, lasty + .4);
            // y = brs.solve(100, JF, -.1, .8);
            // double y = bis.solve(100, JF, 0, 2);
        } catch (NoBracketingException e) {
            success = false;
            // System.out.println("exception at x y " + x + " " + y);

        } finally {

            if (success) {
                // System.out.println("x y " + x + " " + y);

                xzv.add(x);
                yzv.add(y);
                lasty = y;
                //System.out.println("last y " + lasty);
            }

        }
    }
}

From source file:com.wwidesigner.modelling.PlayingRange.java

/**
 * Construct a playing-range calculator for a specified fingering.
 * @param calculator/*from w w  w.jav a 2s .  c  o m*/
 * @param fingering
 */
public PlayingRange(InstrumentCalculator calculator, Fingering fingering) {
    this.calculator = calculator;
    this.fingering = fingering;
    this.reactance = new Reactance();
    this.zMagnitude = new ZMagnitude();
    this.gainOne = new Gain();
    this.zRatio = new ZRatio();
    this.solver = new BrentSolver();
    this.optimizer = new BrentOptimizer(0.0001, 0.0001); // Approximate minimum is sufficient.
}

From source file:uk.ac.diamond.scisoft.analysis.roi.fitting.EllipseFitterTest.java

@Test
public void testOrthoDist() {

    AngleDerivativeFunction angleDerivative = new AngleDerivativeFunction();
    BrentSolver solver = new BrentSolver();
    double a = 10.2;
    double b = 3.1;
    final double twopi = 2 * Math.PI;
    double alpha = twopi * 10. / 360; // 0 to 2 pi
    angleDerivative.setRadii(a, b);//w  w w.  ja  v  a 2 s. c  o m
    angleDerivative.setAngle(alpha);

    //      final double ca = 0;
    //      final double cb = b-0.5;
    final double Xc = -5.; // Math.cos(alpha)*ca + Math.sin(alpha)*cb;
    final double Yc = 5.5; //Math.sin(alpha)*ca + Math.cos(alpha)*cb;

    angleDerivative.setCoordinate(Xc, Yc);
    try {
        // find quadrant to use
        double p = Math.atan2(Yc, Xc);
        if (p < 0)
            p += twopi;
        p -= alpha;
        final double end;
        final double halfpi = 0.5 * Math.PI;
        p /= halfpi;
        end = Math.ceil(p) * halfpi;
        final double angle = solver.solve(100, angleDerivative, end - halfpi, end);
        //         final double cos = Math.cos(angle);
        //         final double sin = Math.sin(angle);

        Assert.assertEquals("Angle found is not close enough", 1.930, angle, 0.001);
        //         double dx = a*cos + Xc;
        //         double dy = b*sin + Yc;
        //
        //         System.out.println("Bracket angle = " + Math.ceil(p));
        //         System.out.println("Delta angle = " + 180.*angle/Math.PI);
        //         System.out.println(dx + ", " + dy);
    } catch (TooManyEvaluationsException e) {
        // TODO
        System.err.println(e);
    } catch (MathIllegalArgumentException e) {
        // TODO
        System.err.println(e);
    }

}