pub struct LimitApproximator { /* private fields */ }Expand description
Symmetric two-sided limit approximation settings.
Implementations§
Source§impl LimitApproximator
impl LimitApproximator
Sourcepub const fn new(step: f64, tolerance: f64) -> Self
pub const fn new(step: f64, tolerance: f64) -> Self
Creates a limit approximator from a sample step and comparison tolerance.
Sourcepub fn try_new(step: f64, tolerance: f64) -> Result<Self, CalculusError>
pub fn try_new(step: f64, tolerance: f64) -> Result<Self, CalculusError>
Creates a limit approximator from a finite positive step and a finite non-negative tolerance.
§Errors
Returns CalculusError::NonFiniteStep or
CalculusError::NonPositiveStep when step is invalid, and returns
CalculusError::NonFiniteTolerance or
CalculusError::NegativeTolerance when tolerance is invalid.
Examples found in repository?
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 step and tolerance are acceptable.
§Errors
Returns the same error variants as Self::try_new.
Sourcepub const fn tolerance(&self) -> f64
pub const fn tolerance(&self) -> f64
Returns the acceptance tolerance between the left and right samples.
Sourcepub fn at<F>(self, function: F, at: f64) -> Result<f64, CalculusError>
pub fn at<F>(self, function: F, at: f64) -> Result<f64, CalculusError>
Approximates a two-sided limit at at using one symmetric sample scale.
§Errors
Returns CalculusError when the stored step or tolerance is invalid,
at is not finite, sampled evaluations are not finite, or the left and
right samples disagree by more than tolerance.
Examples found in repository?
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 LimitApproximator
impl Clone for LimitApproximator
Source§fn clone(&self) -> LimitApproximator
fn clone(&self) -> LimitApproximator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LimitApproximator
impl Debug for LimitApproximator
Source§impl PartialEq for LimitApproximator
impl PartialEq for LimitApproximator
Source§fn eq(&self, other: &LimitApproximator) -> bool
fn eq(&self, other: &LimitApproximator) -> bool
self and other values to be equal, and is used by ==.