13#ifndef DUMUX_NUMERIC_DIFFERENTIATION_HH
14#define DUMUX_NUMERIC_DIFFERENTIATION_HH
34 template<
class Scalar>
35 static Scalar
epsilon(
const Scalar value,
const Scalar baseEps = 1e-10)
37 assert(std::numeric_limits<Scalar>::epsilon()*1e4 < baseEps);
41 return baseEps*(abs(value) + 1.0);
48 template<
class Function,
class Scalar,
class FunctionEvalType>
50 FunctionEvalType& derivative,
51 const FunctionEvalType& fx0,
52 const int numericDifferenceMethod = 1)
65 template<
class Function,
class Scalar,
class FunctionEvalType>
67 FunctionEvalType& derivative,
68 const FunctionEvalType& fx0,
70 const int numericDifferenceMethod = 1)
74 if (numericDifferenceMethod >= 0)
78 derivative = function(x0 + eps);
84 else derivative = fx0;
88 if (numericDifferenceMethod <= 0)
92 derivative -= function(x0 - eps);
98 else derivative -= fx0;
A class for numeric differentiation with respect to a scalar parameter.
Definition: numericdifferentiation.hh:26
static Scalar epsilon(const Scalar value, const Scalar baseEps=1e-10)
Computes the epsilon used for numeric differentiation.
Definition: numericdifferentiation.hh:35
static void partialDerivative(const Function &function, Scalar x0, FunctionEvalType &derivative, const FunctionEvalType &fx0, const int numericDifferenceMethod=1)
Computes the derivative of a function with respect to a function parameter.
Definition: numericdifferentiation.hh:49
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 respect to a function parameter.
Definition: numericdifferentiation.hh:66