use_calculus_numerical/
basic_usage.rs1use use_calculus::{Differentiator, IntegrationInterval, Integrator, LimitApproximator};
2
3fn main() -> Result<(), use_calculus::CalculusError> {
4 let differentiator = Differentiator::try_new(1.0e-5)?;
5 let interval = IntegrationInterval::try_new(0.0, 1.0)?;
6 let integrator = Integrator::try_new(128)?;
7 let limit = LimitApproximator::try_new(1.0e-6, 1.0e-5)?;
8
9 let slope = differentiator.derivative_at(|x| x.powi(2), 3.0)?;
10 let area = integrator.simpson(|x| x * x, interval)?;
11 let sinc_limit = limit.at(
12 |x| {
13 if x == 0.0 { 1.0 } else { x.sin() / x }
14 },
15 0.0,
16 )?;
17
18 assert!((slope - 6.0).abs() < 1.0e-6);
19 assert!((area - (1.0 / 3.0)).abs() < 1.0e-6);
20 assert!((sinc_limit - 1.0).abs() < 1.0e-5);
21
22 Ok(())
23}