mathhook_core/calculus/integrals/
numerical.rs

1//! Numerical integration methods
2//!
3//! Provides numerical quadrature algorithms for approximate evaluation
4//! of definite integrals when symbolic integration is not feasible.
5
6pub mod gaussian;
7pub mod romberg;
8pub mod simpson;
9
10pub use gaussian::GaussianQuadrature;
11pub use romberg::RombergIntegration;
12pub use simpson::AdaptiveSimpson;
13
14use crate::error::MathError;
15
16/// Configuration for numerical integrators
17#[derive(Debug, Clone)]
18pub struct IntegrationConfig {
19    pub tolerance: f64,
20    pub max_iterations: usize,
21    pub min_subdivisions: usize,
22}
23
24impl Default for IntegrationConfig {
25    fn default() -> Self {
26        Self {
27            tolerance: 1e-10,
28            max_iterations: 1000,
29            min_subdivisions: 1,
30        }
31    }
32}
33
34/// Result of numerical integration
35#[derive(Debug, Clone)]
36pub struct IntegrationResult {
37    pub value: f64,
38    pub error_estimate: f64,
39    pub iterations: usize,
40    pub subdivisions: usize,
41}
42
43/// Trait for numerical integrators
44pub trait NumericalIntegrator {
45    /// Integrate a function over an interval
46    ///
47    /// # Arguments
48    ///
49    /// * `f` - Function to integrate (as closure)
50    /// * `a` - Lower bound of integration
51    /// * `b` - Upper bound of integration
52    /// * `config` - Integration configuration
53    ///
54    /// # Returns
55    ///
56    /// Integration result with value and error estimate
57    fn integrate<F>(
58        &self,
59        f: F,
60        a: f64,
61        b: f64,
62        config: &IntegrationConfig,
63    ) -> Result<IntegrationResult, MathError>
64    where
65        F: Fn(f64) -> f64;
66}