Expand description
Bracket generation.
A bracket is a closed interval [a, b] where the signs at a and b differ. For continuous functions this guarantees the interval contains at least one root.
Brackets are used directly by bracketing root finders like bisection. They also allow for “safe” variants of iterative methods which avoid stepping outside the bracket, stay within the bracket, falling back to bisection if needed, and ensuring global convergence.
Brackets can be generated by sweeping a window over a region of interest and looking for sign changes at the window boundary.
There are several pitfalls:
- Roots which touch but don’t cross the x-axis can’t be detected using a sliding window.
- Windows which are “too large” may miss the root. (e.g. function dips under x axis and back up again all inside the same window bounds).
- Windows which are “too large” may capture multiple roots. Root finding algorithms operating on the bracket will only converge on one of the contained roots.
§Examples
use rootfind::bracket::{BracketGenerator, Bounds};
use rootfind::wrap::RealFn;
// roots at 0, pi, 2pi, ...
let fin = |x: f64| x.sin();
let f = RealFn::new(&fin);
// search for root-holding brackets
let window_size = 0.1;
let bounds = Bounds::new(-0.1, 6.3);
let brackets: Vec<Bounds> =
BracketGenerator::new(&f, bounds, window_size).into_iter().collect();
assert_eq!(brackets.len(), 3);The resulting brackets can be passed to a root finding method like bisection() to locate the actual roots.
Structs§
- Bounds
- Bounds represents the closed finite interval [a,b].
- Bracket
Generator - BracketGenerator is an iterator that emits root-holding brackets.
Functions§
- first_
bracket - Scans interval [a, b] and emits the first bracket containing a sign change.
- is_
sign_ change - Check if signs differ while properly handling floating point underflow.