I need to run a bisection on a function instead of on an array. My research in the .NET API has only produced Array.BinarySearch where the searched domain is an array but that is not my case.

Reproducibility is easy. Any function with the signature

public static bool IsValid(double x)

has the same signature as the function I need to search. Behaviourally, I will need to assume that the function is monotonic in its return value but may be increasing or decreasing: that is to say, for the value of x I need to find, the return value is true for all x above it and false for all x below it or it could be the inverted version of that.

My search function signature will look like

public double Bisect(Func<double, bool> func, double xTrue, double xFalse, double tolerance = 1e-3)

where

func is the function to be repeatedly called xTrue is a known value of x for which func returns true xFalse is a known value of x for which func returns false tolerance is the difference between two function calls below which the search will terminate

If there is nothing built-in then I am happy to implement this myself.

avigt's user avatar

3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.