numdiff
Numerical differentiation.
Documentation
Please see https://docs.rs/numdiff.
Example
Consider the function
f(x) = (x₀)⁵ + sin³(x₁)
The numdiff
crate provides various functions that can be used to approximate its gradient. Here, we approximate its gradient at x = (5, 8)ᵀ
using numdiff::forward_difference::gradient()
(i.e. using the forward difference approximation). We perform this gradient approximation three times, each time using a different vector type to define the function f(x)
.
use SVector;
use ;
use *;
use gradient;
// f(x) written in terms of a dynamically-sized standard vector (f1), a statically-sized
// nalgebra vector (f2), and a dynamically-sized ndarray vector (f3).
let f1 = ;
let f2 = ;
let f3 = ;
// Evaluation points using the three types of vectors.
let x1: = vec!;
let x2: = from_row_slice;
let x3: = array!;
// Approximate the gradients.
let grad_f1: = gradient;
let grad_f2: = gradient;
let grad_f3: = gradient;
// Verify that the gradient approximations are all identical.
assert_arrays_equal!;
assert_arrays_equal!;