static bool TryScanForCrossingsWithRoots(Func <double, double> f, Func <double, double> df, double lowerBound, double upperBound, double accuracy, int maxIterations, int subdivision, out double root) { var zeroCrossings = ZeroCrossingBracketing.FindIntervalsWithin(f, lowerBound, upperBound, subdivision); foreach (Tuple <double, double> bounds in zeroCrossings) { if (TryFindRoot(f, df, bounds.Item1, bounds.Item2, accuracy, maxIterations, subdivision, out root)) { return(true); } } root = double.NaN; return(false); }
/// <summary>Find a solution of the equation f(x)=0.</summary> /// <exception cref="NonConvergenceException"></exception> public static double FindRootExpand(Func <double, double> f, double guessLowerBound, double guessUpperBound, double accuracy = 1e-8, double expandFactor = 1.6, int maxExpandIteratons = 100) { ZeroCrossingBracketing.Expand(f, ref guessLowerBound, ref guessUpperBound, expandFactor, maxExpandIteratons); return(FindRoot(f, guessLowerBound, guessUpperBound, accuracy)); }