Expand description

Root Finding

Implemented Algorithms

  • Bisection
  • False Position (Regula Falsi)
  • Secant
  • Newton

Low-level API

Members

  • RootState
    • P(f64) : For point-like initial guess
    • I(f64, f64) : For interval-like initial guess
    • fn get_point(&self) -> Option<f64> : Returns the point
    • fn get_interval(&self) -> Option<(f64, f64)> : Returns the interval
  • RootFind : Algorithms for root finding
    • Bisection
    • FalsePosition
    • Newton
    • Secant
  • RootError : Error for root finding
    • MismatchedState : Mismatched state and method (ex: Point vs Bisection)
    • TimesUp : No root until self.times
    • NaNRoot : NaN
  • RootFinder : Main structure for root finding
    • fn new(RootState, RootFind, f) : Create RootFinder (times: 100, tol: 1e-10)
    • fn condition_number(&self) -> f64 : Compute condition number
    • fn set_tol(&mut self, f64) -> &mut Self : Set tolerance
    • fn set_times(&mut self, usize) -> &mut Self : Set max iteration times
    • fn get_tol(&self) -> f64 : Get tolerance
    • fn get_times(&self) -> usize : Get max iteration times
    • fn get_method(&self) -> RootFind : Get method
    • fn get_curr(&self) -> &RootState : Get current state
    • fn check_find(&self) -> RootBool : Check if find root
    • fn update(&mut self) : Update one step
    • fn 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