## roots

Library of well known algorithms for numerical root finding

### 8 releases

Uses old Rust 2015

 0.0.8 Dec 21, 2022 Jun 17, 2021 Dec 22, 2019 Jan 17, 2019 Mar 23, 2015

#24 in Math

Used in 49 crates (18 directly)

BSD-2-Clause

155KB
3K SLoC

Library of well known algorithms for numerical root finding.

## Usage

``````extern crate roots;
use roots::Roots;
use roots::find_roots_cubic;
use roots::find_root_brent;
use roots::find_root_secant;

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