kaede 0.1.2

Kaede adalah rust library untuk operasi matematika sederhana.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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)
}