Skip to content

num::bisection

Defined in header <roots/roots.hpp>

template <typename Float = double, bracketable_function<Float> Func = scalar_fn>
root_result<Float> bisection(Func &&f, Float a, Float b, Float tol = Float{1e-10},
                             idx max_iter = 1000);

Find a root by bisection, given \(f(a) f(b) \le 0\): \(|x_k - x^*| \le (b - a) / 2^k\).

Exceptions

  • std::invalid_argument: If \(f(a)\) and \(f(b)\) share a sign.