pub struct Differentiator { /* private fields */ }Expand description
Finite-difference differentiation configuration.
Implementations§
Source§impl Differentiator
impl Differentiator
Sourcepub const fn new(step: f64) -> Differentiator
pub const fn new(step: f64) -> Differentiator
Creates a differentiator with the given sample step.
Sourcepub fn try_new(step: f64) -> Result<Differentiator, CalculusError>
pub fn try_new(step: f64) -> Result<Differentiator, CalculusError>
Creates a differentiator from a finite positive step.
§Errors
Returns CalculusError::NonFiniteStep when step is NaN or
infinite, and CalculusError::NonPositiveStep when step <= 0.0.
§Examples
use use_calculus::{CalculusError, Differentiator};
let differentiator = Differentiator::try_new(1.0e-4)?;
assert_eq!(differentiator, Differentiator::new(1.0e-4));
assert!(matches!(
Differentiator::try_new(0.0),
Err(CalculusError::NonPositiveStep(0.0))
));Sourcepub fn validate(self) -> Result<Differentiator, CalculusError>
pub fn validate(self) -> Result<Differentiator, CalculusError>
Validates that the stored step is finite and positive.
§Errors
Returns the same error variants as Self::try_new.
Sourcepub fn derivative_at<F>(
self,
function: F,
at: f64,
) -> Result<f64, CalculusError>
pub fn derivative_at<F>( self, function: F, at: f64, ) -> Result<f64, CalculusError>
Approximates the first derivative using the central-difference formula.
§Errors
Returns CalculusError when the stored step is invalid, at is not
finite, or sampled evaluations are not finite.
§Examples
use use_calculus::Differentiator;
let differentiator = Differentiator::try_new(1.0e-5)?;
let slope = differentiator.derivative_at(|x| x.powi(2), 3.0)?;
assert!((slope - 6.0).abs() < 1.0e-6);Sourcepub fn second_derivative_at<F>(
self,
function: F,
at: f64,
) -> Result<f64, CalculusError>
pub fn second_derivative_at<F>( self, function: F, at: f64, ) -> Result<f64, CalculusError>
Approximates the second derivative using the central-difference formula.
§Errors
Returns CalculusError when the stored step is invalid, at is not
finite, or sampled evaluations are not finite.
Trait Implementations§
Source§impl Clone for Differentiator
impl Clone for Differentiator
Source§fn clone(&self) -> Differentiator
fn clone(&self) -> Differentiator
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 Differentiator
impl Debug for Differentiator
Source§impl PartialEq for Differentiator
impl PartialEq for Differentiator
Source§fn eq(&self, other: &Differentiator) -> bool
fn eq(&self, other: &Differentiator) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Copy for Differentiator
impl StructuralPartialEq for Differentiator
Auto Trait Implementations§
impl Freeze for Differentiator
impl RefUnwindSafe for Differentiator
impl Send for Differentiator
impl Sync for Differentiator
impl Unpin for Differentiator
impl UnsafeUnpin for Differentiator
impl UnwindSafe for Differentiator
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