mathhook_core/algebra/
root_finding.rs1pub mod bisection;
7pub mod newton_raphson;
8pub mod secant;
9
10pub use bisection::BisectionMethod;
11pub use newton_raphson::NewtonRaphson;
12pub use secant::SecantMethod;
13
14use crate::error::MathError;
15
16#[derive(Debug, Clone)]
18pub struct RootFindingConfig {
19 pub tolerance: f64,
20 pub max_iterations: usize,
21 pub derivative_h: f64,
22}
23
24impl Default for RootFindingConfig {
25 fn default() -> Self {
26 Self {
27 tolerance: 1e-10,
28 max_iterations: 1000,
29 derivative_h: 1e-8,
30 }
31 }
32}
33
34#[derive(Debug, Clone)]
36pub struct RootResult {
37 pub root: f64,
38 pub iterations: usize,
39 pub function_value: f64,
40 pub converged: bool,
41}
42
43pub trait RootFinder {
45 fn find_root<F>(&self, f: F, config: &RootFindingConfig) -> Result<RootResult, MathError>
56 where
57 F: Fn(f64) -> f64;
58}