use crate::MathError;
pub fn integral<F>(f: F, a: f64, b: f64, n: usize) -> Result<f64, MathError>
where
F: Fn(f64) -> f64,
{
if n == 0 {
return Err(MathError::TipeError("Jumlah interval tidak boleh nol".to_string()));
}
let h = (b - a) / n as f64;
let mut sum = 0.5 * (f(a) + f(b));
for i in 1..n {
sum += f(a + i as f64 * h);
}
Ok(sum * h)
}