Package dev.nm.analysis.differentiation
Class Ridders
- java.lang.Object
-
- dev.nm.analysis.function.rn2r1.AbstractRealScalarFunction
-
- dev.nm.analysis.differentiation.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface dev.nm.analysis.function.Function
Function.EvaluationException
-
-
Constructor Summary
Constructors Constructor 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 Instance Methods Concrete Methods Modifier and Type Method Description double
evaluate(double x)
Evaluate f'(x), where f is aUnivariateRealFunction
.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 dev.nm.analysis.function.rn2r1.AbstractRealScalarFunction
dimensionOfDomain, dimensionOfRange
-
-
-
-
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
- theUnivariateRealFunction
to take derivative oforder
- the order of differentiationrate
- 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
- theUnivariateRealFunction
to take derivative oforder
- 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 ofvaridx
- specify the variable indices, numbering from 1 up to the domain dimension of frate
-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 ofvaridx
- 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 aUnivariateRealFunction
.- 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 ath
- the step size- Returns:
- f'(x), the numerical derivative of f at point x with step size h
-
-