pub struct Integrator { /* private fields */ }Expand description
Numerical integration configuration.
Implementations§
Source§impl Integrator
impl Integrator
Sourcepub fn try_new(subintervals: usize) -> Result<Self, CalculusError>
pub fn try_new(subintervals: usize) -> Result<Self, CalculusError>
Creates an integrator from a positive subinterval count.
§Errors
Returns CalculusError::ZeroSubintervals when subintervals == 0.
Examples found in repository?
examples/basic_usage.rs (line 6)
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}Sourcepub fn validate(self) -> Result<Self, CalculusError>
pub fn validate(self) -> Result<Self, CalculusError>
Validates that the stored subinterval count is positive.
§Errors
Returns the same error variants as Self::try_new.
Sourcepub const fn subintervals(&self) -> usize
pub const fn subintervals(&self) -> usize
Returns the stored subinterval count.
Sourcepub fn trapezoidal<F>(
self,
function: F,
interval: IntegrationInterval,
) -> Result<f64, CalculusError>
pub fn trapezoidal<F>( self, function: F, interval: IntegrationInterval, ) -> Result<f64, CalculusError>
Approximates a definite integral with the trapezoidal rule.
§Errors
Returns CalculusError when the interval or subinterval count is
invalid, or when sampled evaluations are not finite.
Sourcepub fn simpson<F>(
self,
function: F,
interval: IntegrationInterval,
) -> Result<f64, CalculusError>
pub fn simpson<F>( self, function: F, interval: IntegrationInterval, ) -> Result<f64, CalculusError>
Approximates a definite integral with Simpson’s rule.
§Errors
Returns CalculusError when the interval or subinterval count is
invalid, when an odd number of subintervals is used, or when sampled
evaluations are not finite.
Examples found in repository?
examples/basic_usage.rs (line 10)
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}Trait Implementations§
Source§impl Clone for Integrator
impl Clone for Integrator
Source§fn clone(&self) -> Integrator
fn clone(&self) -> Integrator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Integrator
impl Debug for Integrator
Source§impl PartialEq for Integrator
impl PartialEq for Integrator
Source§fn eq(&self, other: &Integrator) -> bool
fn eq(&self, other: &Integrator) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Copy for Integrator
impl Eq for Integrator
impl StructuralPartialEq for Integrator
Auto Trait Implementations§
impl Freeze for Integrator
impl RefUnwindSafe for Integrator
impl Send for Integrator
impl Sync for Integrator
impl Unpin for Integrator
impl UnsafeUnpin for Integrator
impl UnwindSafe for Integrator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more