Module rootfind::solver
[−]
[src]
Root finding algorithms.
Fucntions typically have to be wrapped before use. See the wrap
module
for how to do this.
Custom convergence criteria can be supplied. Canned ones exist in the
convergence
module.
Examples
Using Newton-Raphson:
use rootfind::solver::newton_raphson; use rootfind::convergence::DeltaX; use rootfind::wrap::RealFnAndFirst; // function and its derivative let in_f = |x: f64| -x*x + 2.0*x + 1.0; let in_df = |x: f64| -2.0*x + 2.0; let f = RealFnAndFirst::new(&in_f, &in_df); // convergence criteria let conv = DeltaX::new(1e-9); // invoke Newton-Raphson let max_iterations = 20; let root = newton_raphson(&f, 3.0, &conv, max_iterations).expect("root"); // root at x=1+sqrt(2) assert!((root-2.41421356237).abs() < 1e-9);
Using Bisection Method or False Position:
use rootfind::bracket::Bounds; use rootfind::solver::{bisection, false_position_illinios}; use rootfind::wrap::RealFn; // function... no derivatives needed! let in_f = |x: f64| -x*x + 2.0*x + 1.0; let f = RealFn::new(&in_f); // invoke bisection let max_iterations = 20; let root = bisection(&f, &Bounds::new(2.0, 3.0), 100).expect("root"); assert!((root-2.41421356237).abs() < 1e-9); // invoke false position let max_iterations = 20; let root = false_position_illinios(&f, &Bounds::new(2.0, 3.0), 100).expect("root"); assert!((root-2.41421356237).abs() < 1e-9);
Enums
RootError |
Root finding error conditions. |
Functions
bisection |
Root finding via Bisection Method. |
false_position_illinios |
Illinois variant of Regula Falsi. |
halley_method |
Root finding using Halley's method. |
newton_raphson |
Root finding using Newton-Raphson. |