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).

§Crate features

  • std (enabled by default).
    Disable (with default-features = false) to compile this crate with #![no_std].
  • rug to compile with support for rug::Float and rug::Rational.

Structs§

Bisect
Bisection algorithm (for Copy types).
BisectMut
Bisection algorithm (for non-Copy types).
BisectMutWorkspace
Workspace needed to run the bisection algorithm for non-Copy types.
Tol
Termination criterion based on a relative tolerance rtol an absolute tolerance atol.
Toms748
toms748 algorithm (for Copy types).
Toms748Mut
toms748_mut algorithm (for non-Copy types).
Toms748MutWorkspace
Workspace needed to run Toms 748 algorithm for non-Copy types.

Enums§

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

Traits§

Bisectable
Trait indicating that the type is suitable for the bisection algorithm.
FloatOrError
A float type or a Result type for floats. This is intended for copy types.
OrdField
Requirements on the type T to be able to use toms748 algorithm.
OrdFieldMut
Requirements on the type T to be able to use toms748_mut algorithm.
SetTolerances
Indicate that the type Self uses relative and absolute tolerances that can be updated from type U.
Terminate
Trait for termination criteria of the bracketing algorithms.
UnitOrError
A unit type or a Result<(), _>.

Functions§

bisect
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.
bisect_mut
Same as bisect for non-Copy types.
toms748
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.
toms748_mut
Same as toms748 for non-Copy types.

Type Aliases§

NoError
Type indicating that no error is raised by the function.