## Root Finding

**numerics4j** provides the means to find roots of functions through the use of common numerical methods. The following routines are available for root finding:

Method | Description |
---|---|

Bisection Root Finder | An implementation of the bisection method. |

Bracket | Techniques to create intervals that bracket a root. Many root finding methods require a bracketted root for initialization in order to function properly. |

False Position Root Finder | An implementation of the false position method. |

Newton Root Finder | An implementation of Newton's method. |

Secant Root Finder | An implementation of the secant method. |

### Bisection Root Finder

The BisectionRootFinder class provides an implementation of the bisection method. The bisection method is a solid, general purpose root finding method. It is not the fastest root finding method but it provides guaranteed convergance and can find roots for any continuous function. For those reasons, it is a good fail-safe routine in situations where other root finding methods may fail to perform.

Finding roots using the bisection method involves creating a new BisectionRootFinder instance providing a Function delegate. Once, the root finder is created, roots of the function can be evaluated by calling the FindRoot method providing a bracketting interval. Here is an example of finding roots for sine:

Function sine = new Function() { public double evaluate(double x) { return Math.sin(x); } }; BisectionRootFinder bisection = new BisectionRootFinder(sine); // find the root between 3 and 4. double pi = bisection.findRoot(3.0, 4.0); // find the root between -1 and 1. double zero = bisection.findRoot(-1.0, 1.0);

### Bracket

The Bracket class provides the means to construct an interval known to contain at least one root. This is accomplished by taking a single, initial pivot point and expanding outward from that point until a bracketing interval is formed. Once this interval is created, it can be used as a starting point for root finding routines, such as the bisection method.

Constructing a bracking interval involves creating a new Bracket instance providing a Function delegate. Once, the bracketer is created, intervals can be created by calling the bracketOut method providing an initial point and a lower and upper bound for the interval. The two bounds are not critical in the construction of the interval and only serve to provide numerical stability to the algorithm. Here is an example of bracketing roots for sine:

Function sine = new Function() { public double evaluate(double x) { return Math.sin(x); } }; Bracket bracket = new Bracket(sine); // bracket a root near three double[] containsPi = bracket.bracketOut(-100.0, 3.0, 100.0); // bracket a root near six double[] contains2Pi = bracket.bracketOut(-100.0, 6.0, 100.0);

### False Position Root Finder

The FalsePositionRootFinder class provides an implementation of the false position method. The false position method is more numerically stable than its cousin algorithm, the secant method, as the false position method maintains a bracketted root at all times. Thus, the false position is guaranteed to converge given a bracketting interval but, no such guaranteed is granted with the secant method.

Finding roots using the false position method involves creating a FalsePositionRootFinder object for a particular Function object. Once, the root finder is created, roots can be evaluated by calling the FindRoot method providing a bracketting interval. Here is an example of finding roots for sine:

Function sine = new Function() { public double evaluate(double x) { return Math.sin(x); } }; FalsePositionRootFinder finder = new FalsePositionRootFinder(sine); // find the root between 3 and 4. double pi = finder.findRoot(3.0, 4.0); // find the root between -1 and 1. double zero = finder.findRoot(-1.0, 1.0);

### Newton Root Finder

The NewtonRootFinder class provides an implementation of Newton's method. Newton's method is fast converging root finding method that utilizes not only a function but the function's derivative. As such, Newton's method only is applicable for functions with a first derivative.

Finding roots using Newton's method involves creating a new NewtonRootFinder instance providing a Function delegate for both the target function and its first derivative. Once, the root finder is created, roots of the function can be evaluated by calling the FindRoot method providing an initial approximation to the root. Here is an example of finding roots for sine:

Function sine = new Function() { public double evaluate(double x) { return Math.sin(x); } }; Function cosine = new Function() { public double evaluate(double x) { return Math.cos(x); } }; NewtonRootFinder finder = new NewtonRootFinder(sine, cosine); // find the root near 3. double pi = finder.findRoot(3.0); // find the root near 1. double zero = finder.findRoot(1.0);

### Secant Root Finder

The SecantRootFinder class provides an implementation of the secant method.

Finding roots using the bisection method involves creating a new SecantRootFinder instance providing a Function delegate. Once, the root finder is created, roots of the function can be evaluated by calling the FindRoot method providing two initial approximations to the actual root. Here is an example of finding roots for sine:

Function sine = new Function() { public double evaluate(double x) { return Math.sin(x); } }; SecantRootFinder finder = new SecantRootFinder(sine); // find the root close to 3 and 4. double pi = finder.findRoot(3.0, 4.0); // find the root close to -1 and 1. double zero = finder.findRoot(-1.0, 1.0);