# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.differentiation

## 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.
"C. J. F. Ridders, "Accurate computation of F'(x) and F''(x)," in Adv. Eng. Sftw., 4, 75-76. 1982."

• ### Nested classes/interfaces inherited from interface com.numericalmethod.suanshu.analysis.function.Function

Function.EvaluationException
• ### Constructor Summary

Constructors
Constructor and Description
Ridders(RealScalarFunction f, int[] varidx)
Construct the derivative function of a vector-valued function using Ridder's method.
Ridders(RealScalarFunction f, int[] varidx, double rate, int discretization)
Construct the derivative function of a vector-valued function using Ridder's method.
Ridders(UnivariateRealFunction f, int order)
Construct the derivative function of a univariate function using Ridder's method.
Ridders(UnivariateRealFunction f, int order, double rate, int discretization)
Construct the derivative function of a univariate function using Ridder's method.
• ### Method Summary

All Methods
Modifier and Type Method and Description
double evaluate(double x)
Evaluate f'(x), where f is a UnivariateRealFunction.
Double evaluate(Vector x)
Evaluate the function f at x, where x is from the domain.
double evaluate(Vector x, double h)
Evaluate numerically the derivative of f at point x, f'(x), with step size h.
• ### Methods inherited from class com.numericalmethod.suanshu.analysis.function.rn2r1.AbstractRealScalarFunction

dimensionOfDomain, dimensionOfRange
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### 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
public double evaluate(Vector x,
double h)
x - the point to evaluate f at
h - the step size