1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
//! Utility methods. /// Compares two functions of a single variable. pub fn cmp<F, G>( n: u32, start: f64, end: f64, f: F, g: G ) -> f64 where F: Fn(f64) -> f64, G: Fn(f64) -> f64 { let mut sum = 0.0; for i in 0..n { let x = i as f64 / n as f64 * (end - start) + start; sum += (f(x) - g(x)).powi(2); } sum / n as f64 }