Skip to content

Added generic numerical differentiation algorithm

Christoph Lehmann requested to merge chleh/ogs:num-diff into master
  1. Feature description was added to the changelog
  2. Tests covering your feature were added?
  3. Any new feature or behavior change was documented?

How to use

NumLib::NumericalDerivative<NumLib::CentralDifferencesStrategy> deriv{

auto const [dfdt, dfdxy, dfdz] =
        deriv(&fNumDiffVectorial, t, Eigen::Vector2d{x, y}, z);

Should work with all functions (plain functions, function objects, lambdas) that take double values or Eigen (column) vectors as input and return values with basic arithmetic capabilites (subtraction and division), e.g.:

struct NumDiffXY
    NumDiffXY(double x, double y) : x{x}, y{y} {}
    explicit NumDiffXY(Eigen::Vector2d const& xy) : x{xy[0]}, y{xy[1]} {}

    NumDiffXY operator-(NumDiffXY const& other) const
        return {x - other.x, y - other.y};

    NumDiffXY operator/(double a) const { return {x / a, y / a}; }

    double x;
    double y;
Edited by Christoph Lehmann

Merge request reports