roots Build StatusCrates.io

Library of well known algorithms for numerical root finding.

Features

Usage

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

// Find the root of a complex function in the area determined by a simpler polynom fn findsolution(enormousfunction: &Fn(f64)->f64, rootareapolynom:(f64,f64,f64,f64)) -> Option { // de-structure polynom coefficients match rootareapolynom { (a3,a2,a1,a0) => { // Set convergency conditions: required precision - 1e-8, max 30 iterations let conv = SimpleConvergency{eps:1e-8f64; maxiter:30}; // 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) => { findrootbrent(roots[0],roots[2],enormousfunction,conv).ok() }, Roots::Two(roots) => { findrootbrent(roots[0],roots[1],enormousfunction,conv).ok() }, Roots::One(roots) => { findrootsecant(roots[0]-1f64,roots[0]+1f64,enormousfunction,conv).ok() }, _ => None, } }, _ => None, } } ```