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:
func | Function to find root for. |
---|---|
der | First derivative of function. |
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 derSine(double x) { return cos(x); } double x = newton(sine, derSine, 2.3, 3.4);
Header:
#include "rootfind.h"