Crate root1d

source ·
Expand description

One dimensional root finding algorithms.

This crate offers several generic root finding algorithms for functions from ℝ to ℝ. It focuses on bracketing algorithms, that is algorithms which start with an interval [a,b] such that the function has opposite signs at a and b (thus containing a root of the function if it is continuous) and compute a smaller interval with the same property.

Example

All root finding procedures have the same structure. For example algorithm Toms 748 starts with a function toms748 to specify the function f and the interval [a, b] on which f changes sign. It returns a structure Toms748 which provides methods to specify various parameters (such as rtol) and functions to compute a root (such as root and root_mut).

use root1d::toms748;
assert!((toms748(|x| x*x - 2., 0., 2.).root()?
         - 2f64.sqrt()).abs() < 1e-12);

Use with your own types

This library can readily be used with types f64 and f32 and, if you activate the feature rug, with rug::Float and rug::Rational.

To use it with with another type, say t, implement the trait Bisectable for t which in turn requires that you decide which type will store the default termination routine (for example one based on tolerances, either Tol<t> or a structure implementing SetTolerances) and implement Terminate and Default for it. To use toms748 (resp. toms748_mut), you must also implement the trait OrdField (resp. OrdFieldMut).

Structs

Enums

  • Errors that may be returned by the root finding methods.

Traits

  • Trait indicating that the type is suitable for the bisection algorithm.
  • Requirements on the type T to be able to use toms748 algorithm.
  • Requirements on the type T to be able to use toms748_mut algorithm.
  • Indicate that the type Self uses relative and absolute tolerances that can be updated from type U.
  • Trait for termination criteria of the bracketing algorithms.

Functions

  • Find a root of the function f on the interval [a, b] with finite bounds assuming f(a) and f(b) have opposite signs and f is continuous using the bisection algorithm.
  • Same as bisect for non-Copy types.
  • Find a root of the function f on the interval [a, b], with finite bounds assuming f(a) and f(b) have opposite signs and f is continuous using Algorithm 748 by Alefeld, Potro and Shi.
  • Same as toms748 for non-Copy types.