FindRoot() public method

Attempts to find a root in the interval [a;b]
public FindRoot ( ) : bool
return bool
Example #1
0
    private double brentMethod()
    {
        double guessVal = (Mathd.Sqrt(obj.parent.gravParam) * currentTime) / semiMajorAxis;

        //second two params are the min and max values the solver will search for, they are at this point total spitballing
        Accord.Math.Optimization.BrentSearch searcher = new Accord.Math.Optimization.BrentSearch(substitutionFunction, -2.0d * (guessVal + 20.0d), 2.0d * (guessVal + 20.0d));

        searcher.Tolerance = 0.0001;
        searcher.FindRoot();
        return(searcher.Solution);
    }
Example #2
0
        public void ConstructorTest()
        {

            // Suppose we were given the function xĀ³ + 2xĀ² - 10x and 
            // we have to find its root, maximum and minimum inside 
            // the interval [-4,3]. First, we express this function
            // as a lambda expression:
            Func<double, double> function = x => x * x * x + 2 * x * x - 10 * x;

            // And now we can create the search algorithm:
            BrentSearch search = new BrentSearch(function, -4, 3);

            // Finally, we can query the information we need
            double max = search.Maximize();  // occurs at -2.61
            double min = search.Minimize();  // occurs at  1.27
            double root = search.FindRoot(); // occurs at  0.50

            Assert.AreEqual(-2.6103173042172645, max);
            Assert.AreEqual(1.2769840667540548, min);
            Assert.AreEqual(-0.5, root);
        }
 /// <summary>
 /// Should solve
 /// </summary>
 /// <param name="c"></param>
 /// <param name="t0"></param>
 /// <param name="distance"></param>
 /// <returns></returns>
 public static double PointAtDistanceFrom(this ICurve c, double t0, double distance)
 {
     Func<double, double> objFunc = t1 =>
     {
         var length3 = t0 < t1 ? c.GetLength3(t0, t1) : c.GetLength3(t1, t0);
         return length3 - Math.Abs(distance);
     };
     var domain = c.Domain();
     var min = distance < 0.0 ? 0.8*domain[0] : t0;
     var max = distance < 0.0 ? t0 : 1.2*domain[1];
     var solver = new BrentSearch(objFunc, min, max);
     solver.FindRoot();
     var sol = solver.Solution;
     return sol;
 }