/// <summary> /// Finds the root of a function in the interval [a;b] /// </summary> /// /// <param name="function">The function to have its root computed.</param> /// <param name="lowerBound">Start of search region.</param> /// <param name="upperBound">End of search region.</param> /// <param name="tol">The tolerance for determining the solution.</param> /// <param name="maxIterations">The maximum number of iterations before terminating.</param> /// /// <returns>The location of the zero value in the given interval.</returns> /// public static double FindRoot( Func <double, double> function, double lowerBound, double upperBound, double tol = DefaultTolerance, int maxIterations = DefaultMaxIterations) { BrentSearchResult result = FindRootInternal(function, lowerBound, upperBound, tol, maxIterations); return(HandleResult(result)); }
/// <summary> /// Attempts to find a value in the interval [a;b] /// </summary> /// /// <returns>Returns <c>true</c> if the method converged to a <see cref="IOptimizationMethod{TInput, TOutput}.Solution"/>. /// In this case, the found value will also be available at the <see cref="IOptimizationMethod{TInput, TOutput}.Value"/> /// property.</returns> /// public bool Find(double value) { BrentSearchResult result = FindRootInternal( x => Function(x) - value, LowerBound, UpperBound, Tolerance, MaxIterations); Solution = result.Solution; Value = result.Value + value; Status = result.Status; return(Status == BrentSearchStatus.Success); }
/// <summary> /// Finds the maximum of the function in the interval [a;b] /// </summary> /// /// <returns>Returns <c>true</c> if the method converged to a <see cref="IOptimizationMethod{TInput, TOutput}.Solution"/>. /// In this case, the found value will also be available at the <see cref="IOptimizationMethod{TInput, TOutput}.Value"/> /// property.</returns> /// public bool Maximize() { BrentSearchResult result = MinimizeInternal( x => - Function(x), LowerBound, UpperBound, Tolerance, MaxIterations); Solution = result.Solution; Value = -result.Value; Status = result.Status; return(Status == BrentSearchStatus.Success); }
/// <summary> /// Attempts to find a root in the interval [a;b] /// </summary> /// /// <returns>Returns <c>true</c> if the method converged to a <see cref="IOptimizationMethod{TInput, TOutput}.Solution"/>. /// In this case, the found value will also be available at the <see cref="IOptimizationMethod{TInput, TOutput}.Value"/> /// property.</returns> /// public bool FindRoot() { BrentSearchResult result = FindRootInternal( Function, LowerBound, UpperBound, Tolerance, MaxIterations); Solution = result.Solution; Value = result.Value; Status = result.Status; Iterations = result.Iterations; return(Status == BrentSearchStatus.Success); }