ADD: add `integrate` to `Calculus` trait
@@ -488,6 +488,7 @@ impl PowOps for Polynomial {
pub trait Calculus {
fn derivative(&self) -> Self;
fn integral(&self) -> Self;
+ fn integrate<T: Into<f64> + Copy>(&self, interval: (T, T)) -> f64;
}
impl Calculus for Polynomial {
@@ -510,6 +511,12 @@ impl Calculus for Polynomial {
}
Self::new(result)
}
+
+ fn integrate<T: Into<f64> + Copy>(&self, interval: (T, T)) -> f64 {
+ let (a, b) = (interval.0.into(), interval.1.into());
+ let integral = self.integral();
+ integral.eval(b) - integral.eval(a)
+ }
}
// =============================================================================
