|
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.multivariate.FiniteDifference
public class FiniteDifference
This class computes the numerical partial derivative of a function.
A partial derivative of a multivariate function is the derivative with respect to one of the variables with the others held constant.
The computation is done by applying (first order) finite difference recursively on the function. Specifically,
∂2 ∂ ∂
------ = ---( ---- )
∂x2∂x1 ∂x2 ∂x1
Each of the two univariate derivative is computed using the central difference method.
| 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 |
| Constructor Summary | |
|---|---|
FiniteDifference(RealScalarFunction f,
int[] varidx)
Construct a finite difference instance for a multi-variable function. |
|
| 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)
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. |
double |
evaluateByRecursion(int n,
double h,
double... z)
Evaluate the n-th derivative using Recursion. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public final RealScalarFunction f
| Constructor Detail |
|---|
public FiniteDifference(RealScalarFunction f,
int[] varidx)
For example,
varidx = new int[]{1, 2} means
∂f
fx1,x2 = -------
∂x2∂x1
∂ ∂
= ---( ---- )
∂x2 ∂x1
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 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 Functionpublic double evaluate(double... x)
f at point x.
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.
evaluate in interface RealScalarFunctionx - 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. 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 the derivative of f ath - the step size
f at point x with step size h
public double evaluateByRecursion(int n,
double h,
double... z)
∂nf
--------
∂x1...∂xn
n - the order, i.e., n-th derivative,h - the step sizez - the point to evaluate the derivative at
z
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||