Namespaces

Types in MathNet.Numerics.Differentiation

Type NumericalDerivative

Namespace MathNet.Numerics.Differentiation

Class to evaluate the numerical derivative of a function using finite difference approximations. Variable point and center methods can be initialized . This class can also be used to return function handles (delegates) for a fixed derivative order and variable. It is possible to evaluate the derivative and partial derivative of univariate and multivariate functions respectively.

Constructors

Methods

Properties

Public Constructors

NumericalDerivative(int points, int center)

Initialized a NumericalDerivative class.
Parameters
int points

Number of points for finite difference derivatives.

int center

Location of the center with respect to other points. Value ranges from zero to points-1.

NumericalDerivative()

Initializes a NumericalDerivative class with the default 3 point center difference method.

Public Methods

Func<double, double> CreateDerivativeFunctionHandle(Func<double, double> f, int order)

Creates a function handle for the derivative of a scalar univariate function.
Parameters
Func<double, double> f

Input function handle.

int order

Derivative order.

Return
Func<double, double>

Function handle that evaluates the derivative of input function at a fixed order.

Func<Double[], Double[]> CreateMixedPartialDerivativeFunctionHandle(Func`2[] f, Int32[] parameterIndex, int order)

Func<Double[], double> CreateMixedPartialDerivativeFunctionHandle(Func<Double[], double> f, Int32[] parameterIndex, int order)

Creates a function handle for the mixed partial derivative of a multivariate function.
Parameters
Func<Double[], double> f

Input function handle.

Int32[] parameterIndex

Vector of indices for the independent variables at descending derivative orders.

int order

Highest derivative order.

Return
Func<Double[], double>

Function handle that evaluates the fixed mixed partial derivative of input function at fixed order.

Func<Double[], double> CreatePartialDerivativeFunctionHandle(Func<Double[], double> f, int parameterIndex, int order)

Creates a function handle for the partial derivative of a multivariate function.
Parameters
Func<Double[], double> f

Input function handle.

int parameterIndex

Index of the independent variable for partial derivative.

int order

Derivative order.

Return
Func<Double[], double>

Function handle that evaluates partial derivative of input function at a fixed order.

Func<Double[], Double[]> CreatePartialDerivativeFunctionHandle(Func`2[] f, int parameterIndex, int order)

bool Equals(object obj)

double EvaluateDerivative(Double[] points, int order, double stepSize)

Evaluates the derivative of equidistant points using the finite difference method.
Parameters
Double[] points

Vector of points StepSize apart.

int order

Derivative order.

double stepSize

Finite difference step size.

Return
double

Derivative of points of the specified order.

double EvaluateDerivative(Func<double, double> f, double x, int order, Nullable<double> currentValue)

Evaluates the derivative of a scalar univariate function.
Supplying the optional argument currentValue will reduce the number of function evaluations required to calculate the finite difference derivative.
Parameters
Func<double, double> f

Function handle.

double x

Point at which to compute the derivative.

int order

Derivative order.

Nullable<double> currentValue

Current function value at center.

Return
double

Function derivative at x of the specified order.

double EvaluateMixedPartialDerivative(Func<Double[], double> f, Double[] x, Int32[] parameterIndex, int order, Nullable<double> currentValue)

Evaluates the mixed partial derivative of variable order for multivariate functions.
This function recursively uses EvaluatePartialDerivative to evaluate mixed partial derivative. Therefore, it is more efficient to call EvaluatePartialDerivative for higher order derivatives of a single independent variable.
Parameters
Func<Double[], double> f

Multivariate function handle.

Double[] x

Points at which to evaluate the derivative.

Int32[] parameterIndex

Vector of indices for the independent variables at descending derivative orders.

int order

Highest order of differentiation.

Nullable<double> currentValue

Current function value at center.

Return
double

Function mixed partial derivative at x of the specified order.

Double[] EvaluateMixedPartialDerivative(Func`2[] f, Double[] x, Int32[] parameterIndex, int order, Nullable`1[] currentValue)

Double[] EvaluatePartialDerivative(Func`2[] f, Double[] x, int parameterIndex, int order, Nullable`1[] currentValue)

double EvaluatePartialDerivative(Func<Double[], double> f, Double[] x, int parameterIndex, int order, Nullable<double> currentValue)

Evaluates the partial derivative of a multivariate function.
Parameters
Func<Double[], double> f

Multivariate function handle.

Double[] x

Vector at which to evaluate the derivative.

int parameterIndex

Index of independent variable for partial derivative.

int order

Derivative order.

Nullable<double> currentValue

Current function value at center.

Return
double

Function partial derivative at x of the specified order.

int GetHashCode()

Type GetType()

void ResetEvaluations()

Resets the evaluation counter.

string ToString()

Public Properties

double BaseStepSize get; set;

Sets and gets the base fininte difference step size. This assigned value to this parameter is only used if StepType is set to RelativeX. However, if the StepType is Relative, it will contain the base step size computed from Epsilon based on the finite difference order.

int Center get; set;

Sets and gets the location of the center point for the finite difference derivative.

double Epsilon get; set;

Sets and gets the base finite difference step size. This parameter is only used if StepType is set to Relative. By default this is set to machine epsilon, from which BaseStepSize is computed.

int Evaluations get; set;

Number of times a function is evaluated for numerical derivatives.

double StepSize get; set;

Sets and gets the finite difference step size. This value is for each function evaluation if relative stepsize types are used. If the base step size used in scaling is desired, see Epsilon.
Setting then getting the StepSize may return a different value. This is not unusual since a user-defined step size is converted to a base-2 representable number to improve finite difference accuracy.

StepType StepType get; set;

Type of step size for computing finite differences. If set to absolute, dx = h. If set to relative, dx = (1+abs(x))*h^(2/(order+1)). This provides accurate results when h is approximately equal to the square-root of machine accuracy, epsilon.