Class MultivariateFiniteDifference
- java.lang.Object
-
- dev.nm.analysis.function.rn2r1.AbstractRealScalarFunction
-
- dev.nm.analysis.differentiation.multivariate.MultivariateFiniteDifference
-
- All Implemented Interfaces:
Function<Vector,Double>
,RealScalarFunction
public class MultivariateFiniteDifference extends AbstractRealScalarFunction
A partial derivative of a multivariate function is the derivative with respect to one of the variables with the others held constant. This implementation applies recursively the (first order) finite difference on the function. For example, \[ {\partial^2 \over \partial x_1 \partial x_2} = {\partial \over \partial x_2}({\partial \over \partial x_1}) \] Each of the two univariate derivatives is computed using the central difference method.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface dev.nm.analysis.function.Function
Function.EvaluationException
-
-
Constructor Summary
Constructors Constructor Description MultivariateFiniteDifference(RealScalarFunction f, int[] varidx)
Construct the partial derivative of a multi-variable function.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Double
evaluate(Vector x)
Evaluate numerically the partial derivative of f at point x.double
evaluate(Vector x, double h)
Evaluate numerically the partial derivative of f at point x with step size h.-
Methods inherited from class dev.nm.analysis.function.rn2r1.AbstractRealScalarFunction
dimensionOfDomain, dimensionOfRange
-
-
-
-
Constructor Detail
-
MultivariateFiniteDifference
public MultivariateFiniteDifference(RealScalarFunction f, int[] varidx)
Construct the partial derivative of a multi-variable function. For example,varidx = new int[]{1, 2}
means \[ f_{x_1,x_2} = {\partial^2 \over \partial x_2 \partial x_1} = {\partial \over \partial x_2}({\partial \over \partial x_1}) \]- Parameters:
f
- the real multivariate function to take derivative ofvaridx
- the variable indices of the derivative, counting from 1 up to the domain dimension of f
-
-
Method Detail
-
evaluate
public Double evaluate(Vector x)
Evaluate numerically the partial derivative of 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.- Parameters:
x
- the point to evaluate the derivative at- Returns:
- the numerical partial derivative of f at point x
- See Also:
- Wikipedia: Practical considerations
-
evaluate
public double evaluate(Vector x, double h)
Evaluate numerically the partial derivative of f at point 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 the derivative of f ath
- the step size- Returns:
- the numerical partial derivative of f at point x with step size h
-
-