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 (withdefault-features = false
) to compile this crate with#![no_std]
.rug
to compile with support forrug::Float
andrug::Rational
.
Structs§
- Bisect
- Bisection algorithm (for
Copy
types). - Bisect
Mut - Bisection algorithm (for non-
Copy
types). - Bisect
MutWorkspace - Workspace needed to run the bisection algorithm for non-Copy types.
- Tol
- Termination criterion based on a relative tolerance
rtol
an absolute toleranceatol
. - Toms748
toms748
algorithm (forCopy
types).- Toms748
Mut toms748_mut
algorithm (for non-Copy
types).- Toms748
MutWorkspace - 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.
- Float
OrError - 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 usetoms748
algorithm. - OrdField
Mut - Requirements on the type
T
to be able to usetoms748_mut
algorithm. - SetTolerances
- Indicate that the type
Self
uses relative and absolute tolerances that can be updated from typeU
. - Terminate
- Trait for termination criteria of the bracketing algorithms.
- Unit
OrError - A unit type or a
Result<(), _>
.
Functions§
- bisect
- Find a root of the function
f
on the interval [a
,b
] with finite bounds assumingf(a)
andf(b)
have opposite signs andf
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 assumingf(a)
andf(b)
have opposite signs andf
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.