lib_jsl_integration/can_integrate.rs
1//! The common interface of the one-dimensional quadrature engines.
2
3use lib_jsl_core::ErrorsJSL;
4
5/// A one-dimensional quadrature rule on an interval `[a, b]`, approximating `∫ₐᵇ f(x) dx`.
6///
7/// Engines are configured at construction (number of points, tolerance, …); the bounds can be
8/// changed afterwards, so one engine can be reused across many integrals. See the book's
9/// [numerical integration chapter](https://jwkunz.github.io/lib_jsl/book/integration/index.html)
10/// for how to choose an engine.
11pub trait CanIntegrate1D {
12 /// Sets the lower bound `a`.
13 fn set_lower_bound(&mut self, x: f64);
14 /// Sets the upper bound `b`.
15 fn set_upper_bound(&mut self, x: f64);
16 /// Approximates `∫ₐᵇ f(x) dx`.
17 fn integrate<F>(&self, f: F) -> Result<f64, ErrorsJSL>
18 where
19 F: Fn(f64) -> f64;
20}