1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Numerical integration.
//!
//! - [`integral`] — the short way to integrate one function over one interval.
//! - [`GaussianSingle`] / [`GaussianMulti`] — Gaussian quadrature (nodes from
//! [`gaussian_tables`](crate::gaussian_tables)), picking a family with
//! [`GaussianQuadratureMethod`].
//! - [`IterativeSingle`] / [`IterativeMulti`] — iterative refinement of a running estimate, picking
//! a rule with [`IterativeMethod`].
//! - [`IntegratorSingleVariable`] / [`IntegratorMultiVariable`] — the shared integrator traits.
pub use crateSummationMethod;
pub use ;
pub use ;
pub use ;
pub use ;
use crateIntegrateError;
use crateNumeric;
/// The integral of a single-variable function over an interval.
///
/// This picks a method on your behalf: it walks the interval in [`DEFAULT_TOTAL_ITERATIONS`] steps
/// using Boole's rule, which is the strongest all-round choice for a smooth integrand. Reach for
/// [`IterativeSingle`] to change the rule or the step count, or [`GaussianSingle`] for quadrature.
/// Either limit may be infinite.
///
/// # Errors
/// [`IntegrateError::LimitsIllDefined`] if the limits are reversed, equal, `NaN`, or point the
/// wrong way at an infinity, or [`IntegrateError::NonFinite`] if the integrand blows up on the way.
///
/// # Examples
/// ```
/// use multicalc::numerical_integration::integral;
/// # fn main() -> Result<(), multicalc::error::IntegrateError> {
/// let line = |x: f64| 2.0 * x;
/// let limits = [0.0, 2.0];
///
/// let area = integral(&line, limits)?; // 2x over [0, 2] is 4
/// assert!((area - 4.0).abs() < 1e-9);
///
/// // a decaying integrand may run to infinity
/// let decay = |x: f64| (-x).exp();
/// let to_infinity = [0.0, f64::INFINITY];
///
/// let tail = integral(&decay, to_infinity)?; // e^-x over [0, inf) is 1
/// assert!((tail - 1.0).abs() < 1e-6);
/// # Ok(())
/// # }
/// ```