|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.analysis.differentiation.Ridders
public class Ridders
This class computes the numerical derivative of a function using Ridders' method.
This method in general 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 com.numericalmethod.suanshu.analysis.function.Function |
|---|
Function.EvaluationException |
| Field Summary | |
|---|---|
RealScalarFunction |
f
the function to take the derivative of |
static int |
N_POINTS_4_EXTRAPOLATION
the default number of points for extrapolation |
int |
nPoints4Extrapolation
the number of points for extrapolation |
int |
order
the order of the derivative |
double |
rate
the rate at which h decreases |
| Constructor Summary | |
|---|---|
Ridders(RealScalarFunction f,
int[] varidx)
Construct the derivative function of a real vector-valued function using Ridder's method. |
|
Ridders(RealScalarFunction f,
int[] varidx,
double rate,
int nPoints4Extrapolation)
Construct the derivative function of a real 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 nPoints4Extrapolation)
Construct the derivative function of a univariate function using Ridder's method. |
|
| Method Summary | |
|---|---|
int |
dimension4Domain()
Get the number of variables of the function. |
int |
dimension4Range()
Get the dimension of the range space the function. |
double |
evaluate(double... x)
A real function, f, takes a double array double[],
{x0, x1, ..., xn}
and maps it to a double,
f(x0, x1, ..., xn) |
double |
evaluate(double[] x,
double h)
Numerically evaluate the derivative of f at point x with step size h. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int N_POINTS_4_EXTRAPOLATION
public final RealScalarFunction f
public final int order
public final double rate
h decreases
public final int nPoints4Extrapolation
| Constructor Detail |
|---|
public Ridders(UnivariateRealFunction f,
int order,
double rate,
int nPoints4Extrapolation)
f - the UnivariateRealFunction 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...nPoints4Extrapolation - number of points used for extrapolation
public Ridders(UnivariateRealFunction f,
int order)
f - the UnivariateRealFunction to take derivative oforder - the order of the derivative
public Ridders(RealScalarFunction f,
int[] varidx,
double rate,
int nPoints4Extrapolation)
For example,
varidx = new int[]{1, 2} means
∂f
fx1,x2 = -------
∂x2∂x1
∂ ∂
= ---( ---- )
∂x2 ∂x1
The indices count from 1 up to the number of variables of f,
i.e., the domain dimension of f.
f - the real 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...nPoints4Extrapolation - number of points used for extrapolation
public Ridders(RealScalarFunction f,
int[] varidx)
For example,
varidx = new int[]{1, 2} means
∂f
fx1,x2 = -------
∂x2∂x1
∂ ∂
= ---( ---- )
∂x2 ∂x1
The indices count from 1 up to the number of variables of f,
i.e., the domain dimension of f.
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 |
|---|
public double evaluate(double... x)
f, takes a double array double[],
and maps it to a double,{x0,x1, ...,xn}
f(x0, x1, ..., xn)
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.
evaluate in interface RealScalarFunctionx - the point to evaluate the derivative of f at
f at point x using Ridders' method
public double evaluate(double[] x,
double h)
f at point x with step size h.
Automatically determining the step size h could be challenging, esp. for when |x| is near 0.
An analysis that involves f' and f'' may be needed to determine the step size.
User may want to experiment with different hs by calling this function.
x - the point to evaluate f ath - step size
f at point x with step size h using Ridders' methodpublic int dimension4Domain()
FunctionFor example, for a univariate function, the domain dimension is 1. For a bivariate function, the domain dimension is 2.
dimension4Domain in interface Functionpublic int dimension4Range()
Function
For example, for a Rn->Rm function, the dimension of the range is m.
dimension4Range in interface Function
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||