Expand description
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 guessfn get_point(&self) -> Option<f64>
: Returns the pointfn get_interval(&self) -> Option<(f64, f64)>
: Returns the interval
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)
: Create 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 get_tol(&self) -> f64
: Get tolerancefn get_times(&self) -> usize
: Get max iteration timesfn get_method(&self) -> RootFind
: Get methodfn get_curr(&self) -> &RootState
: Get current statefn check_find(&self) -> RootBool
: Check if find rootfn 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
- Structure for Root finding
Enums
Functions
- Bisection method to find root
- False position method to find root
- Newton method to find root
- Secant method to find root