fn trapezoid(rhs: fn(f64) -> f64, a: f64, b: f64, n: i32) -> f64 {
    // Width of one trapezoid
    let h = (b - a) / n as f64;
    let inner_sum = (1..n).fold(0.0, |acc, i| acc + rhs(a + h * i as f64));
    h * (0.5 * rhs(a) + inner_sum + 0.5 * rhs(b))
}
/// Compute numerical integral of function of one real variable using the
/// composite trapezoidal rule.
Compute numerical integral of function of one real variable using the
composite trapezoidal rule.
Compute numerical integral of function of one real variable using the composite trapezoidal rule .
fn trapezoid(rhs: fn(f64) -> f64, a: f64, b: f64, n: i32) -> f64 {
    // Width of one trapezoid
    let h = (b - a) / n as f64;
    let inner_sum = (1..n).fold(0.0, |acc, i| acc + rhs(a + h * i as f64));
    h * (0.5 * rhs(a) + inner_sum + 0.5 * rhs(b))
}
fn trapezoid ( rhs : fn ( f64 ) -> f64 , a : f64 , b : f64 , n : i32 ) -> f64 { // Width of one trapezoid let h = ( b - a ) / n as f64 ; let inner_sum = ( 1 .. n ) . fold ( 0.0 , | acc , i | acc + rhs ( a + h * i as f64 ) ) ; h * ( 0.5 * rhs ( a ) + inner_sum + 0.5 * rhs ( b ) ) }
Compute numerical integral of function of one real variable using the
composite trapezoidal rule.
Compute numerical integral of function of one real variable using the composite trapezoidal rule .
rhs
fn(f64) -> f64
a
f64
b
f64
n
i32
rhs
fn(f64) -> f64
a
f64
b
f64
n
i32