[][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 guess
    • I(f64, f64) : For interval-like initial guess
  • 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) : Creat 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 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::<_, AD1>::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<T: AD>(x: T) -> T {
    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<T: AD>(x: T) -> T {
    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