Class Ridders

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

    public class Ridders
    extends AbstractRealScalarFunction
    Ridders' method computes the numerical derivative of a function. In general it gives a higher precision than the simple finite differencing method, c.f., FiniteDifference. Ridders' method tries a sequence of decreasing h's to compute the derivatives, and then extrapolate to zero using Neville's algorithm. The choice of the initial h is critical. If h is too big, the value computed could be inaccurate. If h is too small, due to rounding error, we might be computing the "same" value over and over again for different h's.
    • Constructor Detail

      • Ridders

        public Ridders​(UnivariateRealFunction f,
                       int order,
                       double rate,
                       int discretization)
        Construct the derivative function of a univariate function using Ridder's method.
        Parameters:
        f - the UnivariateRealFunction to take derivative of
        order - the order of differentiation
        rate - the rate at which the increment h decreases; rate should be a simple number such as 0.75, not like 0.66666666666...
        discretization - the number of points for extrapolation
      • Ridders

        public Ridders​(UnivariateRealFunction f,
                       int order)
        Construct the derivative function of a univariate function using Ridder's method.
        Parameters:
        f - the UnivariateRealFunction to take derivative of
        order - the order of the derivative
      • Ridders

        public Ridders​(RealScalarFunction f,
                       int[] varidx,
                       double rate,
                       int discretization)
        Construct the derivative function of a vector-valued function using Ridder's method.

        By convention, varidx = new int[]{1, 2} means \[ f_{x_1,x_2} = {\partial^2 f \over \partial x_1 \partial x_2} = {\partial \over \partial x_2}{\partial \over \partial x_1} \]

        The indices count from 1 up to the number of variables of f, i.e., the domain dimension of f.

        Parameters:
        f - the multivariate function to take derivative of
        varidx - specify the variable indices, numbering from 1 up to the domain dimension of f
        rate - rate should be a simple number, not like 0.66666666666...
        discretization - the number of points used for extrapolation
      • Ridders

        public Ridders​(RealScalarFunction f,
                       int[] varidx)
        Construct the derivative function of a vector-valued function using Ridder's method.

        By convention, varidx = new int[]{1, 2} means \[ f_{x_1,x_2} = {\partial^2 f \over \partial x_1 \partial x_2} = {\partial \over \partial x_2}{\partial \over \partial x_1} \]

        The indices count from 1 up to the number of variables of f, i.e., the domain dimension of f.

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

      • evaluate

        public Double evaluate​(Vector x)
        Evaluate the function f at x, where x is from the domain.

        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, the step size.

        Parameters:
        x - the point to evaluate the derivative of f at
        Returns:
        f'(x), the numerical derivative of f at point x using Ridders' method
        See Also:
        Wikipedia: Practical considerations
      • evaluate

        public double evaluate​(double x)
        Evaluate f'(x), where f is a UnivariateRealFunction.
        Parameters:
        x - the point to evaluate the derivative of f at
        Returns:
        f'(x), the numerical derivative of f at point x using Ridders' method
        See Also:
        Wikipedia: Practical considerations
      • evaluate

        public double evaluate​(Vector x,
                               double h)
        Evaluate numerically the derivative of f at point x, f'(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 f at
        h - the step size
        Returns:
        f'(x), the numerical derivative of f at point x with step size h