bisection

double bisectionWithState(FunctionWithState func, void* state, double x0, double x1, double tol)

Returns the root of func (parameterized by state) bracketed between x0 and x1 using the bisection method. The returned root is within tol of the true value of the root.

Parameters:
funcFunction to find root for.
stateParameters used by func.
x0Lower bound of root.
x1Upper bound of root.
tolMaximum error tolerance.

Returns:
The value x, such that func(x) = 0.

Usage:

typedef struct {
    double value;
} state_t;

double square(double x, void* state)
{
	return x * x - ((state_t*)s)->value;
}

state_t state = {5.0};
double x = bisectionWithState(square, &state, 2.0, 3.0);

Header:
#include "rootfind.h"

See Also: FunctionWithState