FiniteDifferences Class
Click or drag to resize
Accord.NET (logo)

FiniteDifferences Class

Derivative approximation by finite differences.
Inheritance Hierarchy
SystemObject
  Accord.Math.DifferentiationFiniteDifferences

Namespace:  Accord.Math.Differentiation
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public class FiniteDifferences
Request Example View Source

The FiniteDifferences type exposes the following members.

Constructors
  NameDescription
Public methodFiniteDifferences(Int32)
Initializes a new instance of the FiniteDifferences class.
Public methodFiniteDifferences(Int32, FuncDouble, Double)
Initializes a new instance of the FiniteDifferences class.
Public methodFiniteDifferences(Int32, Int32)
Initializes a new instance of the FiniteDifferences class.
Public methodFiniteDifferences(Int32, FuncDouble, Double, Int32)
Initializes a new instance of the FiniteDifferences class.
Public methodFiniteDifferences(Int32, Int32, Double)
Initializes a new instance of the FiniteDifferences class.
Public methodFiniteDifferences(Int32, FuncDouble, Double, Int32, Double)
Initializes a new instance of the FiniteDifferences class.
Top
Properties
  NameDescription
Public propertyFunction
Gets or sets the function to be differentiated.
Public propertyNumberOfPoints
Gets or sets the number of points to be used when computing the approximation. Default is 3.
Public propertyNumberOfVariables
Gets the number of parameters expected by the Function to be differentiated.
Public propertyOrder
Gets or sets the order of the partial derivatives to be obtained. Default is 1 (computes the first derivative).
Public propertyPoints Obsolete.
Obsolete. Please use NumberOfPoints instead.
Public propertyStepSize
Gets or sets the relative step size used to approximate the derivatives. Default is 1e-2. Setting this property updates the step size for all parameters at once. To adjust only a single parameter, please refer to StepSizes instead.
Public propertyStepSizes
Gets or sets the relative step sizes used to approximate the derivatives. Default is 1e-2.
Top
Methods
  NameDescription
Public methodCompute(Double) Obsolete.
Public methodCompute(Double, Double) Obsolete.
Public methodStatic memberCreateCoefficients
Creates the interpolation coefficient table for interpolated numerical differentation.
Public methodStatic memberDerivative(FuncDouble, Double, Double)
Computes the derivative for a simpler unidimensional function.
Public methodStatic memberDerivative(FuncDouble, Double, Double, Int32)
Computes the derivative for a simpler unidimensional function.
Public methodStatic memberDerivative(FuncDouble, Double, Double, Int32, Double)
Computes the derivative for a simpler unidimensional function.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGradient(Double)
Computes the gradient at the given point x.
Public methodGradient(Double, Double)
Computes the gradient at the given point x, storing the result at result.
Public methodStatic memberGradient(FuncDouble, Double, Int32, Int32)
Obtains the gradient function for a multidimensional function.
Public methodHessian(Double)
Computes the Hessian matrix at given point x.
Public methodHessian(Double, Double)
Computes the Hessian matrix at given point x.
Public methodStatic memberHessian(FuncDouble, Double, Int32)
Obtains the Hessian function for a multidimensional function.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

Numerical differentiation is a technique of numerical analysis to produce an estimate of the derivative of a mathematical function or function subroutine using values from the function and perhaps other knowledge about the function.

A finite difference is a mathematical expression of the form f(x + b) − f(x + a). If a finite difference is divided by b − a, one gets a difference quotient. The approximation of derivatives by finite differences plays a central role in finite difference methods for the numerical solution of differential equations, especially boundary value problems.

This class implements Newton's finite differences method for approximating the derivatives of a multivariate function. A simplified version of the class is also available for univariate functions through its Derivative static methods.

References:

Examples
// Create a simple function with two parameters: f(x,y) = x² + y
Func<double[], double> function = x => Math.Pow(x[0], 2) + x[1];

// The gradient w.r.t to x should be 2x,
// the gradient w.r.t to y should be  1


// Create a new finite differences calculator
var calculator = new FiniteDifferences(2, function);

// Evaluate the gradient function at the point (2, -1)
double[] result = calculator.Compute(2, -1); // answer is (4, 1)
// Create a simple function with two parameters: f(x,y) = x² + y
Func<double[], double> function = x => Math.Pow(x[0], 2) + x[1];

// The gradient w.r.t to x should be 2x,
// the gradient w.r.t to y should be  1

// Create a new finite differences calculator
var calculator = new FiniteDifferences(2, function);

// Evaluate the gradient function at the point (2, -1)
double[][] result = calculator.Hessian(new[] { 2.0, -1.0 }); // answer is [(2, 0), (0, 0)]
See Also