newton

double newton(Function func, Function der, double x0, double x1, double tol)

Returns the root of func with first derivative der using Newton's method with initial approximation x0. The returned root is within tol of the true value of the root.

Parameters:
funcFunction to find root for.
derFirst derivative of function.
x0Lower bound of root.
x1Upper bound of root.
tolMaximum error tolerance.

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

Usage:

double sine(double x) { return sin(x); }
double derSine(double x) { return cos(x); }
double x = newton(sine, derSine, 2.3, 3.4);

Header:
#include "rootfind.h"