Class MultivariateFiniteDifference

  • All Implemented Interfaces:
    Function<Vector,​Double>, RealScalarFunction

    public class MultivariateFiniteDifference
    extends AbstractRealScalarFunction
    A partial derivative of a multivariate function is the derivative with respect to one of the variables with the others held constant. This implementation applies recursively the (first order) finite difference on the function. For example, \[ {\partial^2 \over \partial x_1 \partial x_2} = {\partial \over \partial x_2}({\partial \over \partial x_1}) \] Each of the two univariate derivatives is computed using the central difference method.
    See Also:
    • Constructor Detail

      • MultivariateFiniteDifference

        public MultivariateFiniteDifference​(RealScalarFunction f,
                                            int[] varidx)
        Construct the partial derivative of a multi-variable function.

        For example, varidx = new int[]{1, 2} means \[ f_{x_1,x_2} = {\partial^2 \over \partial x_2 \partial x_1} = {\partial \over \partial x_2}({\partial \over \partial x_1}) \]

        Parameters:
        f - the real multivariate function to take derivative of
        varidx - the variable indices of the derivative, counting from 1 up to the domain dimension of f
    • Method Detail

      • evaluate

        public Double evaluate​(Vector x)
        Evaluate numerically the partial derivative of f at point x.

        Make sure that h and x+h are representable in floating point precision so that the difference between x+h and x is exactly h.

        Parameters:
        x - the point to evaluate the derivative at
        Returns:
        the numerical partial derivative of f at point x
        See Also:
        Wikipedia: Practical considerations
      • evaluate

        public double evaluate​(Vector x,
                               double h)
        Evaluate numerically the partial derivative of f at point x with step size h. It could be challenging to automatically determine the step size h, esp. when |x| is near 0. It may, for example, require an analysis that involves f' and f''. The user may want to experiment with different hs by calling this function.
        Parameters:
        x - the point to evaluate the derivative of f at
        h - the step size
        Returns:
        the numerical partial derivative of f at point x with step size h