List of usage examples for org.apache.commons.math3.analysis.solvers BrentSolver solve
double solve(int maxEval, FUNC f, double min, double max);
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 w w . j av a2 s .c om 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: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 ww . j a v a 2 s .co 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); } }