[−][src]Module peroxide::numerical::root
Root Finding
Implemented Algorithms
- Bisection
- False Position (Regula Falsi)
- Secant
- Newton
Low-level API
Members
RootState
P(f64)
: For point-like initial guessI(f64, f64)
: For interval-like initial guess
RootFind
: Algorithms for root findingBisection
FalsePosition
Newton
Secant
RootError
: Error for root findingMismatchedState
: Mismatched state and method (ex: Point vs Bisection)TimesUp
: No root untilself.times
NaNRoot
: NaN
RootFinder
: Main structure for root findingfn new(RootState, RootFind, f)
: Creat RootFinder (times: 100, tol: 1e-10)fn condition_number(&self) -> f64
: Compute condition numberfn set_tol(&mut self, f64) -> &mut Self
: Set tolerancefn set_times(&mut self, usize) -> &mut Self
: Set max iteration timesfn update(&mut self)
: Update one stepfn find_root(&mut self) -> Result<f64, RootError>
: Find root
Usage
extern crate peroxide; use peroxide::fuga::*; fn main() -> Result<(), RootError> { let init = RootState::I(1f64, 4f64); let mut rf = RootFinder::new(init, Bisection, f)?; rf.set_tol(1e-15) // Default: 1e-10 .set_times(200); // Default: 100 let root = rf.find_root()?; root.print(); Ok(()) } fn f(x: AD) -> AD { x.sin() }
High-level API
Members
All output type is Result<f64, RootError>
bisection(f, interval: (f64, f64), times: usize, tol: f64)
false_position(f, interval: (f64, f64), times: usize, tol: f64)
secant(f, initial_guess: (f64, f64), times: usize, tol: f64)
newton(f, initial_guess: f64, times: usize, tol: f64)
Usage
extern crate peroxide; use peroxide::fuga::*; fn main() -> Result<(), RootError> { let root = bisection(f, (1f64, 4f64), 100, 1e-15)?; root.print(); Ok(()) } fn f(x: AD) -> AD { x.sin() }
Reference
- Walter Gautschi, Numerical Analysis, Springer (2012)
Structs
RootFinder | Structure for Root finding |
Enums
RootBool | |
RootError | |
RootFind | |
RootState |
Functions
bisection | Bisection method to find root |
false_position | False position method to find root |
newton | Newton method to find root |
secant | Secant method to find root |