double bisection(Function func, double x0, double x1, double tol)
Returns the root of func bracketed between x0 and x1 using the bisection method. The returned root is within tol of the true value of the root.
Parameters:
func | Function to find root for. |
---|---|
x0 | Lower bound of root. |
x1 | Upper bound of root. |
tol | Maximum error tolerance. |
Returns:
The value x, such that func(x) = 0.
Usage:
double sine(double x) { return sin(x); } double x = bisection(sine, 2.3, 3.4);
Header:
#include "rootfind.h"