25#ifndef DUMUX_NUMERIC_DIFFERENTIATION_HH
26#define DUMUX_NUMERIC_DIFFERENTIATION_HH
46 template<
class Scalar>
47 static Scalar
epsilon(
const Scalar value,
const Scalar baseEps = 1e-10)
49 assert(std::numeric_limits<Scalar>::epsilon()*1e4 < baseEps);
53 return baseEps*(abs(value) + 1.0);
60 template<
class Function,
class Scalar,
class FunctionEvalType>
62 FunctionEvalType& derivative,
63 const FunctionEvalType& fx0,
64 const int numericDifferenceMethod = 1)
77 template<
class Function,
class Scalar,
class FunctionEvalType>
79 FunctionEvalType& derivative,
80 const FunctionEvalType& fx0,
82 const int numericDifferenceMethod = 1)
86 if (numericDifferenceMethod >= 0)
90 derivative = function(x0 + eps);
96 else derivative = fx0;
100 if (numericDifferenceMethod <= 0)
104 derivative -= function(x0 - eps);
110 else derivative -= fx0;
A class for numeric differentiation with respect to a scalar parameter.
Definition: numericdifferentiation.hh:38
static Scalar epsilon(const Scalar value, const Scalar baseEps=1e-10)
Computes the epsilon used for numeric differentiation.
Definition: numericdifferentiation.hh:47
static void partialDerivative(const Function &function, Scalar x0, FunctionEvalType &derivative, const FunctionEvalType &fx0, const int numericDifferenceMethod=1)
Computes the derivative of a function with repect to a function parameter.
Definition: numericdifferentiation.hh:61
static void partialDerivative(const Function &function, Scalar x0, FunctionEvalType &derivative, const FunctionEvalType &fx0, const Scalar eps, const int numericDifferenceMethod=1)
Computes the derivative of a function with repect to a function parameter.
Definition: numericdifferentiation.hh:78