pub fn minimize_scalar(
f: impl Fn(f64) -> f64,
a: f64,
b: f64,
opts: &MinimizeOpts,
) -> Result<ScalarMinimum, SymplexError>Expand description
Minimise a scalar function on [a, b] by Brent’s method.
Combines golden-section steps with successive parabolic interpolation
(Brent’s localmin), giving superlinear convergence on smooth functions
and golden-section behaviour otherwise. Returns the minimiser and the
value there as a ScalarMinimum. On a bracket containing several
local minima the method converges to one of them; which one depends on
the bracket. A reversed interval is accepted.
§Errors
SymplexError::InvalidArgumentif an endpoint is not finite, the interval has zero width, or the options are negative.SymplexError::ComputationFailediffreturns a non-finite value or the tolerance is not met within the iteration budget (default200).
§Examples
use symplex::optimize::{minimize_scalar, MinimizeOpts};
let m = minimize_scalar(|x| (x - 1.0).powi(2) + 3.0, -5.0, 5.0, &MinimizeOpts::default()).unwrap();
assert!((m.x - 1.0).abs() < 1e-6);
assert!((m.value - 3.0).abs() < 1e-12);