[−][src]Function reikna::derivative::nth_derivative
pub fn nth_derivative(n: u64, f: &Function) -> Function
Return a Function
estimating the n
th derivative of f
.
This function will return a Function
that estimates the
n
th derivative of f
using the limit definition of the
derivative:
f(x + h) - f(x)
f'(x) = lim ---------------
h -> 0 h
Where h
is equal to EPSILON
. See the documentation for
EPSILON
for more information.
This function will use recursion to provide derivatives for n > 1
.
It is important to note that the inaccuracy of the derivative
estimates compound each other, the higher n
is, the less precise
the resulting function will be!
If n = 0
, then a clone()
of f
is returned.
Examples
#[macro_use] extern crate reikna; use reikna::derivative::*; let f = func![|x| x * x]; let first_deriv = nth_derivative(1, &f); let second_deriv = nth_derivative(2, &f); println!("f(5) = {}", f(5.0)); println!("f'(5) = {}", first_deriv(5.0)); println!("f''(5) = {}", second_deriv(5.0));
Outputs:
f(5) = 25
f'(5) = 10.00000100148668
f''(5) = 2.000177801164682