Library of well known algorithms for numerical root finding.

LicenseBuild StatusCrates.io

Features

Usage

```rust extern crate roots; use roots::Roots; use roots::findrootscubic; use roots::findrootbrent; use roots::findrootsecant;

// Find the root of a complex function in the area determined by a simpler polynom fn findsolution(enormousfunction: F, rootareapolynom:(f64,f64,f64,f64)) -> Option where F: Fn(f64) -> f64 { // de-structure polynom coefficients match rootareapolynom { (a3,a2,a1,a0) => { // Find root area by solving the polynom match findrootscubic(a3,a2,a1,a0) { // Try to find the root by one of iterative methods Roots::Three(roots) => { // Three roots found, normal case findrootbrent(roots[0],roots[2],enormousfunction, &mut 1e-8f64).ok() }, Roots::Two(roots) => { // Two roots found, High precision required findrootbrent(roots[0],roots[1],enormousfunction,&mut 1e-15f64).ok() }, Roots::One(roots) => { // One root found, Low precision is enough findrootsecant(roots[0]-1f64,roots[0]+1f64,enormous_function,&mut 1e-3f64).ok() }, _ => None, } }, _ => None, } } ```