|
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.function.rn2r1.UnivariateRealFunction
com.numericalmethod.suanshu.analysis.differentiation.univariate.FiniteDifference
public class FiniteDifference
A finite difference (divided by a small increment) is an approximation of the derivative of a function.
The accuracy of central difference is the best while those of forward and backward differences are more or less the same.
In general, for finite difference the higher an order of a derivative, the less accurate it gets. For example, approximating the 5-th derivative is much less accurate than approximating the 1st derivative. Also, the accuracy depends on the function to take the derivative of.
| Nested Class Summary | |
|---|---|
static class |
FiniteDifference.Type
the types of finite difference available |
| Nested classes/interfaces inherited from interface com.numericalmethod.suanshu.analysis.function.Function |
|---|
Function.EvaluationException |
| Field Summary | |
|---|---|
UnivariateRealFunction |
f
the univariate function to take the derivative of |
int |
order
the order of the derivative |
FiniteDifference.Type |
type
the type of finite difference chosen |
| Constructor Summary | |
|---|---|
FiniteDifference(UnivariateRealFunction f,
int order,
FiniteDifference.Type type)
Construct an approximation of the derivative function for f using finite difference. |
|
| Method Summary | |
|---|---|
double |
df(double x,
double h)
Compute the finite difference for f at x with an increment h
for the n-th order
using either forward, backward, or central difference. |
double |
evaluate(double x)
Numerically evaluate the derivative of f at point x. |
double |
evaluate(double[] x,
double h)
Numerically evaluate the derivative of f at point x with step size h. |
| Methods inherited from class com.numericalmethod.suanshu.analysis.function.rn2r1.UnivariateRealFunction |
|---|
dimension4Domain, dimension4Range, evaluate |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public final UnivariateRealFunction f
public final int order
public final FiniteDifference.Type type
| Constructor Detail |
|---|
public FiniteDifference(UnivariateRealFunction f,
int order,
FiniteDifference.Type type)
f using finite difference.
f - a univariate functionorder - the order of the derivativetype - the type of finite difference type to use, c.f., FiniteDifference.Type| Method Detail |
|---|
public double evaluate(double x)
f at point x.
evaluate in class UnivariateRealFunctionx - the point to evaluate the derivative at
f at point x
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. when |x| is near 0.
An analysis that involves f' and f'' may be needed to determine the proper step size.
User may want to experiment with different h's by calling this function.
x - the point to evaluate the derivative of f at.
Although it is a double[] array, only x[0] is used (f is univariate).h - step size
f at point x using step size h
public double df(double x,
double h)
f at x with an increment h
for the n-th order
using either forward, backward, or central difference.
x - evaluate the function at xh - the increment
dnh[f](x)
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||